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

Add alias 'topics' for 'contexts' #864

Merged
merged 3 commits into from
Aug 28, 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
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