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

CF SDK: Make dial and reattach a sync function #1171

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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: 5 additions & 0 deletions .changeset/dry-horses-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/js': patch
---

CF SDK: Make `dial` and `reattach` a sync function
5 changes: 3 additions & 2 deletions internal/e2e-js/tests/buildVideoWithFabricSDK.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
OverlayMap,
LocalVideoOverlay,
FabricRoomSession,
SignalWireClient,
} from '@signalwire/js'
import { test, expect, Page } from '../fixtures'
import {
Expand Down Expand Up @@ -269,9 +270,9 @@ test.describe('buildVideoElement with CallFabric SDK', () => {
async ({ roomName }) => {
return new Promise<any>(async (resolve, _reject) => {
// @ts-expect-error
const client = window._client
const client: SignalWireClient = window._client

const call = await client.dial({
const call = client.dial({
to: `/public/${roomName}?channel=video`,
rootElement: document.getElementById('rootElement'),
})
Expand Down
10 changes: 5 additions & 5 deletions internal/e2e-js/tests/callfabric/reattach.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test.describe('Reattach Tests', () => {
// @ts-expect-error
const client: SignalWireClient = window._client

const call = await client.reattach({
const call = client.reattach({
to: `/public/${roomName}?channel=video`,
rootElement: document.getElementById('rootElement'),
})
Expand Down Expand Up @@ -75,9 +75,9 @@ test.describe('Reattach Tests', () => {
async ({ roomName }) => {
return new Promise<any>(async (resolve, _reject) => {
// @ts-expect-error
const client = window._client
const client: SignalWireClient = window._client

const call = await client.dial({
const call = client.dial({
to: `/public/${roomName}?channel=video`,
rootElement: document.getElementById('rootElement'),
})
Expand Down Expand Up @@ -148,9 +148,9 @@ test.describe('Reattach Tests', () => {
async ({ roomName }) => {
return new Promise<any>(async (resolve, _reject) => {
// @ts-expect-error
const client = window._client
const client: SignalWireClient = window._client

const call = await client.reattach({
const call = client.reattach({
to: `/public/${roomName}?channel=video`,
rootElement: document.getElementById('rootElement'),
})
Expand Down
10 changes: 7 additions & 3 deletions internal/e2e-js/tests/callfabric/videoRoom.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { uuid } from '@signalwire/core'
import { FabricRoomSession, CallJoinedEventParams } from '@signalwire/js'
import {
FabricRoomSession,
CallJoinedEventParams,
SignalWireClient,
} from '@signalwire/js'
import { test, expect } from '../../fixtures'
import {
SERVER_URL,
Expand Down Expand Up @@ -377,9 +381,9 @@ test.describe('CallFabric VideoRoom', () => {
const roomSession = await page.evaluate(async () => {
try {
// @ts-expect-error
const client = window._client
const client: SignalWireClient = window._client

const call = await client.dial({
const call = client.dial({
to: `/public/invalid-address?channel=video`,
rootElement: document.getElementById('rootElement'),
})
Expand Down
10 changes: 5 additions & 5 deletions internal/e2e-js/tests/callfabric/websocket_reconnect.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SignalWireClient } from '@signalwire/js'
import { test } from '../../fixtures'
import { SERVER_URL, createCFClient, expectMCUVisible } from '../../utils'

Expand All @@ -19,9 +20,9 @@ test.describe('CallFabric Reconnections', () => {
async ({ roomName }) => {
return new Promise<any>(async (resolve, _reject) => {
// @ts-expect-error
const client = window._client
const client: SignalWireClient = window._client

const call = await client.dial({
const call = client.dial({
to: `/public/${roomName}`,
rootElement: document.getElementById('rootElement'),
})
Expand Down Expand Up @@ -186,9 +187,9 @@ test.describe('CallFabric Reconnections', () => {
async ({ roomName }) => {
return new Promise<any>(async (resolve, _reject) => {
// @ts-expect-error
const client = window._client
const client: SignalWireClient = window._client

const call = await client.dial({
const call = client.dial({
to: `/public/${roomName}`,
rootElement: document.getElementById('rootElement'),
})
Expand Down Expand Up @@ -333,5 +334,4 @@ test.describe('CallFabric Reconnections', () => {
],
})
})

})
2 changes: 1 addition & 1 deletion internal/playground-js/src/fabric/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ window.ready(async function () {
const room = urlParams.get('room')
if (room) {
await connect()
await dial({ reattach: true })
dial({ reattach: true })
} else {
console.log('Room parameter not found')
}
Expand Down
25 changes: 4 additions & 21 deletions packages/js/src/fabric/WSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { buildVideoElement } from '../buildVideoElement'
import {
CallParams,
DialParams,
FabricRoomSession,
IncomingInvite,
OnlineParams,
HandlePushNotificationParams,
Expand Down Expand Up @@ -299,28 +298,12 @@ export class WSClient extends BaseClient<{}> implements WSClientContract {
})
}

public async dial(params: DialParams) {
return new Promise<FabricRoomSession>(async (resolve, reject) => {
try {
const call = this.buildOutboundCall(params)
resolve(call)
} catch (error) {
this.logger.error('Unable to connect and dial a call', error)
reject(error)
}
})
public dial(params: DialParams) {
return this.buildOutboundCall(params)
}

public async reattach(params: DialParams) {
return new Promise<FabricRoomSession>(async (resolve, reject) => {
try {
const call = this.buildOutboundCall({ ...params, attach: true })
resolve(call)
} catch (error) {
this.logger.error('Unable to connect and reattach a call', error)
reject(error)
}
})
public reattach(params: DialParams) {
return this.buildOutboundCall({ ...params, attach: true })
}

public handlePushNotification(params: HandlePushNotificationParams) {
Expand Down
8 changes: 4 additions & 4 deletions packages/js/src/fabric/interfaces/wsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ export interface WSClientContract {
* Dial a resource and connect the call
*
* @param params {@link DialParams}
* @returns A promise resolving to the session object {@link FabricRoomSession}.
* @returns A session object {@link FabricRoomSession}.
*/
dial(params: DialParams): Promise<FabricRoomSession>
dial(params: DialParams): FabricRoomSession
/**
* Reattach to the previous call if the previous call was not disconnected
*
* @param params {@link DialParams}
* @returns A promise resolving to the session object {@link FabricRoomSession}.
* @returns A session object {@link FabricRoomSession}.
*/
reattach(params: DialParams): Promise<FabricRoomSession>
reattach(params: DialParams): FabricRoomSession
/**
* Handles the incoming call via Push Notification
*
Expand Down
Loading