Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [Unreleased](https://github.com/purecloudlabs/genesys-cloud-streaming-client/compare/v19.7.1...HEAD)
### Breaking Changes
* [STREAM-1604](https://inindca.atlassian.net/browse/STREAM-1604) - Replace `uuid` with native `globalThis.crypto.randomUUID()`. `randomUUID()` has been widely available in browsers since 2022, so this should only affect you if you use streaming-client in an older browser. Also update `genesys-cloud-client-logger` from v4.2.18 to v5.

### Added
* [STREAM-1661](https://inindca.atlassian.net/browse/STREAM-1661) - Expose current alerting leader status rather than exposing a snapshot of the value. The previous property is now deprecated.

Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
'<rootDir>/test/unit/**/*.(ts|js)'
],
setupFiles: [
'<rootDir>/test/helpers/setup-browser-env.js'
],
transform: {
'^.+\\.jsx?$': 'babel-jest',
Expand Down
12,072 changes: 7,238 additions & 4,834 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@
"core-js": "^3.6.5",
"debounce-promise": "^3.1.2",
"exponential-backoff": "^3.1.1",
"genesys-cloud-client-logger": "^4.2.18",
"genesys-cloud-client-logger": "^5.0.0",
"limiter": "^1.1.0",
"lodash.throttle": "^4.1.1",
"lru-cache": "^11.0.1",
"stanza": "^12.20.0",
"strict-event-emitter": "^0.5.0",
"strict-event-emitter-types": "^2.0.0",
"unorm": "^1.6.0",
"uuid": "^9.0.1",
"webrtc-stats-gatherer": "^9.0.10",
"whatwg-fetch": "^3.0.0",
"wildemitter": "^1.2.1",
Expand All @@ -89,7 +88,6 @@
"@types/lodash.throttle": "^4.1.6",
"@types/nock": "^11.1.0",
"@types/node": "^14.6.2",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"atob": "^2.1.2",
Expand Down
3 changes: 1 addition & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import SaslError from './types/sasl-error';
import { TimeoutError } from './types/timeout-error';
import { MessengerExtensionApi, MessengerExtension } from './messenger';
import { SASLFailureCondition } from 'stanza/Constants';
import { v4 } from 'uuid';
import { ConnectionTransfer } from './connection-transfer';
import UserCancelledError from './types/user-cancelled-error';

Expand Down Expand Up @@ -756,7 +755,7 @@ export class Client extends EventEmitter {
}

// If no jidResource is provided, generate a random one to maintain ourselves.
this.jidResource = this.config.jidResource || v4();
this.jidResource = this.config.jidResource || globalThis.crypto.randomUUID();

const channelRequestOpts: RequestApiOptions = {
method: 'post',
Expand Down
3 changes: 1 addition & 2 deletions src/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import Logger from 'genesys-cloud-client-logger';
import { AgentConfig, createClient } from 'stanza';
import { SASL } from 'stanza/protocol';
import { v4 } from 'uuid';
import { IClientConfig } from './types/interfaces';
import { NamedAgent } from './types/named-agent';
import SaslError from './types/sasl-error';
Expand All @@ -35,7 +34,7 @@ export class ConnectionManager {
(stanza.sasl as any).mechanisms = (stanza.sasl as any).mechanisms.sort((a, b) => b.priority - a.priority);

// we are going to give the stanza instance an id for tracking and logging purposes
stanza.id = v4();
stanza.id = globalThis.crypto.randomUUID();
const channelId = stanza.channelId = this.config.channelId;

let boundCheckForErrorStanza: (rawString: string) => void;
Expand Down
3 changes: 1 addition & 2 deletions src/messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { GenesysMediaMessage, StreamingClientExtension } from './types/interface

import { Emitter } from 'strict-event-emitter';
import { toBare } from 'stanza/JID';
import { v4 } from 'uuid';

type MessageWithMediaMessage = {
from?: string;
Expand Down Expand Up @@ -58,7 +57,7 @@ export class MessengerExtension extends Emitter<MessengerEvents> implements Stre
* @returns Promise<messageId>
*/
async broadcastMessage (msg: MessageWithMediaMessage): Promise<string> {
const id = v4();
const id = globalThis.crypto.randomUUID();
msg.id = id;
msg.from = this.stanzaInstance.jid;

Expand Down
3 changes: 1 addition & 2 deletions src/types/genesys-cloud-media-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { JingleReason, IQ } from 'stanza/protocol';
import { ConnectionState, IGenesysCloudMediaSessionParams, IMediaSession, IMediaSessionParams, SessionState } from './media-session';
import Logger, { ILogMessageOptions } from 'genesys-cloud-client-logger';
import { WebrtcExtension } from '../webrtc';
import { v4 } from 'uuid';
import { timeoutPromise } from '../utils';
import { SessionTypes, GenesysSessionTerminateParams, GenesysInfoActiveParams, GenesysWebrtcSdpParams, GenesysWebrtcMuteParams, GenesysWebrtcJsonRpcMessage } from './interfaces';

Expand Down Expand Up @@ -129,7 +128,7 @@ export class GenesysCloudMediaSession {
}

private async sendGenesysWebrtc (info: GenesysWebrtcJsonRpcMessage): Promise<any> {
info.id = info.id || v4();
info.id = info.id || globalThis.crypto.randomUUID();
info.jsonrpc = info.jsonrpc || '2.0';

const iq: IQ = {
Expand Down
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 } from 'uuid';
import { TimeoutError } from './types/timeout-error';
import { StreamingClientErrorTypes, StreamingSubscriptionErrorDetails } from './types/interfaces';

Expand Down Expand Up @@ -160,7 +159,7 @@ export function retryPromise<T = any> (
promise,
cancel,
complete,
_id: v4(),
_id: globalThis.crypto.randomUUID(),
hasCompleted: () => _hasCompleted
};
}
Expand Down
5 changes: 2 additions & 3 deletions src/webrtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { toBare } from 'stanza/JID';
import { LRUCache } from 'lru-cache';
import { JingleAction } from 'stanza/Constants';
import { SessionManager } from 'stanza/jingle';
import { v4 } from 'uuid';
import { StatsEvent } from 'webrtc-stats-gatherer';
import throttle from 'lodash.throttle';
import JingleSession, { SessionOpts } from 'stanza/jingle/Session';
Expand Down Expand Up @@ -724,7 +723,7 @@ export class WebrtcExtension extends EventEmitter implements StreamingClientExte
const session: any = {
to: opts.jid,
propose: {
id: v4(),
id: globalThis.crypto.randomUUID(),
descriptions: []
}
};
Expand Down Expand Up @@ -767,7 +766,7 @@ export class WebrtcExtension extends EventEmitter implements StreamingClientExte
const mediaPresence = {
type: 'upgradeMedia' as any,
to: opts.jid,
id: v4(),
id: globalThis.crypto.randomUUID(),
from: this.jid,
media: {
conversationId: opts.conversationId,
Expand Down
4 changes: 4 additions & 0 deletions test/helpers/setup-browser-env.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
import { randomUUID } from 'crypto';

global.window = global;
global.self = global;
globalThis.crypto = { randomUUID: jest.fn(() => randomUUID())}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node doesn't have globalThis.crypto... by default so just mock it.


4 changes: 1 addition & 3 deletions test/unit/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import UserCancelledError from '../../src/types/user-cancelled-error';
jest.mock('genesys-cloud-client-logger');
jest.mock('../../src/ping');
jest.mock('../../src/server-monitor');
jest.mock('uuid', () => ({
v4: jest.fn(() => 'mocked-uuid'),
}));
jest.spyOn(globalThis.crypto, 'randomUUID').mockReturnValue('mocked-uuid' as any);

const defaultOptions = {
jid: 'anon@example.mypurecloud.com',
Expand Down
5 changes: 2 additions & 3 deletions test/unit/messenger.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import EventEmitter from "events";
import { Agent, createClient } from "stanza";
import { v4 } from "uuid";
import { HttpClient } from "../../src/http-client";
import { MediaMessageEvent, MessengerExtension } from "../../src/messenger";
import { NamedAgent } from "../../src/types/named-agent";
Expand All @@ -11,7 +10,7 @@ function getFakeStanzaClient (): NamedAgent {
instance,
{
config: {},
id: v4(),
id: globalThis.crypto.randomUUID(),
jid: 'myuser@asdf.com/client1',
send: jest.fn().mockResolvedValue(null),
}
Expand Down Expand Up @@ -125,4 +124,4 @@ describe('broadcastMessage', () => {
expect(id).toEqual(msgCall.id);
expect(msgCall.to).toEqual('123myjid@orgspan.com');
});
});
});
3 changes: 1 addition & 2 deletions test/unit/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Agent } from 'stanza';
import { HttpClient } from '../../src/http-client';
import { EventEmitter } from 'stream';
import { NamedAgent } from '../../src/types/named-agent';
import { v4 } from 'uuid';
import axios, { AxiosResponse } from 'axios';
import AxiosMockAdapter from 'axios-mock-adapter';
import { splitIntoIndividualTopics } from '../../src/utils';
Expand All @@ -22,7 +21,7 @@ function getFakeStanzaClient (): NamedAgent {
return Object.assign(
instance,
{
id: v4(),
id: globalThis.crypto.randomUUID(),
subscribeToNode: jest.fn(),
unsubscribeFromNode: jest.fn(),
channelId
Expand Down
3 changes: 1 addition & 2 deletions test/unit/session-initiation-timing.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { EventEmitter } from "events";
import { Agent, createClient } from "stanza";
import { IQ } from 'stanza/protocol';
import { v4 as uuidv4 } from 'uuid';

import { HttpClient } from "../../src/http-client";
import { GenesysCloudMediaSession } from '../../src/types/genesys-cloud-media-session';
Expand Down Expand Up @@ -50,7 +49,7 @@ function getFakeStanzaClient (): NamedAgent {
instance,
{
config: {},
id: uuidv4(),
id: globalThis.crypto.randomUUID(),
getServices: jest.fn(),
stanzas: {
define: jest.fn()
Expand Down
3 changes: 1 addition & 2 deletions test/unit/stanza-definitions/webrtc-signaling.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { definitions } from '../../../src/stanza-definitions/webrtc-signaling';
import { v4 } from 'uuid';
import { createClient } from 'stanza';

const stanza = createClient({});
Expand All @@ -10,7 +9,7 @@ describe('upgradeMediaPresenceDefinition', () => {
const mediaPresence = {
type: 'upgradeMedia' as any,
to: 'tojid@conference.com',
id: v4(),
id: globalThis.crypto.randomUUID(),
from: 'fromjid@conference.com',
media: {
conversationId: 'myconversationid',
Expand Down
19 changes: 9 additions & 10 deletions test/unit/webrtc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import WildEmitter from 'wildemitter';
import { Agent, createClient } from 'stanza';
import { JingleAction } from 'stanza/Constants';
import { SessionOpts } from 'stanza/jingle/Session';
import { v4 } from 'uuid';
import { EventEmitter } from 'events';
import browserama from 'browserama';

Expand All @@ -29,7 +28,7 @@ function getFakeStanzaClient (): NamedAgent {
instance,
{
config: {},
id: v4(),
id: globalThis.crypto.randomUUID(),
getServices: jest.fn(),
stanzas: {
define: jest.fn()
Expand Down Expand Up @@ -538,7 +537,7 @@ describe('configureNewStanzaInstance', () => {
];

for (const e of events) {
const fakeData = { str: v4() };
const fakeData = { str: globalThis.crypto.randomUUID() };
fakeStanza.jingle.emit(e, fakeSession, fakeData);
expect(fakeSession.emit).toHaveBeenCalledWith(e, fakeData);
fakeSession.emit.mockReset();
Expand Down Expand Up @@ -578,7 +577,7 @@ describe('configureNewStanzaInstance', () => {
];

for (const e of events) {
const fakeData = { str: v4() };
const fakeData = { str: globalThis.crypto.randomUUID() };
fakeStanza.jingle.emit(e, fakeSession, fakeData);
expect(fakeSession.emit).not.toHaveBeenCalled();
}
Expand Down Expand Up @@ -617,8 +616,8 @@ describe('handlePropose', () => {
from: 'myJid',
propose: {
autoAnswer: false,
conversationId: v4(),
sessionId: v4()
conversationId: globalThis.crypto.randomUUID(),
sessionId: globalThis.crypto.randomUUID()
},
to: 'myJid'
});
Expand All @@ -637,8 +636,8 @@ describe('handlePropose', () => {

const propose = {
autoAnswer: false,
conversationId: v4(),
sessionId: v4()
conversationId: globalThis.crypto.randomUUID(),
sessionId: globalThis.crypto.randomUUID()
};

webrtc['handlePropose']({
Expand Down Expand Up @@ -666,13 +665,13 @@ describe('handlePropose', () => {
const fakeStanza = webrtc['stanzaInstance'] = getFakeStanzaClient();

const spy = jest.spyOn(webrtc, 'acceptRtcSession');
const sessionId = v4();
const sessionId = globalThis.crypto.randomUUID();

webrtc.pendingSessions[sessionId] = { accepted: true } as any;

const propose = {
autoAnswer: false,
conversationId: v4(),
conversationId: globalThis.crypto.randomUUID(),
sessionId
};

Expand Down
Loading