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
368
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.18.0-dev.202212271634.a594a28.0 to 3.18.0-dev.202301191718.e2c475a.0

dist/js/src/utils/storage.d.ts

2

dist/core/src/BaseComponent.d.ts

@@ -78,3 +78,3 @@ import type { Task } from '@redux-saga/types';

runSaga: any;
}) => Task;
}) => Task<any>;
dispatch: import("redux").Dispatch<import("redux").AnyAction>;

@@ -81,0 +81,0 @@ getState(): any;

import { PayloadAction } from './redux';
import { SessionOptions, RPCConnectResult, JSONRPCRequest, JSONRPCResponse, WebSocketAdapter, NodeSocketAdapter, WebSocketClient, SessionStatus, SessionAuthError } from './utils/interfaces';
import { SwAuthorizationState } from '.';
export declare const SW_SYMBOL: unique symbol;

@@ -21,2 +22,3 @@ export declare class BaseSession {

private _host;
protected _swConnectError: symbol;
private _executeTimeoutMs;

@@ -37,3 +39,3 @@ private _executeTimeoutError;

get signature(): string;
protected get logger(): import("./utils/interfaces").InternalSDKLogger;
protected get logger(): import(".").InternalSDKLogger;
get connecting(): boolean;

@@ -57,3 +59,3 @@ get connected(): boolean;

*/
protected _createSocket(): WebSocketClient;
protected _createSocket(): import(".").NodeSocketClient | WebSocketClient;
/** Allow children classes to override it. */

@@ -84,3 +86,2 @@ protected destroySocket(): void;

protected _onSocketMessage(event: MessageEvent): void | Promise<void>;
protected _handleWebSocketMessage(_payload: JSONRPCRequest | JSONRPCResponse): void;
dispatch(_payload: PayloadAction<any>): void;

@@ -95,2 +96,5 @@ /**

protected decode<T>(input: any): T;
onSwAuthorizationState(state: SwAuthorizationState): Promise<void>;
protected retrieveSwAuthorizationState(): Promise<string>;
protected persistSwAuthorizationState(_: SwAuthorizationState): Promise<void>;
private _send;

@@ -97,0 +101,0 @@ private _addToExecuteQueue;

@@ -5,3 +5,4 @@ import { SagaIterator, EventChannel } from '@redux-saga/core';

declare type SessionSagaParams = {
sessionChannel: EventChannel<unknown>;
session: BaseSession;
sessionChannel: EventChannel<any>;
pubSubChannel: PubSubChannel;

@@ -17,5 +18,5 @@ swEventChannel: SwEventChannel;

export declare function executeActionWatcher(session: BaseSession): SagaIterator;
export declare function sessionChannelWatcher({ sessionChannel, pubSubChannel, swEventChannel, }: SessionSagaParams): SagaIterator;
export declare function createSessionChannel(session: BaseSession): EventChannel<unknown>;
export declare function sessionChannelWatcher({ sessionChannel, pubSubChannel, swEventChannel, session, }: SessionSagaParams): SagaIterator;
export declare function createSessionChannel(session: BaseSession): EventChannel<import("@redux-saga/types").NotUndefined>;
export {};
//# sourceMappingURL=sessionSaga.d.ts.map

@@ -264,2 +264,3 @@ import type { PayloadAction, AnyAction } from '../../toolkit';

}>, sessionReducer: import("redux").Reducer<{
readonly authStatus: SessionAuthStatus;
readonly protocol: string;

@@ -272,3 +273,2 @@ readonly iceServers?: readonly {

}[] | undefined;
readonly authStatus: SessionAuthStatus;
readonly authState?: {

@@ -275,0 +275,0 @@ readonly type: "video";

@@ -17,3 +17,3 @@ import { Saga, Task } from '@redux-saga/core';

runSaga: any;
}) => Task;
}) => Task<any>;
dispatch: import("redux").Dispatch<import("redux").AnyAction>;

@@ -20,0 +20,0 @@ getState(): any;

@@ -395,2 +395,3 @@ export declare const rootReducer: import("redux").Reducer<import("redux").CombinedState<{

session: {
readonly authStatus: import("..").SessionAuthStatus;
readonly protocol: string;

@@ -403,3 +404,2 @@ readonly iceServers?: readonly {

}[] | undefined;
readonly authStatus: import("..").SessionAuthStatus;
readonly authState?: {

@@ -406,0 +406,0 @@ readonly type: "video";

@@ -8,3 +8,3 @@ import type { SagaIterator } from '@redux-saga/types';

session: BaseSession;
sessionChannel: EventChannel<unknown>;
sessionChannel: EventChannel<any>;
pubSubChannel: PubSubChannel;

@@ -11,0 +11,0 @@ userOptions: InternalUserOptions;

@@ -17,2 +17,3 @@ declare type WithToken = {

protocol?: string;
authorization_state?: string;
contexts?: string[];

@@ -19,0 +20,0 @@ };

@@ -9,3 +9,3 @@ export declare const RPCPing: () => {

};
export declare const RPCPingResponse: (id: string, timestamp?: number | undefined) => {
export declare const RPCPingResponse: (id: string, timestamp?: number) => {
id: string;

@@ -12,0 +12,0 @@ result: {

@@ -13,7 +13,7 @@ /// <reference types="jest" />

*/
export declare const configureJestStore: (options?: Partial<ConfigureStoreOptions> | undefined) => {
export declare const configureJestStore: (options?: Partial<ConfigureStoreOptions>) => {
runSaga: <T>(saga: import("@redux-saga/types").Saga<any[]>, args: {
instance: T;
runSaga: any;
}) => import("@redux-saga/types").Task;
}) => import("@redux-saga/types").Task<any>;
dispatch: import("redux").Dispatch<import("redux").AnyAction>;

@@ -37,3 +37,3 @@ getState(): any;

runSaga: any;
}) => import("@redux-saga/types").Task;
}) => import("@redux-saga/types").Task<any>;
dispatch: import("redux").Dispatch<import("redux").AnyAction>;

