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

@signalwire/core

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@signalwire/core - npm Package Compare versions

Comparing version 3.4.0-dev.202111101133.b962aa0.0 to 3.4.0-dev.202111121613.f6a4e9d.0

import { Action } from '@reduxjs/toolkit';
import { Task } from '@redux-saga/types';
import type { Task } from '@redux-saga/types';
import { ExecuteParams, BaseComponentOptions, ExecuteExtendedOptions, EventsPrefix, EventTransform, SDKWorker } from './utils/interfaces';

@@ -22,3 +22,3 @@ import { EventEmitter } from './utils/EventEmitter';

private _destroyer?;
protected get logger(): import("./utils/interfaces").SDKLogger;
protected get logger(): import("./utils/interfaces").InternalSDKLogger;
/**

@@ -25,0 +25,0 @@ * A Namespace let us scope specific instances inside of a

import { PayloadAction } from '@reduxjs/toolkit';
import { SessionOptions, RPCConnectResult, JSONRPCRequest, JSONRPCResponse, WebSocketAdapter, NodeSocketAdapter, SessionStatus } from './utils/interfaces';
import { SessionOptions, RPCConnectResult, JSONRPCRequest, JSONRPCResponse, WebSocketAdapter, NodeSocketAdapter, WebSocketClient, SessionStatus } from './utils/interfaces';
export declare class BaseSession {

@@ -28,3 +28,3 @@ options: SessionOptions;

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

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

*/
protected _createSocket(): import("./utils/interfaces").NodeSocketClient;
protected _createSocket(): WebSocketClient;
/**

@@ -49,0 +49,0 @@ * Clear the Session and close the WS connection.

@@ -13,3 +13,2 @@ import { uuid, setLogger, getLogger, isGlobalEvent, toExternalJSON, toLocalEvent, extendComponent } from './utils';

export * from './RPCMessages';
export * from './internal';
export * from './utils/interfaces';

@@ -21,3 +20,3 @@ export * from './types';

export * as sagaHelpers from './redux/utils/sagaHelpers';
export * as sagaEffects from 'redux-saga/effects';
export * as sagaEffects from '@redux-saga/core/effects';
export type { SagaIterator, Task, Saga } from '@redux-saga/types';

@@ -24,0 +23,0 @@ export * as Rooms from './rooms';

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

import { SagaIterator } from 'redux-saga';
import { SagaIterator } from '@redux-saga/core';
export declare function executeQueueWatcher(): SagaIterator;
export declare function flushExecuteQueueWorker(): SagaIterator;
//# sourceMappingURL=executeQueueSaga.d.ts.map

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

import { SagaIterator } from 'redux-saga';
import { SagaIterator } from '@redux-saga/core';
import type { EventEmitter } from '../../../utils/EventEmitter';

@@ -3,0 +3,0 @@ import type { PubSubChannel } from '../../interfaces';

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

import { SagaIterator, EventChannel } from 'redux-saga';
import { SagaIterator, EventChannel } from '@redux-saga/core';
import { BaseSession } from '../../../BaseSession';

@@ -3,0 +3,0 @@ import { PubSubChannel } from '../../interfaces';

@@ -12,3 +12,3 @@ import { SDKState } from './interfaces';

declare const configureStore: (options: ConfigureStoreOptions) => {
runSaga: <S extends import("redux-saga").Saga<any[]>>(saga: S, ...args: Parameters<S>) => import("redux-saga").Task;
runSaga: <S extends import("@redux-saga/types").Saga<any[]>>(saga: S, ...args: Parameters<S>) => import("@redux-saga/types").Task;
dispatch: import("redux-thunk").ThunkDispatch<import("redux").CombinedState<{

@@ -15,0 +15,0 @@ components: Readonly<import("./interfaces").ComponentState>;

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

import { SagaIterator } from '@redux-saga/types';
import { EventChannel } from 'redux-saga';
import type { SagaIterator } from '@redux-saga/types';
import { EventChannel } from '@redux-saga/core';
import { SessionConstructor, InternalUserOptions } from '../utils/interfaces';

@@ -17,10 +17,10 @@ import { BaseSession } from '../BaseSession';

pubSubChannel: PubSubChannel;
}): Generator<import("redux-saga/effects").ChannelPutEffect<import("./interfaces").MapToPubSubShape<import("..").VideoRecordingStartedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRecordingUpdatedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRecordingEndedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoPlaybackStartedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoPlaybackUpdatedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoPlaybackEndedEvent> | import("./interfaces").MapToPubSubShape<import("..").InternalVideoMemberUpdatedEvent> | import("./interfaces").MapToPubSubShape<import("..").InternalVideoMemberTalkingEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoMemberJoinedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoMemberUpdatedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoMemberLeftEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoMemberTalkingEvent> | import("./interfaces").MapToPubSubShape<import("..").InternalVideoRoomJoinedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRoomStartedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRoomSubscribedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRoomUpdatedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRoomEndedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoLayoutChangedEvent> | {
}): Generator<import("@redux-saga/core/effects").ChannelPutEffect<import("./interfaces").MapToPubSubShape<import("..").VideoRecordingStartedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRecordingUpdatedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRecordingEndedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoPlaybackStartedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoPlaybackUpdatedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoPlaybackEndedEvent> | import("./interfaces").MapToPubSubShape<import("..").InternalVideoMemberUpdatedEvent> | import("./interfaces").MapToPubSubShape<import("..").InternalVideoMemberTalkingEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoMemberJoinedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoMemberUpdatedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoMemberLeftEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoMemberTalkingEvent> | import("./interfaces").MapToPubSubShape<import("..").InternalVideoRoomJoinedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRoomStartedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRoomSubscribedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRoomUpdatedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoRoomEndedEvent> | import("./interfaces").MapToPubSubShape<import("..").VideoLayoutChangedEvent> | {
type: "session.connected" | "session.unknown" | "session.idle" | "session.reconnecting" | "session.disconnected";
payload: undefined;
}> | import("redux-saga/effects").CallEffect<void> | import("redux-saga/effects").CallEffect<true>, void, unknown>;
}> | import("@redux-saga/core/effects").CallEffect<void> | import("@redux-saga/core/effects").CallEffect<true>, void, unknown>;
export declare function reauthenticateWorker({ session, token, }: {
session: BaseSession;
token: string;
}): Generator<import("redux-saga/effects").CallEffect<void>, void, unknown>;
}): Generator<import("@redux-saga/core/effects").CallEffect<void>, void, unknown>;
export declare function sessionStatusWatcher(options: StartSagaOptions): SagaIterator;

@@ -27,0 +27,0 @@ export declare function startSaga(options: StartSagaOptions): SagaIterator;

export declare const createRestartableSaga: (saga: any) => () => Generator<never, void, unknown>;
export declare const createCatchableSaga: (saga: any) => () => Generator<import("redux-saga/effects").CallEffect<unknown>, void, unknown>;
export declare const createCatchableSaga: (saga: any) => () => Generator<import("@redux-saga/core/effects").CallEffect<unknown>, void, unknown>;
//# sourceMappingURL=sagaHelpers.d.ts.map
import { PubSubChannel } from './redux/interfaces';
import { RPCConnectResult, SDKLogger } from './utils/interfaces';
export declare const mockLogger: SDKLogger;
import { RPCConnectResult, InternalSDKLogger } from './utils/interfaces';
export declare const createMockedLogger: () => InternalSDKLogger;
/**

@@ -11,3 +11,3 @@ * Helper method to configure a Store w/o Saga middleware.

export declare const configureJestStore: () => {
runSaga: <S extends import("redux-saga").Saga<any[]>>(saga: S, ...args: Parameters<S>) => import("redux-saga").Task;
runSaga: <S extends import("@redux-saga/types").Saga<any[]>>(saga: S, ...args: Parameters<S>) => import("@redux-saga/types").Task;
dispatch: import("redux-thunk").ThunkDispatch<import("redux").CombinedState<{

@@ -14,0 +14,0 @@ components: Readonly<import("./redux/interfaces").ComponentState>;

@@ -19,5 +19,5 @@ import type { EventEmitter } from '../utils/EventEmitter';

/** The id of the video device, or null if not available */
get cameraId(): string | null;
readonly cameraId: string | null;
/** The label of the video device, or null if not available */
get cameraLabel(): string | null;
readonly cameraLabel: string | null;
/**

@@ -27,5 +27,5 @@ * Provides access to the local audio

*/
get localAudioTrack(): MediaStreamTrack | null;
readonly localAudioTrack: MediaStreamTrack | null;
/** Provides access to the local [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream) */
get localStream(): MediaStream | undefined;
readonly localStream: MediaStream | undefined;
/**

@@ -35,19 +35,19 @@ * Provides access to the local video

*/
get localVideoTrack(): MediaStreamTrack | null;
readonly localVideoTrack: MediaStreamTrack | null;
/** The id of the audio input device, or null if not available */
get microphoneId(): string | null;
readonly microphoneId: string | null;
/** The label of the audio input device, or null if not available */
get microphoneLabel(): string | null;
readonly microphoneLabel: string | null;
/**
* Provides access to the remote [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream)
*/
get remoteStream(): MediaStream | undefined;
readonly remoteStream: MediaStream | undefined;
/** The unique identifier for the room */
get roomId(): string;
readonly roomId: string;
/** The unique identifier for the room session */
get roomSessionId(): string;
readonly roomSessionId: string;
/** Whether the connection is currently active */
get active(): boolean;
readonly active: boolean;
/** The id of the current member within the room */
get memberId(): string;
readonly memberId: string;
updateCamera(constraints: MediaTrackConstraints): Promise<void>;

