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

Review dev #881

Merged
merged 15 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 5 deletions .changeset/calm-berries-kneel.md

This file was deleted.

95 changes: 95 additions & 0 deletions .changeset/cuddly-carrots-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
'@signalwire/realtime-api': major
'@signalwire/core': major
---

New interface for Voice APIs

The new interface contains a single SW client with Chat and PubSub namespaces
```javascript
import { SignalWire } from '@signalwire/realtime-api'

(async () => {
const client = await SignalWire({
host: process.env.HOST,
project: process.env.PROJECT,
token: process.env.TOKEN,
})

const unsubVoiceOffice = await client.voice.listen({
topics: ['office'],
onCallReceived: async (call) => {
try {
await call.answer()

const unsubCall = await call.listen({
onStateChanged: (call) => {},
onPlaybackUpdated: (playback) => {},
onRecordingStarted: (recording) => {},
onCollectInputStarted: (collect) => {},
onDetectStarted: (detect) => {},
onTapStarted: (tap) => {},
onPromptEnded: (prompt) => {}
// ... more call listeners can be attached here
})

// ...

await unsubCall()
} catch (error) {
console.error('Error answering inbound call', error)
}
}
})

const call = await client.voice.dialPhone({
to: process.env.VOICE_DIAL_TO_NUMBER as string,
from: process.env.VOICE_DIAL_FROM_NUMBER as string,
timeout: 30,
listen: {
onStateChanged: async (call) => {
// When call ends; unsubscribe all listeners and disconnect the client
if (call.state === 'ended') {
await unsubVoiceOffice()

await unsubVoiceHome()

await unsubPlay()

client.disconnect()
}
},
onPlaybackStarted: (playback) => {},
},
})

const unsubCall = await call.listen({
onPlaybackStarted: (playback) => {},
onPlaybackEnded: (playback) => {
// This will never run since we unsubscribe this listener before the playback stops
},
})

// Play an audio
const play = await call.playAudio({
url: 'https://cdn.signalwire.com/default-music/welcome.mp3',
listen: {
onStarted: async (playback) => {
await unsubCall()

await play.stop()
},
},
})

const unsubPlay = await play.listen({
onStarted: (playback) => {
// This will never run since this listener is attached after the call.play has started
},
onEnded: async (playback) => {
await call.hangup()
},
})

})
```
10 changes: 0 additions & 10 deletions .changeset/early-cheetahs-tease.md

This file was deleted.

33 changes: 33 additions & 0 deletions .changeset/fluffy-birds-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
'@signalwire/realtime-api': major
'@signalwire/core': major
---

- New interface for the realtime-api Video SDK.
- Listen function with _video_, _room_, _playback_, _recording_, and _stream_ objects.
- Listen param with `room.play`, `room.startRecording`, and `room.startStream` functions.
- Decorated promise for `room.play`, `room.startRecording`, and `room.startStream` functions.

```js
import { SignalWire } from '@signalwire/realtime-api'

const client = await SignalWire({ project, token })

const unsub = await client.video.listen({
onRoomStarted: async (roomSession) => {
console.log('room session started', roomSession)

await roomSession.listen({
onPlaybackStarted: (playback) => {
console.log('plyaback started', playback)
}
})

// Promise resolves when playback ends.
await roomSession.play({ url: "http://.....", listen: { onEnded: () => {} } })
},
onRoomEnded: (roomSession) => {
console.log('room session ended', roomSession)
}
})
```
6 changes: 0 additions & 6 deletions .changeset/fuzzy-flowers-joke.md

This file was deleted.

76 changes: 76 additions & 0 deletions .changeset/hip-bobcats-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
'@signalwire/realtime-api': major
'@signalwire/core': major
---

New interface for PubSub and Chat APIs

