Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@signalwire/js

Package Overview
Dependencies
Maintainers
2
Versions
367
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@signalwire/js - npm Package Compare versions

Comparing version 3.22.0-dev.202306291038.e8141c0.0 to 3.22.0-dev.202307041304.c72e7ce.0

dist/js/src/fabric/createHttpClient.d.ts

25

dist/core/src/types/voiceCall.d.ts

@@ -67,14 +67,17 @@ import type { SwEvent } from '.';

}
export interface VoiceCallPhoneParams {
interface VoiceCallParams {
timeout?: number;
callStateUrl?: string;
callStateEvents?: CallingCallState[];
}
export interface VoiceCallPhoneParams extends VoiceCallParams {
type: 'phone';
from?: string;
to: string;
timeout?: number;
}
export declare type OmitType<T> = Omit<T, 'type'>;
export interface VoiceCallSipParams {
export interface VoiceCallSipParams extends VoiceCallParams {
type: 'sip';
from: string;
to: string;
timeout?: number;
headers?: SipHeader[];

@@ -553,2 +556,8 @@ codecs?: SipCodec[];

*/
declare type CallDeviceParamsShared = {
timeout?: number;
max_duration?: number;
call_state_url?: string;
call_state_events?: string[];
};
export interface CallingCallPhoneDevice {

@@ -559,5 +568,3 @@ type: 'phone';

to_number: string;
timeout: number;
max_duration: number;
};
} & CallDeviceParamsShared;
}

@@ -570,8 +577,6 @@ export interface CallingCallSIPDevice {

to: string;
timeout?: number;
max_duration?: number;
headers?: SipHeader[];
codecs?: SipCodec[];
webrtc_media?: boolean;
};
} & CallDeviceParamsShared;
}

@@ -578,0 +583,0 @@ declare type CallingCallDevice = CallingCallPhoneDevice | CallingCallSIPDevice;

14

dist/js/src/fabric/Client.d.ts

@@ -1,2 +0,1 @@

import { RoomSession } from '../video';
interface ClientOptions {

@@ -6,2 +5,9 @@ host?: string;

}
/**
*
*
* // TODO: Remove this file
* Replaced by SWClient.ts
*
*/
export declare class Client {

@@ -20,9 +26,5 @@ options: ClientOptions;

rootElement: HTMLElement;
}): Promise<RoomSession>;
createSATCall(params: {
destinationNumber: string;
rootElement: HTMLElement;
}): Promise<RoomSession>;
}): Promise<import("../RoomSession").RoomSession>;
}
export {};
//# sourceMappingURL=Client.d.ts.map

@@ -1,5 +0,4 @@

export * from './getAddresses';
export * from './Client';
export * from './registerDevice';
export * from './unregisterDevice';
export * from './SWClient';
export * from './WSClient';
//# sourceMappingURL=index.d.ts.map

@@ -24,2 +24,3 @@ /**

import type { VideoRoomSessionEventNames, RoomStarted, RoomSubscribed, RoomUpdated, RoomEnded, VideoMemberEntity } from '@signalwire/core';
import { SWClient } from './fabric';
/** @ignore @deprecated */

@@ -58,2 +59,3 @@ export declare type RoomStartedEventName = RoomStarted;

