Skip to content

Commit

Permalink
Add alias 'topics' for 'contexts' (#864)
Browse files Browse the repository at this point in the history
* Add alias 'topics' for 'contexts'

* include changeset

* fix voiceCallReceiveWorker issue
  • Loading branch information
iAmmar7 authored Aug 28, 2023
1 parent 2a9b88d commit be17e61
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/fresh-steaks-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@signalwire/realtime-api': minor
'@signalwire/core': minor
---

Add alias 'topics' for 'contexts'
2 changes: 1 addition & 1 deletion internal/e2e-realtime-api/src/voice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const handler = () => {
host: process.env.RELAY_HOST || 'relay.swire.io',
project: process.env.RELAY_PROJECT as string,
token: process.env.RELAY_TOKEN as string,
contexts: [process.env.VOICE_CONTEXT as string],
topics: [process.env.VOICE_CONTEXT as string],
// logLevel: "trace",
debug: {
logWsTraffic: true,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/BaseSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ export class BaseSession {
if (this._relayProtocolIsValid()) {
params.protocol = this.relayProtocol
}
if (this.options.contexts?.length) {
if (this.options.topics?.length) {
params.contexts = this.options.topics
} else if (this.options.contexts?.length) {
params.contexts = this.options.contexts
}
this._rpcConnectResult = await this.execute(RPCConnect(params))
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/RPCMessages/RPCConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type RPCConnectParams = {
protocol?: string
authorization_state?: string
contexts?: string[]
topics?: string[]
}

export const DEFAULT_CONNECT_VERSION = {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export interface SessionOptions {
token: string
/** SignalWire contexts, e.g. 'home', 'office'.. */
contexts?: string[]
/** An alias for contexts - Topics has more priority over contexts */
topics?: string[]
// From `LogLevelDesc` of loglevel to simplify our docs
/** logging level */
logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent'
Expand Down
13 changes: 9 additions & 4 deletions packages/realtime-api/src/voice/VoiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ interface VoiceClient extends Voice {
new (opts: VoiceClientOptions): this
}

export interface VoiceClientOptions
extends Omit<UserOptions, '_onRefreshToken'> {
contexts: string[]
}
export type VoiceClientOptions = Omit<UserOptions, '_onRefreshToken'> &
(
| {
contexts: string[]
}
| {
topics: string[]
}
)

/**
* You can use instances of this class to initiate or receive calls. Please see
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const voiceCallReceiveWorker = function* (
} = options

// Contexts is required
const { contexts = [] } = client?.options ?? {}
if (!contexts.length) {
const { contexts = [], topics = [] } = client?.options ?? {}
if (!contexts.length && !topics.length) {
throw new Error('Invalid contexts to receive inbound calls')
}

Expand Down

0 comments on commit be17e61

Please sign in to comment.