@@ -54,0 +54,0 @@ updateMicrophone(constraints: MediaTrackConstraints): Promise<void>;

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

export { setLogger, getLogger } from './logger';
export { setLogger, getLogger, setDebugOptions } from './logger';
export { v4 as uuid } from 'uuid';

@@ -3,0 +3,0 @@ export * from './parseRPCResponse';

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

import type { URL as NodeURL } from 'node:url';
import { InternalRPCMethods } from '../internal';
declare type JSONRPCParams = Record<string, any>;

@@ -15,3 +14,3 @@ declare type JSONRPCResult = Record<string, any>;

export declare type VertoMethod = 'verto.invite' | 'verto.attach' | 'verto.answer' | 'verto.info' | 'verto.display' | 'verto.media' | 'verto.event' | 'verto.bye' | 'verto.punt' | 'verto.broadcast' | 'verto.subscribe' | 'verto.unsubscribe' | 'verto.clientReady' | 'verto.modify' | 'verto.mediaParams' | 'verto.prompt' | 'jsapi' | 'verto.stats' | 'verto.ping' | 'verto.announce';
export declare type JSONRPCMethod = 'signalwire.connect' | 'signalwire.ping' | 'signalwire.disconnect' | 'signalwire.event' | 'signalwire.reauthenticate' | 'signalwire.subscribe' | 'video.message' | RoomMethod | VertoMethod | InternalRPCMethods;
export declare type JSONRPCMethod = 'signalwire.connect' | 'signalwire.ping' | 'signalwire.disconnect' | 'signalwire.event' | 'signalwire.reauthenticate' | 'signalwire.subscribe' | 'video.message' | RoomMethod | VertoMethod;
export interface JSONRPCRequest {

@@ -49,2 +48,8 @@ jsonrpc: '2.0';

devTools?: boolean;
/** @internal */
debug?: {
logWsTraffic?: boolean;
};
/** @internal */
logger?: SDKLogger;
}