export * as Fabric from './fabric';
export { SWClient };
/**

@@ -60,0 +62,0 @@ * The Video namespace contains the classes and functions that you need to

@@ -17,2 +17,3 @@ import { BaseJWTSession, SessionOptions, SwAuthorizationState } from '@signalwire/core';

agent: string;
private tokenTyp;
constructor(options: SessionOptions);

@@ -25,6 +26,4 @@ get allowReattach(): boolean;

protected _onSocketClose(event: CloseEvent): void;
private getAuthStateSessionStorageKey;
private getProtocolSessionStorageKey;
private getSessionStorageKey;
private isVRT;
}
//# sourceMappingURL=JWTSession.d.ts.map

@@ -1,2 +0,1 @@

export declare const CALL_ID = "callId";
/**

@@ -6,2 +5,7 @@ * Note: ready to support RN with a "storage.native.ts" file.

export declare const getStorage: () => Storage | undefined;
export declare const sessionStorageManager: (token: string) => {
authStateKey: string | false;
protocolKey: string | false;
callIdKey: string | false;
};
//# sourceMappingURL=storage.d.ts.map

@@ -46,2 +46,3 @@ import { BaseComponent, BaseComponentOptions, BaseConnectionState, Rooms, EventEmitter, BaseConnectionContract, WebRTCMethod } from '@signalwire/core';

get roomSessionId(): any;
get nodeId(): any;
get callId(): string;

@@ -111,3 +112,3 @@ get localStream(): MediaStream | undefined;

/** @internal */
answer(): Promise<unknown>;
answer<T>(): Promise<T>;
/** @internal */

@@ -129,2 +130,8 @@ onLocalSDPReady(rtcPeer: RTCPeer<EventTypes>): void | Promise<void>;

executeInvite(sdp: string, rtcPeerId: string, nodeId?: string): Promise<void>;
/**
* Send the `verto.answer` only if the state is `new`
* - new: the first time we send out the answer.
* @internal
*/
executeAnswer(sdp: string, rtcPeerId: string): Promise<void>;
/** @internal */

@@ -169,2 +176,3 @@ executeUpdateMedia(sdp: string, rtcPeerId: string): Promise<void>;

private _checkDefaultMediaConstraints;
private _initPeer;
/** @internal */

@@ -171,0 +179,0 @@ protected _finalize(): void;

@@ -8,3 +8,2 @@ import { EventEmitter } from '@signalwire/core';

instance: RTCPeerConnection;
private options;
private _iceTimeout;

@@ -30,2 +29,3 @@ private _negotiating;

constructor(call: BaseConnection<EventTypes>, type: RTCSdpType);
get options(): import("./BaseConnection").BaseConnectionOptions<EventTypes & import("./BaseConnection").BaseConnectionStateEventTypes>;
get watchMediaPacketsTimeout(): number;

@@ -32,0 +32,0 @@ get localStream(): MediaStream | undefined;

@@ -91,2 +91,4 @@ import type { VideoPositions } from '@signalwire/core';

prevCallId?: string;
/** @internal */
nodeId?: string;
layout?: string;

@@ -93,0 +95,0 @@ positions?: VideoPositions;

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "3.22.0-dev.202306291038.e8141c0.0",
"version": "3.22.0-dev.202307041304.c72e7ce.0",
"main": "dist/index.js",

@@ -43,4 +43,4 @@ "module": "dist/index.esm.js",

"dependencies": {
"@signalwire/core": "3.17.0-dev.202306291038.e8141c0.0",
"@signalwire/webrtc": "3.8.0-dev.202306291038.e8141c0.0",
"@signalwire/core": "3.17.0-dev.202307041304.c72e7ce.0",
"@signalwire/webrtc": "3.8.0-dev.202307041304.c72e7ce.0",
"jwt-decode": "^3.1.2"

@@ -47,0 +47,0 @@ },

@@ -25,4 +25,8 @@ import { MakeRoomOptions } from '../Client'

obj = new RoomSession({
// host: document.getElementById('host').value,
token: params.token,
debug: {
logWsTraffic: true,
},
logLevel: 'debug',
watchMediaPackets: false,
...userParams,

@@ -32,3 +36,5 @@ })

return new Promise((resolve, reject) => {
obj.on('room.joined', (params) => resolve(params))
obj.once('room.joined', (params) => resolve(params))
// @ts-ignore
obj.emitter.once('verto.display', (params) => resolve(params))
return obj.join(joinParams).catch((error) => reject(error))

@@ -35,0 +41,0 @@ })

@@ -1,4 +0,3 @@