@@ -40,0 +40,0 @@ getState(): any;

@@ -27,2 +27,4 @@ import type { EventEmitter } from '../utils/EventEmitter';

export interface BaseConnectionContract<EventTypes extends EventEmitter.ValidEventTypes> extends EmitterContract<EventTypes> {
/** @internal The BaseConnection options */
readonly options: Record<any, any>;
/** The id of the video device, or null if not available */

@@ -54,2 +56,4 @@ readonly cameraId: string | null;

readonly roomId: string;
/** @internal The underlying connection id - callId */
readonly callId: string;
/** The unique identifier for the room session */

@@ -135,3 +139,10 @@ readonly roomSessionId: string;

}
export declare type SwEventParams = VideoAPIEventParams | WebRTCMessageParams | VideoManagerEvent | ChatEvent | TaskEvent | MessagingEvent | VoiceCallEvent;
export declare type SwAuthorizationState = string;
export interface SwAuthorizationStateParams {
event_type: 'signalwire.authorization.state';
params: {
authorization_state: SwAuthorizationState;
};
}
export declare type SwEventParams = VideoAPIEventParams | WebRTCMessageParams | VideoManagerEvent | ChatEvent | TaskEvent | MessagingEvent | VoiceCallEvent | SwAuthorizationStateParams;
export declare type PubSubChannelEvents = InternalVideoEventNames | SessionEvents;

@@ -138,0 +149,0 @@ export * from './video';

@@ -81,2 +81,3 @@ import type { SwEvent } from '.';

webrtcMedia?: boolean;
sessionTimeout?: number;
}