@@ -254,3 +259,10 @@ export interface InternalUserOptions extends UserOptions {

}
export interface WsTrafficOptions {
type: 'send' | 'recv';
payload: JSONRPCResponse | JSONRPCRequest;
}
export interface InternalSDKLogger extends SDKLogger {
wsTraffic: (options: WsTrafficOptions) => void;
}
export {};
//# sourceMappingURL=interfaces.d.ts.map

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

import { SDKLogger } from '..';
import type { SDKLogger, InternalSDKLogger } from '..';
declare const setLogger: (logger: SDKLogger | null) => void;
declare const getLogger: () => SDKLogger;
export { setLogger, getLogger };
declare const setDebugOptions: (options: any) => void;
declare const getLogger: () => InternalSDKLogger;
export { setLogger, getLogger, setDebugOptions };
//# sourceMappingURL=logger.d.ts.map

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

"license": "MIT",
"version": "3.4.0-dev.202111101133.b962aa0.0",
"version": "3.4.0-dev.202111121613.f6a4e9d.0",
"main": "dist/index.node.js",

@@ -41,2 +41,3 @@ "module": "dist/index.esm.js",

"dependencies": {
"@redux-saga/core": "^1.1.3",
"@reduxjs/toolkit": "^1.6.0",

@@ -46,3 +47,2 @@ "@types/uuid": "^8.3.0",

"loglevel": "^1.7.1",
"redux-saga": "^1.1.3",
"redux-saga-test-plan": "^4.0.1",

@@ -49,0 +49,0 @@ "uuid": "^8.3.2"

import { Action } from '@reduxjs/toolkit'
import { Task } from '@redux-saga/types'
import type { Task } from '@redux-saga/types'
import {

@@ -4,0 +4,0 @@ uuid,

@@ -203,3 +203,3 @@ import { PayloadAction } from '@reduxjs/toolkit'

this.logger.trace('SEND: \n', JSON.stringify(msg, null, 2), '\n')
this.logger.wsTraffic({ type: 'send', payload: msg })
this._socket!.send(JSON.stringify(msg))

@@ -268,3 +268,3 @@

const payload: any = safeParseJson(event.data)
this.logger.trace('RECV: \n', JSON.stringify(payload, null, 2), '\n')
this.logger.wsTraffic({ type: 'recv', payload })
const request = this._requests.get(payload.id)

@@ -271,0 +271,0 @@ if (request) {

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

export * from './RPCMessages'
export * from './internal'
export * from './utils/interfaces'

@@ -59,3 +58,3 @@ export * from './types'

export * as sagaHelpers from './redux/utils/sagaHelpers'
export * as sagaEffects from 'redux-saga/effects'
export * as sagaEffects from '@redux-saga/core/effects'
export type { SagaIterator, Task, Saga } from '@redux-saga/types'

@@ -62,0 +61,0 @@ export * as Rooms from './rooms'

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

import { SagaIterator } from 'redux-saga'
import { put, take, fork, select } from 'redux-saga/effects'
import { SagaIterator } from '@redux-saga/core'
import { put, take, fork, select } from '@redux-saga/core/effects'
import { PayloadAction } from '@reduxjs/toolkit'

@@ -4,0 +4,0 @@ import { ExecuteActionParams } from '../../interfaces'

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

import { SagaIterator } from 'redux-saga'
import { take } from 'redux-saga/effects'
import { SagaIterator } from '@redux-saga/core'
import { take } from '@redux-saga/core/effects'
import {

@@ -4,0 +4,0 @@ isInternalGlobalEvent,

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

import { eventChannel } from 'redux-saga'
import { eventChannel } from '@redux-saga/core'
import { expectSaga } from 'redux-saga-test-plan'

@@ -3,0 +3,0 @@ import { VertoResult } from '../../../RPCMessages'

@@ -1,3 +0,10 @@

import { SagaIterator, eventChannel, EventChannel } from 'redux-saga'
import { call, put, take, fork, select, cancelled } from 'redux-saga/effects'
import { SagaIterator, eventChannel, EventChannel } from '@redux-saga/core'
import {
call,
put,
take,
fork,
select,
cancelled,
} from '@redux-saga/core/effects'
import { PayloadAction } from '@reduxjs/toolkit'

@@ -4,0 +11,0 @@ import { BaseSession } from '../../../BaseSession'

import { configureStore as rtConfigureStore } from '@reduxjs/toolkit'
import createSagaMiddleware from 'redux-saga'
import createSagaMiddleware from '@redux-saga/core'
import { rootReducer } from './rootReducer'

@@ -4,0 +4,0 @@ import rootSaga from './rootSaga'

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

import { channel, eventChannel } from 'redux-saga'
import { channel, eventChannel } from '@redux-saga/core'
import { expectSaga, testSaga } from 'redux-saga-test-plan'

@@ -3,0 +3,0 @@ import rootSaga, {

@@ -1,6 +0,6 @@

import { Task, SagaIterator } from '@redux-saga/types'
import { channel, EventChannel } from 'redux-saga'
import { fork, call, take, put, delay, all } from 'redux-saga/effects'
import type { Task, SagaIterator } from '@redux-saga/types'
import { channel, EventChannel } from '@redux-saga/core'
import { fork, call, take, put, delay, all } from '@redux-saga/core/effects'
import { SessionConstructor, InternalUserOptions } from '../utils/interfaces'
import { getLogger } from '../utils'
import { getLogger, setDebugOptions, setLogger } from '../utils'
import { BaseSession } from '../BaseSession'

@@ -217,2 +217,9 @@ import {

return function* root(userOptions: InternalUserOptions): SagaIterator {
if (userOptions.logger) {
setLogger(userOptions.logger)
}
if (userOptions.debug) {
setDebugOptions(userOptions.debug)
}
yield fork(executeQueueWatcher)

@@ -219,0 +226,0 @@

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

import { call, spawn } from 'redux-saga/effects'
import { call, spawn } from '@redux-saga/core/effects'
import { getLogger } from '../../utils'

@@ -3,0 +3,0 @@

@@ -1,6 +0,6 @@

import { channel } from 'redux-saga'
import { channel } from '@redux-saga/core'
import { configureStore } from './redux'
import { PubSubChannel } from './redux/interfaces'
import { BaseSession } from './BaseSession'
import { RPCConnectResult, SDKLogger } from './utils/interfaces'
import { RPCConnectResult, InternalSDKLogger } from './utils/interfaces'
import { EventEmitter } from './utils/EventEmitter'

@@ -11,3 +11,3 @@

export const mockLogger: SDKLogger = {
export const createMockedLogger = (): InternalSDKLogger => ({
fatal: jest.fn(),

@@ -19,3 +19,4 @@ error: jest.fn(),

trace: jest.fn(),
}
wsTraffic: jest.fn(),
})

@@ -22,0 +23,0 @@ /**

@@ -38,5 +38,5 @@ import type { EventEmitter } from '../utils/EventEmitter'

/** The id of the video device, or null if not available */
get cameraId(): string | null
readonly cameraId: string | null
/** The label of the video device, or null if not available */
get cameraLabel(): string | null
readonly cameraLabel: string | null
/**

@@ -46,5 +46,5 @@ * Provides access to the local audio

*/
get localAudioTrack(): MediaStreamTrack | null
readonly localAudioTrack: MediaStreamTrack | null
/** Provides access to the local [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream) */
get localStream(): MediaStream | undefined
readonly localStream: MediaStream | undefined
/**

@@ -54,19 +54,19 @@ * Provides access to the local video

*/
get localVideoTrack(): MediaStreamTrack | null
readonly localVideoTrack: MediaStreamTrack | null
/** The id of the audio input device, or null if not available */
get microphoneId(): string | null
readonly microphoneId: string | null
/** The label of the audio input device, or null if not available */
get microphoneLabel(): string | null
readonly microphoneLabel: string | null
/**
* Provides access to the remote [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream)
*/
get remoteStream(): MediaStream | undefined
readonly remoteStream: MediaStream | undefined
/** The unique identifier for the room */
get roomId(): string
readonly roomId: string
/** The unique identifier for the room session */
get roomSessionId(): string
readonly roomSessionId: string
/** Whether the connection is currently active */
get active(): boolean
readonly active: boolean
/** The id of the current member within the room */
get memberId(): string
readonly memberId: string

@@ -73,0 +73,0 @@ updateCamera(constraints: MediaTrackConstraints): Promise<void>

@@ -8,3 +8,3 @@ import {

} from './constants'
export { setLogger, getLogger } from './logger'
export { setLogger, getLogger, setDebugOptions } from './logger'

@@ -11,0 +11,0 @@ export { v4 as uuid } from 'uuid'

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

import type { URL as NodeURL } from 'node:url'
import { InternalRPCMethods } from '../internal'

@@ -51,3 +50,2 @@ type JSONRPCParams = Record<string, any>

| VertoMethod
| InternalRPCMethods

@@ -86,6 +84,11 @@ export interface JSONRPCRequest {

}
export interface UserOptions extends SessionOptions {
/** @internal */
devTools?: boolean
/** @internal */
debug?: {
logWsTraffic?: boolean
}
/** @internal */
logger?: SDKLogger
}

@@ -390,1 +393,10 @@

}
export interface WsTrafficOptions {
type: 'send' | 'recv'
payload: JSONRPCResponse | JSONRPCRequest
}
export interface InternalSDKLogger extends SDKLogger {
wsTraffic: (options: WsTrafficOptions) => void
}

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

import { getLogger, setLogger } from './logger'
import { mockLogger } from '../testUtils'
import { getLogger, setLogger, setDebugOptions } from './logger'
import { createMockedLogger } from '../testUtils'
import { InternalSDKLogger } from '..'

@@ -19,3 +20,4 @@ describe('logger', () => {

it('should allow us to pass a customer logger', () => {
setLogger(mockLogger)
const mockedLogger = createMockedLogger()
setLogger(mockedLogger)
const logger = getLogger()

@@ -29,9 +31,82 @@

expect(mockLogger.info).toHaveBeenCalledWith('info')
expect(mockLogger.debug).toHaveBeenCalledWith('debug')
expect(mockLogger.error).toHaveBeenCalledWith('error')
expect(mockLogger.trace).toHaveBeenCalledWith('trace')
expect(mockLogger.warn).toHaveBeenCalledWith('warn')
expect(mockedLogger.info).toHaveBeenCalledWith('info')
expect(mockedLogger.debug).toHaveBeenCalledWith('debug')
expect(mockedLogger.error).toHaveBeenCalledWith('error')
expect(mockedLogger.trace).toHaveBeenCalledWith('trace')
expect(mockedLogger.warn).toHaveBeenCalledWith('warn')
})
})
describe('WS Traffic', () => {
let mockedLogger: InternalSDKLogger
beforeEach(() => {
mockedLogger = createMockedLogger()
setLogger(mockedLogger)
})
afterEach(() => {
setLogger(null)
setDebugOptions(null)
})
it('should be a noop unless `debug.logWsTraffic: true`', () => {
const logger = getLogger()
logger.wsTraffic({ type: 'send', payload: {} as any })
expect(mockedLogger.info).not.toHaveBeenCalled()
})
it('should expose a `wsTraffic` method', () => {
setDebugOptions({
logWsTraffic: true,
})
const logger = getLogger()
const payload = {
jsonrpc: '2.0' as const,
id: 'uuid',
method: 'signalwire.event' as const,
params: {
key: 'value',
},
}
logger.wsTraffic({ type: 'send', payload })
logger.wsTraffic({ type: 'recv', payload })
expect(mockedLogger.info).toHaveBeenNthCalledWith(
1,
`SEND: \n`,
JSON.stringify(payload, null, 2),
'\n'
)
expect(mockedLogger.info).toHaveBeenNthCalledWith(
2,
`RECV: \n`,
JSON.stringify(payload, null, 2),
'\n'
)
})
it('should not stringify ping events', () => {
setDebugOptions({
logWsTraffic: true,
})
const logger = getLogger()
const payload = {
jsonrpc: '2.0' as const,
id: 'uuid',
method: 'signalwire.ping' as const,
params: {
key: 'value',
},
}
logger.wsTraffic({ type: 'send', payload })
expect(mockedLogger.info).toHaveBeenCalledWith(`SEND: \n`, payload, '\n')
})
})
})
import log from 'loglevel'
import { SDKLogger } from '..'
import type {
SDKLogger,
InternalSDKLogger,
WsTrafficOptions,
UserOptions,
} from '..'

@@ -21,3 +26,3 @@ const datetime = () =>

const level =
const defaultLoggerLevel =
// @ts-ignore

@@ -27,3 +32,3 @@ 'development' === process.env.NODE_ENV

: defaultLogger.getLevel()
defaultLogger.setLevel(level)
defaultLogger.setLevel(defaultLoggerLevel)

@@ -35,6 +40,52 @@ let userLogger: SDKLogger | null

const getLogger = (): SDKLogger => {
let debugOptions: UserOptions['debug'] = {}
const setDebugOptions = (options: any) => {
if (options == null) {
debugOptions = {}
return
}
Object.assign(debugOptions, options)
}
const getLoggerInstance = (): SDKLogger => {
return userLogger ?? (defaultLogger as any as SDKLogger)
}
export { setLogger, getLogger }
const shouldStringify = (payload: WsTrafficOptions['payload']) => {
if ('method' in payload && payload.method === 'signalwire.ping') {
return false
}
return true
}
const wsTraffic: InternalSDKLogger['wsTraffic'] = ({ type, payload }) => {
const logger = getLoggerInstance()
const { logWsTraffic } = debugOptions || {}
if (!logWsTraffic) {
return undefined
}
const msg = shouldStringify(payload)
? JSON.stringify(payload, null, 2)
: payload
return logger.info(`${type.toUpperCase()}: \n`, msg, '\n')
}
const getLogger = (): InternalSDKLogger => {
const logger = getLoggerInstance()
return new Proxy(logger, {
get(target, prop: keyof InternalSDKLogger, receiver) {
if (prop === 'wsTraffic') {
return wsTraffic
}
return Reflect.get(target, prop, receiver)
},
}) as InternalSDKLogger
}
export { setLogger, getLogger, setDebugOptions }

@@ -95,3 +95,12 @@ import { RPCConnect, RPCExecute } from '../RPCMessages'

})
it('should handle nested "result" fields with error', () => {
const response = JSON.parse(
'{"jsonrpc":"2.0","id":"uuid","result":{"requester_nodeid":"node1","requester_identity":"node1","responder_nodeid":"node2","responder_identity":"node2","result":{"code":"500","message":"Server error"}}}'
)
expect(parseRPCResponse({ request, response })).toEqual({
error: { code: '500', message: 'Server error' },
})
})
})
})

@@ -54,6 +54,10 @@ import { JSONRPCRequest, JSONRPCResponse } from './interfaces'

if (nestedResult) {
if (nestedResult.jsonrpc) {
const { jsonrpc, code } = nestedResult
if (jsonrpc) {
// This is a verto message
return parseResponse(nestedResult, node_id)
}
if (code && code !== '200') {
return { error: nestedResult }
}
return { result: nestedResult }

@@ -60,0 +64,0 @@ }

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