import { createHttpClient } from './httpClient'
import { createHttpClient } from './createHttpClient'
import { buildCall } from './buildCall'
import { RoomSession } from '../video'

@@ -10,2 +9,9 @@ interface ClientOptions {

/**
*
*
* // TODO: Remove this file
* Replaced by SWClient.ts
*
*/
export class Client {

@@ -75,17 +81,2 @@ private httpClient: ReturnType<typeof createHttpClient>

}
async createSATCall(params: {
destinationNumber: string
rootElement: HTMLElement
}) {
console.log('createSATCall to', params)
const obj = new RoomSession({
host: this.host.includes('swire') ? 'relay.swire.io' : undefined,
token: this.options.accessToken,
...params,
})
return obj
}
}

@@ -1,4 +0,3 @@

export * from './getAddresses'
export * from './Client'
export * from './registerDevice'
export * from './unregisterDevice'
export * from './SWClient'
export * from './WSClient'

@@ -33,2 +33,4 @@ /**

import { SWClient } from './fabric'
/** @ignore @deprecated */

@@ -64,2 +66,3 @@ export type RoomStartedEventName = RoomStarted

export * as Fabric from './fabric'
export { SWClient }

@@ -66,0 +69,0 @@ /**

@@ -8,5 +8,7 @@ import jwtDecode from 'jwt-decode'

} from '@signalwire/core'
import { getStorage, CALL_ID } from './utils/storage'
import { getStorage, sessionStorageManager } from './utils/storage'
import { SwCloseEvent } from './utils/CloseEvent'
type JWTHeader = { ch?: string; typ?: string }
export class JWTSession extends BaseJWTSession {

@@ -17,6 +19,10 @@ public WebSocketConstructor = WebSocket

private tokenTyp: string
constructor(public options: SessionOptions) {
let decodedJwt
let decodedJwt: JWTHeader = {}
try {
decodedJwt = jwtDecode<{ ch?: string }>(options.token, { header: true })
decodedJwt = jwtDecode<{ ch?: string; typ: string }>(options.token, {
header: true,
})
} catch (e) {

@@ -32,2 +38,3 @@ if (process.env.NODE_ENV !== 'production') {

})
this.tokenTyp = decodedJwt.typ ?? 'VRT'
}

@@ -37,3 +44,3 @@

// @ts-expect-error
return this.options?.reattach !== false
return this.options?.reattach !== false && this.isVRT()
}

@@ -46,6 +53,6 @@

const key = this.getProtocolSessionStorageKey()
if (key) {
this.logger.trace('Hijacking: search protocol for', key)
return getStorage()?.getItem(key) ?? ''
const { protocolKey } = sessionStorageManager(this.options.token)
if (protocolKey) {
this.logger.trace('Search protocol for', protocolKey)
return getStorage()?.getItem(protocolKey) ?? ''
}

@@ -60,6 +67,6 @@ return ''

const key = this.getProtocolSessionStorageKey()
if (key) {
this.logger.trace('Hijacking: persist protocol', key, this.relayProtocol)
getStorage()?.setItem(key, this.relayProtocol)
const { protocolKey } = sessionStorageManager(this.options.token)
if (protocolKey) {
this.logger.trace('Persist protocol', protocolKey, this.relayProtocol)
getStorage()?.setItem(protocolKey, this.relayProtocol)
}

@@ -69,5 +76,5 @@ }

protected override async retrieveSwAuthorizationState() {
const key = this.getAuthStateSessionStorageKey()
if (key) {
return getStorage()?.getItem(key) ?? ''
const { authStateKey } = sessionStorageManager(this.options.token)
if (authStateKey) {
return getStorage()?.getItem(authStateKey) ?? ''
}

@@ -84,6 +91,6 @@ return ''

const key = this.getAuthStateSessionStorageKey()
if (key) {
this.logger.trace('Hijacking: persist auth state', key, state)
getStorage()?.setItem(key, state)
const { authStateKey } = sessionStorageManager(this.options.token)
if (authStateKey) {
this.logger.trace('Persist auth state', authStateKey, state)
getStorage()?.setItem(authStateKey, state)
}

@@ -94,13 +101,18 @@ }

if (this.status === 'unknown') {
this.logger.trace('Hijacking: invalid values - cleaning up storage')
const protocolKey = this.getProtocolSessionStorageKey()
const { protocolKey, authStateKey, callIdKey } = sessionStorageManager(
this.options.token
)
this.logger.debug('Cleaning up storage')
if (protocolKey) {
this.logger.debug('Remove protocolKey', protocolKey)
getStorage()?.removeItem(protocolKey)
}
const authStatekey = this.getAuthStateSessionStorageKey()
if (authStatekey) {
getStorage()?.removeItem(authStatekey)
if (authStateKey) {
this.logger.debug('Remove authStateKey', authStateKey)
getStorage()?.removeItem(authStateKey)
}
// Remove also the previous callId
getStorage()?.removeItem(CALL_ID)
if (callIdKey) {
this.logger.debug('Remove callIdKey', callIdKey)
getStorage()?.removeItem(callIdKey)
}
}

@@ -111,23 +123,5 @@

private getAuthStateSessionStorageKey() {
return `as-${this.getSessionStorageKey()}`
private isVRT() {
return this.tokenTyp === 'VRT'
}
private getProtocolSessionStorageKey() {
return `pt-${this.getSessionStorageKey()}`
}
private getSessionStorageKey() {
try {
const jwtPayload = jwtDecode<{ r: string; ja: string }>(
this.options.token
)
return `${jwtPayload?.r}`
} catch (e) {
if (process.env.NODE_ENV !== 'production') {
getLogger().error('[getSessionStorageKey] error decoding the JWT')
}
return ''
}
}
}

@@ -15,3 +15,3 @@ import {

} from './utils/interfaces'
import { getStorage, CALL_ID } from './utils/storage'
import { getStorage, sessionStorageManager } from './utils/storage'

@@ -111,2 +111,4 @@ /**

localStream,
watchMediaPackets,
watchMediaPacketsTimeout,
...userOptions

@@ -124,49 +126,57 @@ } = roomOptions

const client = createClient<RoomSession>(userOptions)
const room = client.rooms.makeRoomObject({
// audio,
// video: video === true ? VIDEO_CONSTRAINTS : video,
negotiateAudio: true,
negotiateVideo: true,
iceServers,
rootElement,
applyLocalVideoOverlay,
mirrorLocalVideoOverlay,
stopCameraWhileMuted,
stopMicrophoneWhileMuted,
speakerId,
destinationNumber,
localStream,
})
// @ts-expect-error - true by default
const allowReattach = roomOptions?.reattach !== false
const { callIdKey } = sessionStorageManager(userOptions.token)
const reattachManager = {
joined: ({ call_id }: VideoRoomSubscribedEventParams) => {
if (allowReattach && callIdKey) {
getStorage()?.setItem(callIdKey, call_id)
}
},
init: () => {
if (allowReattach) {
getStorage()?.setItem(CALL_ID, call_id)
room.on('room.subscribed', reattachManager.joined)
}
room.options.prevCallId = reattachManager.getPrevCallId()
},
init: () => {
destroy: () => {
if (!allowReattach) {
return
}
room.on('room.subscribed', reattachManager.joined)
const prevCallId = getStorage()?.getItem(CALL_ID)
if (prevCallId) {
room.options.prevCallId = prevCallId
room.off('room.subscribed', reattachManager.joined)
if (callIdKey) {
getStorage()?.removeItem(callIdKey)
}
},
destroy: () => {
if (!allowReattach) {
getPrevCallId: () => {
if (!allowReattach || !callIdKey) {
return
}
room.off('room.subscribed', reattachManager.joined)
getStorage()?.removeItem(CALL_ID)
return getStorage()?.getItem(callIdKey) ?? undefined
},
}
const client = createClient<RoomSession>(userOptions)
const room = client.rooms.makeRoomObject({
// audio,
// video: video === true ? VIDEO_CONSTRAINTS : video,
negotiateAudio: true,
negotiateVideo: true,
iceServers,
rootElement,
applyLocalVideoOverlay,
mirrorLocalVideoOverlay,
stopCameraWhileMuted,
stopMicrophoneWhileMuted,
speakerId,
destinationNumber,
localStream,
watchMediaPackets,
watchMediaPacketsTimeout,
prevCallId: reattachManager.getPrevCallId(),
})
// WebRTC connection left the room.

@@ -200,37 +210,40 @@ room.once('destroy', () => {

const authState: VideoAuthorization = client._sessionAuthState
const mediaOptions = getJoinMediaParams({
authState,
// constructor values override the send
sendAudio: Boolean(audio),
sendVideo: Boolean(video),
...params,
})
getLogger().debug('getJoinMediaParams authState?', authState)
if (authState && authState.type === 'video') {
const mediaOptions = getJoinMediaParams({
authState,
// constructor values override the send
sendAudio: Boolean(audio),
sendVideo: Boolean(video),
...params,
})
if (!checkMediaParams(mediaOptions)) {
client.disconnect()
return reject(
new Error(
`Invalid arguments to join the room. The token used has join_as: '${
authState.join_as
}'. \n${JSON.stringify(params, null, 2)}\n`
if (!checkMediaParams(mediaOptions)) {
client.disconnect()
return reject(
new Error(
`Invalid arguments to join the room. The token used has join_as: '${
authState.join_as
}'. \n${JSON.stringify(params, null, 2)}\n`
)
)
)
}
getLogger().debug('Set mediaOptions', mediaOptions)
/**
* audio and video might be objects with MediaStreamConstraints
* so if we must send media, we make sure to use the user's
* preferences.
* Note: params.sendAudio: `true` will override audio: `false` so
* we're using `||` instead of `??` for that reason.
*/
// @ts-expect-error
room.updateMediaOptions({
audio: mediaOptions.mustSendAudio ? audio || true : false,
video: mediaOptions.mustSendVideo ? video || true : false,
negotiateAudio: mediaOptions.mustRecvAudio,
negotiateVideo: mediaOptions.mustRecvVideo,
})
}
getLogger().debug('Set mediaOptions', mediaOptions)
/**
* audio and video might be objects with MediaStreamConstraints
* so if we must send media, we make sure to use the user's
* preferences.
* Note: params.sendAudio: `true` will override audio: `false` so
* we're using `||` instead of `??` for that reason.
*/
// @ts-expect-error
room.updateMediaOptions({
audio: mediaOptions.mustSendAudio ? audio || true : false,
video: mediaOptions.mustSendVideo ? video || true : false,
negotiateAudio: mediaOptions.mustRecvAudio,
negotiateVideo: mediaOptions.mustRecvVideo,
})
room.once('room.subscribed', (payload) => {

@@ -237,0 +250,0 @@ // @ts-expect-error

@@ -1,2 +0,3 @@

export const CALL_ID = 'callId'
import jwtDecode from 'jwt-decode'
import { getLogger } from '@signalwire/core'

@@ -12,1 +13,21 @@ /**

}
export const sessionStorageManager = (token: string) => {
let roomName: string = ''
try {
const jwtPayload = jwtDecode<{ r: string; ja: string }>(token)
roomName = jwtPayload?.r ?? ''
} catch (e) {
if (process.env.NODE_ENV !== 'production') {
getLogger().error('[sessionStorageManager] error decoding JWT', token)
}
roomName = ''
}
const valid = Boolean(roomName)
return {
authStateKey: valid && `as-${roomName}`,
protocolKey: valid && `pt-${roomName}`,
callIdKey: valid && `ci-${roomName}`,
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc