Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Explore runSaga #777

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
95ed949
EventEmitter for each instance of a component (#754)
iAmmar7 Mar 31, 2023
334f5ea
Parent voice call worker to fork child call workers (#762)
iAmmar7 Apr 5, 2023
5dd2c0d
GH Action jobs should not run on push (#780)
iAmmar7 Apr 12, 2023
0d8fa63
Cleanup emitter transform for Voice Call APIs (#781)
iAmmar7 Apr 12, 2023
9f8cf09
Use base event emitter for Message API (#782)
iAmmar7 Apr 17, 2023
fbc0a87
Use base event emitter for Chat & PubSub API (#783)
iAmmar7 Apr 27, 2023
7883886
initial changes playing with runSaga
edolix Mar 31, 2023
382884c
update tests
edolix Apr 3, 2023
cc867c0
poc working
edolix Apr 3, 2023
f49dbb3
start removing redux
edolix Apr 3, 2023
2f59f0c
attempt removing redux
edolix Apr 3, 2023
c6f2695
rm unused @redux-saga/testing-utils
edolix Apr 4, 2023
c5eab0f
review rootSaga tests
edolix Apr 4, 2023
9bbc547
update vertoEventWorker tests
edolix Apr 6, 2023
16e7fdf
testUtils
edolix Apr 6, 2023
45a5fc5
remove usage of sessionListeners
edolix Apr 6, 2023
1f93fdf
reduce logs in unit tests
edolix Apr 6, 2023
d7badd4
reduce logs
edolix Apr 6, 2023
ff6d1a6
re-put authErrorAction to bubble up error
edolix Apr 6, 2023
72bed3a
update realtime tests
edolix Apr 6, 2023
330ac86
reduce logs in js test run
edolix Apr 6, 2023
be9501b
Unhandled dispatch warn only in dev mode
edolix Apr 6, 2023
a8a478f
error instead of warn
edolix Apr 6, 2023
ef6879d
improve unit tests
edolix Apr 6, 2023
c24de2c
rmove detectOpenHandles and forceExit
edolix Apr 6, 2023
1b53b6c
always disconnect the session
edolix Apr 6, 2023
7b0b22d
remove .only in spesc
edolix Apr 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-games-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/core': patch
---

Base event emitter for PubSub and Chat APIs
5 changes: 5 additions & 0 deletions .changeset/dry-hairs-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/realtime-api': patch
---

Base event emitter for Messaging API
6 changes: 6 additions & 0 deletions .changeset/rude-horses-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@signalwire/realtime-api': patch
'@signalwire/core': patch
---

Event emitter for each instance of a component
5 changes: 5 additions & 0 deletions .changeset/serious-poems-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/realtime-api': patch
---

Remove emitter transform for Voice Call APIs
6 changes: 6 additions & 0 deletions .changeset/ten-geckos-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@signalwire/realtime-api': patch
'@signalwire/core': patch
---

Event emitter for each Call instance
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [main]
pull_request:
branches: [main]
branches: [main, dev]
workflow_dispatch:

concurrency:
Expand Down
73 changes: 39 additions & 34 deletions internal/e2e-js/tests/chat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,49 @@ test.describe('Chat', () => {
},
})

const { message: chatMessage, allowedChannels }: any = await page.evaluate(
(options) => {
return new Promise(async (resolve) => {
try {
// @ts-expect-error
const Chat = window._SWJS.Chat
const client = new Chat.Client({
host: options.RELAY_HOST,
token: options.API_TOKEN,
})
const allowedChannels = await client.getAllowedChannels()
// .subscribe should be after .on but i left here for test.
await client.subscribe([options.channel])
client.on('message', (message: any) => {
resolve({ allowedChannels, message })
})
const { msgContent, msgChannel, allowedChannels }: any =
await page.evaluate(
(options) => {
return new Promise(async (resolve) => {
try {
// @ts-expect-error
const Chat = window._SWJS.Chat
const client = new Chat.Client({
host: options.RELAY_HOST,
token: options.API_TOKEN,
})
const allowedChannels = await client.getAllowedChannels()
// .subscribe should be after .on but i left here for test.
await client.subscribe([options.channel])
client.on('message', (message: any) => {
resolve({
allowedChannels,
msgContent: message.content,
msgChannel: message.channel,
})
})

await client.publish({
channel: options.channel,
content: options.messageContent,
})
} catch (error) {
console.log('Chat Error', error)
}
})
},
{
RELAY_HOST: process.env.RELAY_HOST,
API_TOKEN: crt,
channel,
messageContent,
}
)
await client.publish({
channel: options.channel,
content: options.messageContent,
})
} catch (error) {
console.log('Chat Error', error)
}
})
},
{
RELAY_HOST: process.env.RELAY_HOST,
API_TOKEN: crt,
channel,
messageContent,
}
)
expect(allowedChannels).toStrictEqual({
'js-e2e': { read: true, write: true },
})
expect(chatMessage.content).toBe(messageContent)
expect(chatMessage.channel).toBe(channel)
expect(msgContent).toBe(messageContent)
expect(msgChannel).toBe(channel)
})

test('should expose disconnect()', async ({ page }) => {
Expand Down
73 changes: 39 additions & 34 deletions internal/e2e-js/tests/pubSub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,49 @@ test.describe('PubSub', () => {
},
})

const { message: chatMessage, allowedChannels }: any = await page.evaluate(
(options) => {
return new Promise(async (resolve) => {
try {
// @ts-expect-error
const PubSub = window._SWJS.PubSub
const pubSubClient = new PubSub.Client({
host: options.RELAY_HOST,
token: options.API_TOKEN,
})
const allowedChannels = await pubSubClient.getAllowedChannels()
// .subscribe should be after .on but i left here for test.
await pubSubClient.subscribe([options.channel])
pubSubClient.on('message', (message: any) => {
resolve({ allowedChannels, message })
})
const { msgContent, msgChannel, allowedChannels }: any =
await page.evaluate(
(options) => {
return new Promise(async (resolve) => {
try {
// @ts-expect-error
const PubSub = window._SWJS.PubSub
const pubSubClient = new PubSub.Client({
host: options.RELAY_HOST,
token: options.API_TOKEN,
})
const allowedChannels = await pubSubClient.getAllowedChannels()
// .subscribe should be after .on but i left here for test.
await pubSubClient.subscribe([options.channel])
pubSubClient.on('message', (message: any) => {
resolve({
allowedChannels,
msgContent: message.content,
msgChannel: message.channel,
})
})

await pubSubClient.publish({
channel: options.channel,
content: options.messageContent,
})
} catch (error) {
console.log('PubSub Error', error)
}
})
},
{
RELAY_HOST: process.env.RELAY_HOST,
API_TOKEN: crt,
channel,
messageContent,
}
)
await pubSubClient.publish({
channel: options.channel,
content: options.messageContent,
})
} catch (error) {
console.log('PubSub Error', error)
}
})
},
{
RELAY_HOST: process.env.RELAY_HOST,
API_TOKEN: crt,
channel,
messageContent,
}
)
expect(allowedChannels).toStrictEqual({
'js-e2e': { read: true, write: true },
})
expect(chatMessage.content).toBe(messageContent)
expect(chatMessage.channel).toBe(channel)
expect(msgContent).toBe(messageContent)
expect(msgChannel).toBe(channel)
})

test('should expose disconnect()', async ({ page }) => {
Expand Down
61 changes: 37 additions & 24 deletions internal/e2e-realtime-api/src/voicePlayback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,35 @@ const handler = () => {
'Inbound - Call answered gets the same instance'
)

// Play an invalid audio
const handle = await call.playAudio({
url: 'https://cdn.fake.com/default-music/fake.mp3',
})

tap.equal(
call.id,
handle.callId,
'Inbound - playback returns the same instance'
)
try {
// Play an invalid audio
const handle = call.playAudio({
url: 'https://cdn.fake.com/default-music/fake.mp3',
})

const waitForPlaybackFailed = new Promise((resolve) => {
call.on('playback.failed', (playback) => {
tap.equal(playback.state, 'error', 'Inbound - playback has failed')
resolve(true)
const waitForPlaybackFailed = new Promise((resolve) => {
call.on('playback.failed', (playback) => {
tap.equal(
playback.state,
'error',
'Inbound - playback has failed'
)
resolve(true)
})
})
})
// Wait for the inbound audio to failed
await waitForPlaybackFailed
// Wait for the inbound audio to failed
await waitForPlaybackFailed

// Resolve late so that we attach `playback.failed` and wait for it
await handle
} catch (error) {
console.log('Inbound - invalid playback error')
tap.equal(
call.id,
error.callId,
'Inbound - playback returns the same instance'
)
}

// Callee hangs up a call
await call.hangup()
Expand All @@ -65,16 +75,10 @@ const handler = () => {
tap.ok(call.id, 'Outbound - Call resolved')

// Play an audio
const handle = await call.playAudio({
const handle = call.playAudio({
url: 'https://cdn.signalwire.com/default-music/welcome.mp3',
})

tap.equal(
call.id,
handle.callId,
'Outbound - Playback returns the same instance'
)

const waitForPlaybackStarted = new Promise((resolve) => {
call.on('playback.started', (playback) => {
tap.equal(playback.state, 'playing', 'Outbound - Playback has started')
Expand All @@ -84,6 +88,15 @@ const handler = () => {
// Wait for the outbound audio to start
await waitForPlaybackStarted

// Resolve late so that we attach `playback.started` and wait for it
const resolvedHandle = await handle

tap.equal(
call.id,
resolvedHandle.callId,
'Outbound - Playback returns the same instance'
)

const waitForPlaybackEnded = new Promise((resolve) => {
call.on('playback.ended', (playback) => {
tap.equal(
Expand Down
60 changes: 36 additions & 24 deletions internal/e2e-realtime-api/src/voicePlaybackMultiple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,34 @@ const handler = () => {
'Inbound - Call answered gets the same instance'
)

// Play an invalid audio
const fakePlay = await call.playAudio({
url: 'https://cdn.fake.com/default-music/fake.mp3',
})

tap.equal(
call.id,
fakePlay.callId,
'Inbound - fakePlay returns the same instance'
)
try {
// Play an invalid audio
const fakePlay = call.playAudio({
url: 'https://cdn.fake.com/default-music/fake.mp3',
})

const waitForPlaybackFailed = new Promise((resolve) => {
call.on('playback.failed', (playback) => {
tap.equal(playback.state, 'error', 'Inbound - playback has failed')
resolve(true)
const waitForPlaybackFailed = new Promise((resolve) => {
call.on('playback.failed', (playback) => {
tap.equal(
playback.state,
'error',
'Inbound - playback has failed'
)
resolve(true)
})
})
})
// Wait for the inbound audio to failed
await waitForPlaybackFailed
// Wait for the inbound audio to failed
await waitForPlaybackFailed

// Resolve late so that we attach `playback.failed` and wait for it
await fakePlay
} catch (error) {
tap.equal(
call.id,
error.callId,
'Inbound - fakePlay returns the same instance'
)
}

const playback = await call.playTTS({
text: 'Random TTS message while the call is up. Thanks and good bye!',
Expand Down Expand Up @@ -96,16 +105,10 @@ const handler = () => {
tap.ok(call.id, 'Outbound - Call resolved')

// Play an audio
const handle = await call.playAudio({
const handle = call.playAudio({
url: 'https://cdn.signalwire.com/default-music/welcome.mp3',
})

tap.equal(
call.id,
handle.callId,
'Outbound - Playback returns the same instance'
)

const waitForPlaybackStarted = new Promise((resolve) => {
call.on('playback.started', (playback) => {
tap.equal(playback.state, 'playing', 'Outbound - Playback has started')
Expand All @@ -115,6 +118,15 @@ const handler = () => {
// Wait for the outbound audio to start
await waitForPlaybackStarted

// Resolve late so that we attach `playback.started` and wait for it
const resolvedHandle = await handle

tap.equal(
call.id,
resolvedHandle.callId,
'Outbound - Playback returns the same instance'
)

const waitForPlaybackEnded = new Promise((resolve) => {
call.on('playback.ended', (playback) => {
tap.equal(
Expand Down
Loading