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

@signalwire/core

Package Overview
Dependencies
Maintainers
5
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@signalwire/core - npm Package Compare versions

Comparing version 4.0.0-beta.0 to 4.0.0-dev.202401261322.b0761a1.1

dist/core/src/RPCMessages/RPCEventAck.d.ts

2

dist/core/src/BaseComponent.d.ts

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

/** @internal */
execute<InputType = unknown, OutputType = unknown, ParamsType = Record<string, any>>({ method, params }: ExecuteParams, { transformParams, transformResolve, transformReject, }?: ExecuteExtendedOptions<InputType, OutputType, ParamsType>): Promise<OutputType>;
execute<InputType = unknown, OutputType = unknown, ParamsType = Record<string, any>>({ method, params, self }: ExecuteParams, { transformParams, transformResolve, transformReject, }?: ExecuteExtendedOptions<InputType, OutputType, ParamsType>): Promise<OutputType>;
/** @internal */

@@ -86,0 +86,0 @@ triggerCustomSaga<T>(action: Action): Promise<T>;

import { SWCloseEvent } from './utils';
import { RPCConnectParams } from './RPCMessages';
import { SessionOptions, RPCConnectResult, JSONRPCRequest, JSONRPCResponse, WebSocketAdapter, NodeSocketAdapter, WebSocketClient, SessionStatus, SessionAuthError } from './utils/interfaces';

@@ -20,2 +21,3 @@ import { SwAuthorizationState } from '.';

reauthenticate?(): Promise<void>;
unifiedEventing: boolean;
protected _rpcConnectResult: RPCConnectResult;

@@ -77,2 +79,3 @@ private _requests;

execute(msg: JSONRPCRequest | JSONRPCResponse): Promise<any>;
protected get _connectParams(): RPCConnectParams;
/**

@@ -108,2 +111,3 @@ * Authenticate with the SignalWire Network

private _pingHandler;
private _eventAcknowledgingHandler;
/**

@@ -110,0 +114,0 @@ * Do something based on the current `this._status`

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

import { JSONRPCResponse, JSONRPCRequest, SessionAuthError, SessionAuthStatus, SessionEvents, JSONRPCMethod, BaseConnectionState, Authorization } from '../utils/interfaces';
import type { VideoAction, ChatAction, TaskAction, MessagingAction, SwEventParams, VoiceCallAction, VideoManagerAction, PubSubEventAction } from '../types';
import type { VideoAction, ChatAction, TaskAction, MessagingAction, SwEventParams, VoiceCallAction, VideoManagerAction, PubSubEventAction, InternalUnifiedActionTarget } from '../types';
import { SDKRunSaga } from '.';

@@ -17,2 +17,3 @@ interface SWComponent {

export interface WebRTCCall extends SWComponent {
self?: InternalUnifiedActionTarget;
state?: BaseConnectionState;

@@ -19,0 +20,0 @@ remoteSDP?: string;

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

readonly [x: string]: {
readonly self?: {
readonly id: string;
readonly callId: string;
readonly nodeId: string;
} | undefined;
readonly state?: import("..").BaseConnectionState | undefined;

@@ -7,0 +12,0 @@ readonly remoteSDP?: string | undefined;

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

import { BaseComponent, EventEmitter } from '..';
import { BaseComponent, EventEmitter, InternalUnifiedActionTarget } from '..';
export interface BaseRoomInterface<EventTypes extends EventEmitter.ValidEventTypes> extends BaseComponent<EventTypes> {

@@ -6,2 +6,3 @@ roomId: string;

memberId: string;
self: InternalUnifiedActionTarget;
}

@@ -8,0 +9,0 @@ export * from './methods';

@@ -8,2 +8,3 @@ export * from './helpers';

export * from './VertoMessages';
export * from './RPCEventAck';
//# sourceMappingURL=index.d.ts.map

@@ -20,2 +20,4 @@ declare type WithToken = {

topics?: string[];
eventing?: string[];
event_acks?: boolean;
};

@@ -27,2 +29,7 @@ export declare const DEFAULT_CONNECT_VERSION: {

};
export declare const UNIFIED_CONNECT_VERSION: {
major: number;
minor: number;
revision: number;
};
export declare const RPCConnect: (params: RPCConnectParams) => {

@@ -36,3 +43,11 @@ id: string;

};
export declare const RPCConnectUnified: (params: RPCConnectParams) => {
id: string;
method: import("..").JSONRPCMethod;
params: {
[key: string]: any;
};
jsonrpc: "2.0";
};
export {};
//# sourceMappingURL=RPCConnect.d.ts.map

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

export * from './voice';
export * from './callfabric';
//# sourceMappingURL=index.d.ts.map

@@ -68,3 +68,6 @@ export declare type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${CamelToSnakeCase<U>}` : S;

};
export declare type Prettify<T> = {
[K in keyof T]: Prettify<T[K]>;
} & {};
export {};
//# sourceMappingURL=utils.d.ts.map

@@ -275,2 +275,7 @@ import type { SwEvent, VideoPosition } from '.';

};
export interface InternalUnifiedVideoMemberEntity extends InternalVideoMemberEntity {
callId: string;
nodeId: string;
}
export declare type InternalUnifiedActionTarget = Pick<InternalUnifiedVideoMemberEntity, 'id' | 'callId' | 'nodeId'>;
/**

@@ -277,0 +282,0 @@ * VideoMember entity plus `updated` field

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

member_id: string;
node_id?: string;
}

@@ -838,0 +839,0 @@ export interface VideoRoomSubscribedEvent extends SwEvent {

@@ -9,3 +9,3 @@ /// <reference types="node" />

import type { URL as NodeURL } from 'node:url';
import { AllOrNone, ChatJSONRPCMethod, MessagingJSONRPCMethod, VoiceJSONRPCMethod, ClientContextMethod } from '..';
import { AllOrNone, ChatJSONRPCMethod, MessagingJSONRPCMethod, VoiceJSONRPCMethod, ClientContextMethod, InternalUnifiedActionTarget } from '..';
declare type JSONRPCParams = Record<string, any>;

@@ -49,2 +49,3 @@ declare type JSONRPCResult = Record<string, any>;

/** To refresh the auth token */
unifiedEventing?: boolean;
onRefreshToken?(): Promise<void>;