The new interface contains a single SW client with Chat and PubSub namespaces
```javascript
import { SignalWire } from '@signalwire/realtime-api'

(async () => {
const client = await SignalWire({
host: process.env.HOST,
project: process.env.PROJECT,
token: process.env.TOKEN,
})

// Attach pubSub listeners
const unsubHomePubSubListener = await client.pubSub.listen({
channels: ['home'],
onMessageReceived: (message) => {
console.log('Message received under the "home" channel', message)
},
})

// Publish on home channel
await client.pubSub.publish({
content: 'Hello There',
channel: 'home',
meta: {
fooId: 'randomValue',
},
})

// Attach chat listeners
const unsubOfficeChatListener = await client.chat.listen({
channels: ['office'],
onMessageReceived: (message) => {
console.log('Message received on "office" channel', message)
},
onMemberJoined: (member) => {
console.log('Member joined on "office" channel', member)
},
onMemberUpdated: (member) => {
console.log('Member updated on "office" channel', member)
},
onMemberLeft: (member) => {
console.log('Member left on "office" channel', member)
},
})

// Publish a chat message on the office channel
const pubRes = await client.chat.publish({
content: 'Hello There',
channel: 'office',
})

// Get channel messages
const messagesResult = await client.chat.getMessages({
channel: 'office',
})

// Get channel members
const getMembersResult = await client.chat.getMembers({ channel: 'office' })

// Unsubscribe pubSub listener
await unsubHomePubSubListener()

// Unsubscribe chat listener
await unsubOfficeChatListener()

// Disconnect the client
client.disconnect()
})();
```
5 changes: 5 additions & 0 deletions .changeset/lovely-tigers-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/realtime-api': patch
---

Fix `onStarted` function in decorated promises
7 changes: 0 additions & 7 deletions .changeset/red-turkeys-rest.md

This file was deleted.

42 changes: 42 additions & 0 deletions .changeset/three-mails-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
'@signalwire/realtime-api': major
'@signalwire/core': major
---

New interface for the Messaging API

The new interface contains a single SW client with Messaging namespace
```javascript
const client = await SignalWire({
host: process.env.HOST || 'relay.swire.io',
project: process.env.PROJECT as string,
token: process.env.TOKEN as string,
})

const unsubOfficeListener = await client.messaging.listen({
topics: ['office'],
onMessageReceived: (payload) => {
console.log('Message received under "office" context', payload)
},
onMessageUpdated: (payload) => {
console.log('Message updated under "office" context', payload)
},
})

try {
const response = await client.messaging.send({
from: process.env.FROM_NUMBER_MSG as string,
to: process.env.TO_NUMBER_MSG as string,
body: 'Hello World!',
context: 'office',
})

await client.messaging.send({
from: process.env.FROM_NUMBER_MSG as string,
to: process.env.TO_NUMBER_MSG as string,
body: 'Hello John Doe!',
})
} catch (error) {
console.log('>> send error', error)
}
```
50 changes: 50 additions & 0 deletions .changeset/tricky-ants-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
'@signalwire/realtime-api': major
'@signalwire/core': major
---

Decorated promise for the following APIs:
- call.play()
- call.playAudio()
- call.playSilence()
- call.playRingtone()
- call.playTTS()
- call.record()
- call.recordAudio()
- call.prompt()
- call.promptAudio()
- call.promptRingtone()
- call.promptTTS()
- call.tap()
- call.tapAudio()
- call.detect()
- call.amd()
- call.detectFax()
- call.detectDigit
- call.collect()

Playback example 1 - **Not resolving promise**
```js
const play = call.playAudio({ url: '...' })
await play.id
```

Playback example 2 - **Resolving promise when playback starts**
```js
const play = await call.playAudio({ url: '...' }).onStarted()
play.id
```

Playback example 3 - **Resolving promise when playback ends**
```js
const play = await call.playAudio({ url: '...' }).onEnded()
play.id
```

Playback example 4 - **Resolving promise when playback ends - Default behavior**
```js
const play = await call.playAudio({ url: '...' })
play.id
```

All the other APIs work in a similar way.
6 changes: 6 additions & 0 deletions .changeset/violet-boats-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@signalwire/realtime-api': major
'@signalwire/core': major
---

Task namespace with new interface
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit and stack tests
name: Tests

on:
push:
Expand Down
Loading
Loading