@@ -83,0 +84,0 @@ export interface NestedArray<T> extends Array<T | NestedArray<T>> {

@@ -165,5 +165,6 @@ /// <reference types="node" />

}
interface NodeSocketClient extends WebSocketClient {
export interface NodeSocketClient extends WebSocketClient {
addEventListener(method: 'open' | 'close' | 'error' | 'message', cb: (event: any) => void, options?: any): void;
removeEventListener(method: 'open' | 'close' | 'error' | 'message', cb: (event: any) => void): void;
send(data: any, cb?: (err?: Error) => void): void;
}

@@ -170,0 +171,0 @@ /**

@@ -16,3 +16,3 @@ interface InternalHttpResponse<T> extends Response {

}
export declare const createHttpClient: ({ baseUrl, timeout, ...globalOptions }: CreateHttpClientOptions, fetcher?: typeof http) => <T>(path: string, options?: HttpClientRequestInit | undefined) => Promise<{
export declare const createHttpClient: ({ baseUrl, timeout, ...globalOptions }: CreateHttpClientOptions, fetcher?: typeof http) => <T>(path: string, options?: HttpClientRequestInit) => Promise<{
body: T;

@@ -19,0 +19,0 @@ }>;

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

import { BaseJWTSession, SessionOptions } from '@signalwire/core';
import { BaseJWTSession, SessionOptions, SwAuthorizationState } from '@signalwire/core';
export declare class JWTSession extends BaseJWTSession {

@@ -14,7 +14,12 @@ options: SessionOptions;

constructor(options: SessionOptions);
get allowHijack(): any;
get allowReattach(): any;
retrieveRelayProtocol(): Promise<string>;
persistRelayProtocol(): Promise<void>;
private getRoomNameFromJWT;
protected retrieveSwAuthorizationState(): Promise<string>;
protected persistSwAuthorizationState(state: SwAuthorizationState): Promise<void>;
protected _onSocketClose(event: CloseEvent): void;
private getAuthStateSessionStorageKey;
private getProtocolSessionStorageKey;
private getSessionStorageKey;
}
//# sourceMappingURL=JWTSession.d.ts.map

@@ -13,3 +13,3 @@ /// <reference types="jest" />

runSaga: any;
}) => import("@redux-saga/types").Task;
}) => import("@redux-saga/types").Task<any>;
dispatch: import("redux").Dispatch<import("redux").AnyAction>;

@@ -33,3 +33,3 @@ getState(): any;

runSaga: any;
}) => import("@redux-saga/types").Task;
}) => import("@redux-saga/types").Task<any>;
dispatch: import("redux").Dispatch<import("redux").AnyAction>;

@@ -36,0 +36,0 @@ getState(): any;

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

*/
export declare const getDevicesWithPermissions: (kind?: DevicePermissionName | undefined, fullList?: boolean) => Promise<MediaDeviceInfo[]>;
export declare const getDevicesWithPermissions: (kind?: DevicePermissionName, fullList?: boolean) => Promise<MediaDeviceInfo[]>;
/**

@@ -114,3 +114,3 @@ * After prompting the user for permission, returns an array of camera devices.

*/
export declare const getDevices: (name?: DevicePermissionName | undefined, fullList?: boolean) => Promise<MediaDeviceInfo[]>;
export declare const getDevices: (name?: DevicePermissionName, fullList?: boolean) => Promise<MediaDeviceInfo[]>;
/**

@@ -117,0 +117,0 @@ * Returns an array of camera devices that can be accessed on this device (for which we have permissions).

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

export declare const enumerateDevices: () => Promise<MediaDeviceInfo[]>;
export declare const enumerateDevicesByKind: (filterByKind?: MediaDeviceKind | undefined) => Promise<MediaDeviceInfo[]>;
export declare const enumerateDevicesByKind: (filterByKind?: MediaDeviceKind) => Promise<MediaDeviceInfo[]>;
//# sourceMappingURL=enumerateDevices.d.ts.map

@@ -16,3 +16,3 @@ /**

*/
export declare const getDisplayMedia: (constraints?: MediaStreamConstraints | undefined) => Promise<MediaStream>;
export declare const getDisplayMedia: (constraints?: MediaStreamConstraints) => Promise<MediaStream>;
//# sourceMappingURL=getDisplayMedia.d.ts.map

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

pingSupported?: boolean;
/** @internal */
prevCallId?: string;
layout?: string;

@@ -83,0 +85,0 @@ positions?: VideoPositions;

@@ -16,3 +16,3 @@ declare type DevicePermissionName = 'camera' | 'microphone' | 'speaker';

*/
export declare const checkPermissions: (name?: DevicePermissionName | undefined) => Promise<boolean | null>;
export declare const checkPermissions: (name?: DevicePermissionName) => Promise<boolean | null>;
/**

@@ -19,0 +19,0 @@ * Asynchronously returns whether we have permissions to access the camera.

@@ -22,3 +22,3 @@ export declare const RTCPeerConnection: (config: RTCConfiguration) => RTCPeerConnection;

export declare const getSupportedConstraints: () => MediaTrackSupportedConstraints;
export declare const streamIsValid: (stream?: MediaStream | undefined) => boolean | undefined;
export declare const streamIsValid: (stream?: MediaStream) => boolean | undefined;
/**

@@ -51,6 +51,6 @@ * Returns whether the current environment supports the selection of a media output device.

export declare const sdpToJsonHack: (sdp: any) => any;
export declare const stopStream: (stream?: MediaStream | undefined) => void;
export declare const stopStream: (stream?: MediaStream) => void;
export declare const stopTrack: (track: MediaStreamTrack) => void;
export declare type DevicePermissionName = 'camera' | 'microphone' | 'speaker';
export declare const _getMediaDeviceKindByName: (name?: DevicePermissionName | undefined) => MediaDeviceKind | undefined;
export declare const _getMediaDeviceKindByName: (name?: DevicePermissionName) => MediaDeviceKind | undefined;
//# sourceMappingURL=primitives.d.ts.map

@@ -34,3 +34,3 @@ export declare const RTCPeerConnection: (config: RTCConfiguration) => any;

export declare type DevicePermissionName = 'camera' | 'microphone' | 'speaker';
export declare const _getMediaDeviceKindByName: (name?: DevicePermissionName | undefined) => MediaDeviceKind | undefined;
export declare const _getMediaDeviceKindByName: (name?: DevicePermissionName) => MediaDeviceKind | undefined;
//# sourceMappingURL=primitives.native.d.ts.map

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

"license": "MIT",
"version": "3.18.0-dev.202212271634.a594a28.0",
"version": "3.18.0-dev.202301191718.e2c475a.0",
"main": "dist/index.js",

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

"dependencies": {
"@signalwire/core": "3.13.0-dev.202212271634.a594a28.0",
"@signalwire/webrtc": "3.5.10-dev.202212271634.a594a28.0",
"@signalwire/core": "3.13.0-dev.202301191718.e2c475a.0",
"@signalwire/webrtc": "3.5.10-dev.202301191718.e2c475a.0",
"jwt-decode": "^3.1.2"

@@ -51,0 +51,0 @@ },

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

/**
* @jest-environment jsdom
*/
import WS from 'jest-websocket-mock'

@@ -2,0 +6,0 @@ import { Client } from './Client'

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

/**
* @jest-environment jsdom
*/
import WS from 'jest-websocket-mock'

@@ -2,0 +6,0 @@ import { AuthError } from '@signalwire/core'

import jwtDecode from 'jwt-decode'
import { BaseJWTSession, getLogger, SessionOptions } from '@signalwire/core'
import {
BaseJWTSession,
getLogger,
SessionOptions,
SwAuthorizationState,
} from '@signalwire/core'
import { getStorage, CALL_ID } from './utils/storage'

@@ -24,16 +30,16 @@ export class JWTSession extends BaseJWTSession {

get allowHijack() {
get allowReattach() {
// @ts-expect-error
return this.options._hijack
return this.options.reattach
}
override async retrieveRelayProtocol() {
if (!this.allowHijack) {
if (!this.allowReattach) {
return ''
}
const roomName = this.getRoomNameFromJWT()
if (roomName) {
this.logger.info('Hijacking: search protocol for', roomName)
return window.sessionStorage.getItem(roomName) ?? ''
const key = this.getProtocolSessionStorageKey()
if (key) {
this.logger.info('Hijacking: search protocol for', key)
return getStorage()?.getItem(key) ?? ''
}

@@ -44,24 +50,70 @@ return ''

override async persistRelayProtocol() {
if (!this.allowHijack) {
if (!this.allowReattach) {
return
}
const roomName = this.getRoomNameFromJWT()
if (roomName) {
this.logger.info(
'Hijacking: persist protocol',
roomName,
this.relayProtocol
)
window.sessionStorage.setItem(roomName, this.relayProtocol)
const key = this.getProtocolSessionStorageKey()
if (key) {
this.logger.info('Hijacking: persist protocol', key, this.relayProtocol)
getStorage()?.setItem(key, this.relayProtocol)
}
}
private getRoomNameFromJWT() {
protected override async retrieveSwAuthorizationState() {
const key = this.getAuthStateSessionStorageKey()
if (key) {
return getStorage()?.getItem(key) ?? ''
}
return ''
}
protected override async persistSwAuthorizationState(
state: SwAuthorizationState
) {
if (!this.allowReattach) {
return
}
const key = this.getAuthStateSessionStorageKey()
if (key) {
this.logger.info('Hijacking: persist auth state', key, state)
getStorage()?.setItem(key, state)
}
}
protected override _onSocketClose(event: CloseEvent) {
if (this.status === 'unknown') {
this.logger.info('Hijacking: invalid values - cleaning up storage')
const protocolKey = this.getProtocolSessionStorageKey()
if (protocolKey) {
getStorage()?.removeItem(protocolKey)
}
const authStatekey = this.getAuthStateSessionStorageKey()
if (authStatekey) {
getStorage()?.removeItem(authStatekey)
}
// Remove also the previous callId
getStorage()?.removeItem(CALL_ID)
}
super._onSocketClose(event)
}
private getAuthStateSessionStorageKey() {
return `as-${this.getSessionStorageKey()}`
}
private getProtocolSessionStorageKey() {
return `pt-${this.getSessionStorageKey()}`
}
private getSessionStorageKey() {
try {
const jwtPayload = jwtDecode<{ r: string }>(this.options.token)
return jwtPayload?.r
const jwtPayload = jwtDecode<{ r: string; ja: string }>(
this.options.token
)
return `${jwtPayload?.r}-${jwtPayload?.ja}`
} catch (e) {
if (process.env.NODE_ENV !== 'production') {
getLogger().error('[getRoomNameFromJWT] error decoding the JWT')
getLogger().error('[getSessionStorageKey] error decoding the JWT')
}

@@ -68,0 +120,0 @@ return ''

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

/**
* @jest-environment jsdom
*/
import WS from 'jest-websocket-mock'

@@ -2,0 +6,0 @@ import { Client } from './Client'

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

import { UserOptions, getLogger, VideoAuthorization } from '@signalwire/core'
import {
UserOptions,
getLogger,
VideoAuthorization,
VideoRoomSubscribedEventParams,
} from '@signalwire/core'
import { createClient } from './createClient'

@@ -7,2 +12,3 @@ import { BaseRoomSession } from './BaseRoomSession'

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

@@ -115,2 +121,32 @@ /**

// @ts-expect-error
const allowReattach = Boolean(roomOptions.reattach)
const reattachManager = {
joined: ({ call_id }: VideoRoomSubscribedEventParams) => {
if (allowReattach) {
getStorage()?.setItem(CALL_ID, call_id)
}
},
init: () => {
if (!allowReattach) {
return
}
room.on('room.subscribed', reattachManager.joined)
const prevCallId = getStorage()?.getItem(CALL_ID)
if (prevCallId) {
room.options.prevCallId = prevCallId
}
},
destroy: () => {
if (!allowReattach) {
return
}
room.off('room.subscribed', reattachManager.joined)
getStorage()?.removeItem(CALL_ID)
},
}
// WebRTC connection left the room.

@@ -120,2 +156,5 @@ room.once('destroy', () => {

room.emit('room.left')
// Remove callId to reattach
reattachManager.destroy()
client.disconnect()

@@ -179,2 +218,5 @@ })

// Hijack previous callId if present
reattachManager.init()
await room.join()

@@ -181,0 +223,0 @@ } catch (error) {

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 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 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

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