@@ -211,2 +212,3 @@ /**

params: Record<string, any>;
self?: InternalUnifiedActionTarget;
};

@@ -213,0 +215,0 @@ export interface ExecuteExtendedOptions<InputType, OutputType, ParamsType> {

@@ -6,3 +6,6 @@ import { MapToPubSubShape } from '../redux/interfaces';

node_id?: string | undefined;
}>(event: T) => MapToPubSubShape<T>;
}>(event: T) => MapToPubSubShape<T> | {
type: string;
payload: any;
};
//# sourceMappingURL=toInternalAction.d.ts.map

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

"license": "MIT",
"version": "4.0.0-beta.0",
"version": "4.0.0-dev.202401261322.b0761a1.1",
"main": "dist/index.node.js",

@@ -9,0 +9,0 @@ "module": "dist/index.esm.js",

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

>(
{ method, params }: ExecuteParams,
{ method, params, self }: ExecuteParams,
{

@@ -201,2 +201,3 @@ transformParams = identity,

initialState: {
self,
requestId,

@@ -203,0 +204,0 @@ componentId: this.__uuid,

@@ -67,4 +67,3 @@ import {

const params: RPCConnectParams = {
agent: this.agent,
version: this.connectVersion,
...this._connectParams,
authentication: {

@@ -71,0 +70,0 @@ jwt_token: this.options.token,

@@ -9,2 +9,3 @@ import WS from 'jest-websocket-mock'

RPCDisconnectResponse,
RPCConnectUnified,
} from './RPCMessages'

@@ -39,9 +40,11 @@ import { SWCloseEvent } from './utils'

const parsedData = JSON.parse(data)
socket.send(
JSON.stringify({
jsonrpc: '2.0',
id: parsedData.id,
result: {},
})
)
if (parsedData.params) {
socket.send(
JSON.stringify({
jsonrpc: '2.0',
id: parsedData.id,
result: {},
})
)
}
})

@@ -63,2 +66,37 @@ })

it('should include events_ack on RPCConnect message', () => {
expect(rpcConnect.params.event_acks).toBeTruthy()
})
it('should subscribe to unified event when session the initialize with unifiedEventing:true', async () => {
const unifiedEventingSession = new BaseSession({
host,
project,
token,
unifiedEventing: true,
})
const rpcConnectUnified = RPCConnectUnified({
authentication: {
project,
token,
}
})
unifiedEventingSession.WebSocketConstructor = WebSocket
unifiedEventingSession.CloseEventConstructor = SWCloseEvent
unifiedEventingSession.dispatch = jest.fn()
unifiedEventingSession.connect()
await ws.connected
expect(unifiedEventingSession.connected).toBe(true)
await expect(ws).toReceiveMessage(JSON.stringify(rpcConnectUnified))
unifiedEventingSession.disconnect()
expect(unifiedEventingSession.connected).toBe(false)
expect(unifiedEventingSession.closed).toBe(true)
})
it('should connect and disconnect to/from the provided host', async () => {

@@ -104,19 +142,47 @@ session.connect()

it('should invoke dispatch with socketMessage action for any other message', async () => {
session.connect()
await ws.connected
describe('signalwire.event messages', () => {
it('should invoke dispatch with socketMessage action for any other message', async () => {
session.connect()
await ws.connected
await expect(ws).toReceiveMessage(JSON.stringify(rpcConnect))
const request = {
jsonrpc: '2.0' as const,
id: 'uuid',
method: 'signalwire.event' as const,
params: {
key: 'value',
},
}
ws.send(JSON.stringify(request))
await expect(ws).toReceiveMessage(JSON.stringify(rpcConnect))
const request = {
jsonrpc: '2.0' as const,
id: 'uuid',
method: 'signalwire.event' as const,
params: {
key: 'value',
},
}
ws.send(JSON.stringify(request))
expect(session.dispatch).toHaveBeenCalledTimes(1)
expect(session.dispatch).toHaveBeenCalledWith(socketMessageAction(request))
expect(session.dispatch).toHaveBeenCalledTimes(1)
expect(session.dispatch).toHaveBeenCalledWith(
socketMessageAction(request)
)
})
it('should send acknowledge message on signalwire.event', async () => {
session.connect()
await ws.connected
await expect(ws).toReceiveMessage(JSON.stringify(rpcConnect))
const request = {
jsonrpc: '2.0' as const,
id: 'uuid',
method: 'signalwire.event' as const,
params: {
key: 'value',
},
}
ws.send(JSON.stringify(request))
await expect(ws).toReceiveMessage(
JSON.stringify({
jsonrpc: '2.0' as const,
id: 'uuid',
result: {},
})
)
})
})

@@ -123,0 +189,0 @@

@@ -19,2 +19,4 @@ import {

RPCPingResponse,
RPCEventAckResponse,
UNIFIED_CONNECT_VERSION,
} from './RPCMessages'

@@ -63,2 +65,3 @@ import {

public reauthenticate?(): Promise<void>
public unifiedEventing = false

@@ -87,3 +90,15 @@ protected _rpcConnectResult: RPCConnectResult

constructor(public options: SessionOptions) {
const { host, logLevel = 'info', sessionChannel } = options
const {
host,
logLevel = 'info',
sessionChannel,
unifiedEventing = false,
} = options
this.unifiedEventing = unifiedEventing
this.connectVersion = unifiedEventing
? UNIFIED_CONNECT_VERSION
: DEFAULT_CONNECT_VERSION
if (host) {

@@ -344,8 +359,4 @@ this._host = checkWebSocketHost(host)

/**
* Authenticate with the SignalWire Network
* @return Promise<void>
*/
async authenticate() {
const params: RPCConnectParams = {
protected get _connectParams(): RPCConnectParams {
return {
agent: this.agent,

@@ -357,3 +368,14 @@ version: this.connectVersion,

},
// FIXME: Remove this once server is ready
// eventing: this.unifiedEventing ? ['unified'] : undefined,
}
}
/**
* Authenticate with the SignalWire Network
* @return Promise<void>
*/
async authenticate() {
const params: RPCConnectParams = this._connectParams
if (this._relayProtocolIsValid()) {

@@ -478,2 +500,5 @@ params.protocol = this.relayProtocol

default:
this._eventAcknowledgingHandler(payload).catch((error) =>
this.logger.error('Event Acknowledging Error', error)
)
// If it's not a response, trigger the dispatch.

@@ -565,2 +590,12 @@ this.dispatch(socketMessageAction(payload))

private async _eventAcknowledgingHandler(
payload: JSONRPCRequest
): Promise<void> {
const { method, id } = payload
if (method === 'signalwire.event') {
return this.execute(RPCEventAckResponse(id))
}
return Promise.resolve()
}
/**

@@ -567,0 +602,0 @@ * Do something based on the current `this._status`

@@ -23,2 +23,3 @@ import type { Channel, SagaIterator } from '@redux-saga/types'

PubSubEventAction,
InternalUnifiedActionTarget,
} from '../types'

@@ -37,2 +38,3 @@ import { SDKRunSaga } from '.'

export interface WebRTCCall extends SWComponent {
self?: InternalUnifiedActionTarget,
state?: BaseConnectionState

@@ -39,0 +41,0 @@ remoteSDP?: string

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

import { BaseComponent, EventEmitter } from '..'
import { BaseComponent, EventEmitter, InternalUnifiedActionTarget } from '..'

@@ -9,2 +9,3 @@ export interface BaseRoomInterface<

memberId: string
self: InternalUnifiedActionTarget
}

@@ -11,0 +12,0 @@

@@ -93,2 +93,3 @@ import {

},
self: this.self
},

@@ -520,2 +521,5 @@ options

transformResolve: baseCodeTransform,
transformParams: (payload) => {
return payload
}
}

@@ -522,0 +526,0 @@ )

@@ -34,2 +34,3 @@ import {

version: DEFAULT_CONNECT_VERSION,
event_acks: true,
},

@@ -55,2 +56,3 @@ })

contexts: ['test'],
event_acks: true,
},

@@ -70,2 +72,3 @@ })

version: DEFAULT_CONNECT_VERSION,
event_acks: true,
},

@@ -92,2 +95,3 @@ })

agent: 'Jest Random Test',
event_acks: true,
},

@@ -111,2 +115,3 @@ })

agent: 'Jest Random Test',
event_acks: true,
},

@@ -113,0 +118,0 @@ })

@@ -8,1 +8,2 @@ export * from './helpers'

export * from './VertoMessages'
export * from './RPCEventAck'

@@ -14,2 +14,4 @@ import { makeRPCRequest } from './helpers'

topics?: string[]
eventing?: string[]
event_acks?: boolean
}

@@ -23,2 +25,8 @@

export const UNIFIED_CONNECT_VERSION = {
major: 4,
minor: 0,
revision: 0,
}
export const RPCConnect = (params: RPCConnectParams) => {

@@ -29,2 +37,3 @@ return makeRPCRequest({

version: DEFAULT_CONNECT_VERSION,
event_acks: true,
...params,

@@ -34,1 +43,12 @@ },

}
export const RPCConnectUnified = (params: RPCConnectParams) => {
return makeRPCRequest({
method: 'signalwire.connect',
params: {
version: UNIFIED_CONNECT_VERSION,
event_acks: true,
...params,
},
})
}

@@ -240,1 +240,2 @@ import type { EventEmitter } from '../utils/EventEmitter'

export * from './voice'
export * from './callfabric'

@@ -143,1 +143,8 @@ export type CamelToSnakeCase<S extends string> =

}
/*
* Type Debug Helper
*/
export type Prettify<T> = {
[K in keyof T]: Prettify<T[K]>
} & {}

@@ -357,2 +357,8 @@ import { PRODUCT_PREFIX_VIDEO } from '../utils/constants'

export interface InternalUnifiedVideoMemberEntity extends InternalVideoMemberEntity {
callId: string,
nodeId: string
}
export type InternalUnifiedActionTarget = Pick<InternalUnifiedVideoMemberEntity, 'id' | 'callId' |'nodeId'>
/**

@@ -359,0 +365,0 @@ * VideoMember entity plus `updated` field

@@ -908,2 +908,3 @@ import type { BaseConnectionContract, SwEvent } from '.'

member_id: string
node_id?: string
}

@@ -910,0 +911,0 @@

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

ClientContextMethod,
InternalUnifiedActionTarget,
} from '..'

@@ -113,2 +114,5 @@

/** To refresh the auth token */
unifiedEventing?: boolean,
onRefreshToken?(): Promise<void>

@@ -394,2 +398,3 @@ /**

params: Record<string, any>
self?: InternalUnifiedActionTarget
}

@@ -396,0 +401,0 @@

@@ -23,2 +23,14 @@ import { JSONRPCRequest } from '..'

// FIXME This is a hack until we can get the nodeId from the members for the unified methods
if(event_type === 'call.joined') {
return {
type: event_type,
payload: {
//@ts-ignore
...params,
node_id: node_id
}
}
}
/**

@@ -25,0 +37,0 @@ * `webrtc.*` events need to carry the node_id with them

@@ -7,2 +7,3 @@ import { call } from '@redux-saga/core/effects'

import type { ExecuteActionParams } from '../redux/interfaces'
import { UnifiedRequestMapper } from '../utils/UnifiedRequestMapper'

@@ -15,6 +16,6 @@ /**

): SagaIterator {
const { initialState, onDone, onFail, getSession } = options
const { initialState, onDone, onFail, getSession, instanceMap } = options
const { requestId, method, params, self, componentId } = initialState
const { requestId, method, params } = initialState
const session = getSession()

@@ -30,3 +31,3 @@

try {
const message = RPCExecute({
let message = RPCExecute({
id: requestId,

@@ -36,2 +37,17 @@ method,

})
if(session.unifiedEventing && message.method in UnifiedRequestMapper) {
const component = instanceMap.get(componentId)
console.log('@#$')
console.log(component)
// FIXME we need to lookup the target from the memberList
const target = {
...self,
member_id: params.member_id
}
//@ts-expect-error
message = UnifiedRequestMapper[message.method](message, self, target)
}
const response = yield call(session.execute, message)

@@ -38,0 +54,0 @@ onDone?.(response)

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

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

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