@ohos-ports/genesys-cloud-streaming-client 20.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +47 -0
  2. package/dist/cjs/alerting-leader.d.ts +29 -0
  3. package/dist/cjs/alerting-leader.js +163 -0
  4. package/dist/cjs/client.d.ts +84 -0
  5. package/dist/cjs/client.js +680 -0
  6. package/dist/cjs/connection-manager.d.ts +18 -0
  7. package/dist/cjs/connection-manager.js +120 -0
  8. package/dist/cjs/connection-transfer.d.ts +7 -0
  9. package/dist/cjs/connection-transfer.js +20 -0
  10. package/dist/cjs/http-client.d.ts +18 -0
  11. package/dist/cjs/http-client.js +230 -0
  12. package/dist/cjs/index.d.ts +10 -0
  13. package/dist/cjs/index.js +31 -0
  14. package/dist/cjs/messenger.d.ts +37 -0
  15. package/dist/cjs/messenger.js +54 -0
  16. package/dist/cjs/notifications.d.ts +94 -0
  17. package/dist/cjs/notifications.js +495 -0
  18. package/dist/cjs/ping.d.ts +21 -0
  19. package/dist/cjs/ping.js +60 -0
  20. package/dist/cjs/polyfills.d.ts +0 -0
  21. package/dist/cjs/polyfills.js +6 -0
  22. package/dist/cjs/server-monitor.d.ts +16 -0
  23. package/dist/cjs/server-monitor.js +44 -0
  24. package/dist/cjs/stanza-definitions/webrtc-signaling.d.ts +29 -0
  25. package/dist/cjs/stanza-definitions/webrtc-signaling.js +113 -0
  26. package/dist/cjs/stanza-definitions/xep0051.d.ts +19 -0
  27. package/dist/cjs/stanza-definitions/xep0051.js +28 -0
  28. package/dist/cjs/stats-formatter.d.ts +6 -0
  29. package/dist/cjs/stats-formatter.js +63 -0
  30. package/dist/cjs/types/genesys-cloud-media-session.d.ts +64 -0
  31. package/dist/cjs/types/genesys-cloud-media-session.js +353 -0
  32. package/dist/cjs/types/interfaces.d.ts +310 -0
  33. package/dist/cjs/types/interfaces.js +22 -0
  34. package/dist/cjs/types/libs.d.ts +32 -0
  35. package/dist/cjs/types/libs.js +1 -0
  36. package/dist/cjs/types/media-session.d.ts +76 -0
  37. package/dist/cjs/types/media-session.js +2 -0
  38. package/dist/cjs/types/named-agent.d.ts +13 -0
  39. package/dist/cjs/types/named-agent.js +2 -0
  40. package/dist/cjs/types/offline-error.d.ts +2 -0
  41. package/dist/cjs/types/offline-error.js +5 -0
  42. package/dist/cjs/types/sasl-error.d.ts +8 -0
  43. package/dist/cjs/types/sasl-error.js +12 -0
  44. package/dist/cjs/types/stanza-media-session.d.ts +56 -0
  45. package/dist/cjs/types/stanza-media-session.js +255 -0
  46. package/dist/cjs/types/streaming-client-extension.d.ts +14 -0
  47. package/dist/cjs/types/streaming-client-extension.js +2 -0
  48. package/dist/cjs/types/timeout-error.d.ts +3 -0
  49. package/dist/cjs/types/timeout-error.js +9 -0
  50. package/dist/cjs/types/user-cancelled-error.d.ts +2 -0
  51. package/dist/cjs/types/user-cancelled-error.js +5 -0
  52. package/dist/cjs/utils.d.ts +34 -0
  53. package/dist/cjs/utils.js +202 -0
  54. package/dist/cjs/webrtc.d.ts +126 -0
  55. package/dist/cjs/webrtc.js +891 -0
  56. package/dist/deploy-info.json +21 -0
  57. package/dist/es/alerting-leader.d.ts +29 -0
  58. package/dist/es/alerting-leader.js +177 -0
  59. package/dist/es/client.d.ts +84 -0
  60. package/dist/es/client.js +699 -0
  61. package/dist/es/connection-manager.d.ts +18 -0
  62. package/dist/es/connection-manager.js +124 -0
  63. package/dist/es/connection-transfer.d.ts +7 -0
  64. package/dist/es/connection-transfer.js +16 -0
  65. package/dist/es/http-client.d.ts +18 -0
  66. package/dist/es/http-client.js +194 -0
  67. package/dist/es/index.bundle.js +39629 -0
  68. package/dist/es/index.d.ts +10 -0
  69. package/dist/es/index.js +10 -0
  70. package/dist/es/messenger.d.ts +37 -0
  71. package/dist/es/messenger.js +62 -0
  72. package/dist/es/notifications.d.ts +94 -0
  73. package/dist/es/notifications.js +507 -0
  74. package/dist/es/ping.d.ts +21 -0
  75. package/dist/es/ping.js +68 -0
  76. package/dist/es/polyfills.d.ts +0 -0
  77. package/dist/es/polyfills.js +6 -0
  78. package/dist/es/server-monitor.d.ts +16 -0
  79. package/dist/es/server-monitor.js +41 -0
  80. package/dist/es/stanza-definitions/webrtc-signaling.d.ts +29 -0
  81. package/dist/es/stanza-definitions/webrtc-signaling.js +110 -0
  82. package/dist/es/stanza-definitions/xep0051.d.ts +19 -0
  83. package/dist/es/stanza-definitions/xep0051.js +25 -0
  84. package/dist/es/stats-formatter.d.ts +6 -0
  85. package/dist/es/stats-formatter.js +54 -0
  86. package/dist/es/types/genesys-cloud-media-session.d.ts +64 -0
  87. package/dist/es/types/genesys-cloud-media-session.js +379 -0
  88. package/dist/es/types/interfaces.d.ts +310 -0
  89. package/dist/es/types/interfaces.js +19 -0
  90. package/dist/es/types/libs.d.ts +32 -0
  91. package/dist/es/types/libs.js +1 -0
  92. package/dist/es/types/media-session.d.ts +76 -0
  93. package/dist/es/types/media-session.js +1 -0
  94. package/dist/es/types/named-agent.d.ts +13 -0
  95. package/dist/es/types/named-agent.js +1 -0
  96. package/dist/es/types/offline-error.d.ts +2 -0
  97. package/dist/es/types/offline-error.js +2 -0
  98. package/dist/es/types/sasl-error.d.ts +8 -0
  99. package/dist/es/types/sasl-error.js +9 -0
  100. package/dist/es/types/stanza-media-session.d.ts +56 -0
  101. package/dist/es/types/stanza-media-session.js +264 -0
  102. package/dist/es/types/streaming-client-extension.d.ts +14 -0
  103. package/dist/es/types/streaming-client-extension.js +1 -0
  104. package/dist/es/types/timeout-error.d.ts +3 -0
  105. package/dist/es/types/timeout-error.js +5 -0
  106. package/dist/es/types/user-cancelled-error.d.ts +2 -0
  107. package/dist/es/types/user-cancelled-error.js +2 -0
  108. package/dist/es/utils.d.ts +34 -0
  109. package/dist/es/utils.js +192 -0
  110. package/dist/es/webrtc.d.ts +126 -0
  111. package/dist/es/webrtc.js +917 -0
  112. package/dist/manifest.json +19 -0
  113. package/dist/npm/CHANGELOG.md +637 -0
  114. package/dist/npm/README.md +47 -0
  115. package/dist/npm/alerting-leader.d.ts +29 -0
  116. package/dist/npm/alerting-leader.js +163 -0
  117. package/dist/npm/client.d.ts +84 -0
  118. package/dist/npm/client.js +680 -0
  119. package/dist/npm/connection-manager.d.ts +18 -0
  120. package/dist/npm/connection-manager.js +120 -0
  121. package/dist/npm/connection-transfer.d.ts +7 -0
  122. package/dist/npm/connection-transfer.js +20 -0
  123. package/dist/npm/http-client.d.ts +18 -0
  124. package/dist/npm/http-client.js +230 -0
  125. package/dist/npm/index.d.ts +10 -0
  126. package/dist/npm/index.js +31 -0
  127. package/dist/npm/messenger.d.ts +37 -0
  128. package/dist/npm/messenger.js +54 -0
  129. package/dist/npm/module.js +10 -0
  130. package/dist/npm/notifications.d.ts +94 -0
  131. package/dist/npm/notifications.js +495 -0
  132. package/dist/npm/ping.d.ts +21 -0
  133. package/dist/npm/ping.js +60 -0
  134. package/dist/npm/polyfills.d.ts +0 -0
  135. package/dist/npm/polyfills.js +6 -0
  136. package/dist/npm/server-monitor.d.ts +16 -0
  137. package/dist/npm/server-monitor.js +44 -0
  138. package/dist/npm/stanza-definitions/webrtc-signaling.d.ts +29 -0
  139. package/dist/npm/stanza-definitions/webrtc-signaling.js +113 -0
  140. package/dist/npm/stanza-definitions/xep0051.d.ts +19 -0
  141. package/dist/npm/stanza-definitions/xep0051.js +28 -0
  142. package/dist/npm/stats-formatter.d.ts +6 -0
  143. package/dist/npm/stats-formatter.js +63 -0
  144. package/dist/npm/types/genesys-cloud-media-session.d.ts +64 -0
  145. package/dist/npm/types/genesys-cloud-media-session.js +353 -0
  146. package/dist/npm/types/interfaces.d.ts +310 -0
  147. package/dist/npm/types/interfaces.js +22 -0
  148. package/dist/npm/types/libs.d.ts +32 -0
  149. package/dist/npm/types/libs.js +1 -0
  150. package/dist/npm/types/media-session.d.ts +76 -0
  151. package/dist/npm/types/media-session.js +2 -0
  152. package/dist/npm/types/named-agent.d.ts +13 -0
  153. package/dist/npm/types/named-agent.js +2 -0
  154. package/dist/npm/types/offline-error.d.ts +2 -0
  155. package/dist/npm/types/offline-error.js +5 -0
  156. package/dist/npm/types/sasl-error.d.ts +8 -0
  157. package/dist/npm/types/sasl-error.js +12 -0
  158. package/dist/npm/types/stanza-media-session.d.ts +56 -0
  159. package/dist/npm/types/stanza-media-session.js +255 -0
  160. package/dist/npm/types/streaming-client-extension.d.ts +14 -0
  161. package/dist/npm/types/streaming-client-extension.js +2 -0
  162. package/dist/npm/types/timeout-error.d.ts +3 -0
  163. package/dist/npm/types/timeout-error.js +9 -0
  164. package/dist/npm/types/user-cancelled-error.d.ts +2 -0
  165. package/dist/npm/types/user-cancelled-error.js +5 -0
  166. package/dist/npm/utils.d.ts +34 -0
  167. package/dist/npm/utils.js +207 -0
  168. package/dist/npm/webrtc.d.ts +126 -0
  169. package/dist/npm/webrtc.js +893 -0
  170. package/dist/streaming-client.browser.js +2 -0
  171. package/dist/streaming-client.browser.js.LICENSE.txt +12 -0
  172. package/dist/v20/streaming-client.browser.js +2 -0
  173. package/dist/v20/streaming-client.browser.js.LICENSE.txt +12 -0
  174. package/dist/v20.1.0/streaming-client.browser.js +2 -0
  175. package/dist/v20.1.0/streaming-client.browser.js.LICENSE.txt +12 -0
  176. package/package.json +132 -0
@@ -0,0 +1,19 @@
1
+ export var AlertableInteractionTypes;
2
+ (function (AlertableInteractionTypes) {
3
+ AlertableInteractionTypes["voice"] = "voice";
4
+ })(AlertableInteractionTypes || (AlertableInteractionTypes = {}));
5
+ export var StreamingClientErrorTypes;
6
+ (function (StreamingClientErrorTypes) {
7
+ StreamingClientErrorTypes["generic"] = "generic";
8
+ StreamingClientErrorTypes["invalid_token"] = "invalid_token";
9
+ StreamingClientErrorTypes["userCancelled"] = "user_cancelled";
10
+ })(StreamingClientErrorTypes || (StreamingClientErrorTypes = {}));
11
+ export var SessionTypes;
12
+ (function (SessionTypes) {
13
+ SessionTypes["softphone"] = "softphone";
14
+ SessionTypes["collaborateVideo"] = "collaborateVideo";
15
+ SessionTypes["acdScreenShare"] = "screenShare";
16
+ SessionTypes["screenRecording"] = "screenRecording";
17
+ SessionTypes["liveScreenMonitoring"] = "liveScreenMonitoring";
18
+ SessionTypes["unknown"] = "unknown";
19
+ })(SessionTypes || (SessionTypes = {}));
@@ -0,0 +1,32 @@
1
+ declare module 'wildemitter' {
2
+ export default class WildEmitter {
3
+ constructor();
4
+ on(event: string, groupNameOrCallback: any, callback?: any): void;
5
+ once(event: string, groupNameOrCallback: any, callback?: any): void;
6
+ off(event: string, groupNameOrCallback?: any, callback?: any): void;
7
+ emit(event: string, ...args: any[]): void;
8
+ emit(event: string, ...args: any[]): void;
9
+ releaseGroup(groupName?: string): void;
10
+ getWildcardCallbacks(): (...args: any[]) => void;
11
+ static mixin(arg: any): void;
12
+ }
13
+ }
14
+ declare module 'backoff-web' {
15
+ export interface Backoff {
16
+ failAfter(attempts: number): void;
17
+ on(evt: 'backoff' | 'ready', callback: (count: number, delay: number) => void): void;
18
+ on(evt: 'fail', callback: (...args: any[]) => void): void;
19
+ backoff(): void;
20
+ reset(): void;
21
+ backoffNumber_: number;
22
+ }
23
+ const backoffInitializer: {
24
+ exponential(options: {
25
+ randomisationFactor: number;
26
+ initialDelay: number;
27
+ maxDelay: number;
28
+ factor: number;
29
+ }): Backoff;
30
+ };
31
+ export default backoffInitializer;
32
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,76 @@
1
+ /// <reference types="node" />
2
+ import EventEmitter from 'events';
3
+ import Logger from 'genesys-cloud-client-logger';
4
+ import { JingleReasonCondition } from 'stanza/Constants';
5
+ import { SessionOpts } from 'stanza/jingle/Session';
6
+ import StrictEventEmitter from 'stanza/lib/StrictEventEmitter';
7
+ import { JingleInfo, JingleReason } from 'stanza/protocol';
8
+ import { StatsEvent } from 'webrtc-stats-gatherer';
9
+ import { JsonRpcMessage, SessionTypes, SessionTypesAsStrings } from './interfaces';
10
+ export declare type SessionState = 'pending' | 'active' | 'ended';
11
+ export declare type ConnectionState = 'starting' | 'new' | 'connecting' | 'connected' | 'interrupted' | 'disconnected' | 'failed' | 'closed';
12
+ export interface SessionEvents {
13
+ iceConnectionType: ({
14
+ localCandidateType: string;
15
+ relayed: boolean;
16
+ remoteCandidateType: string;
17
+ });
18
+ peerTrackAdded: (track: MediaStreamTrack, stream?: MediaStream) => void;
19
+ peerTrackRemoved: (track: MediaStreamTrack, stream?: MediaStream) => void;
20
+ mute: JingleInfo;
21
+ unmute: JingleInfo;
22
+ sessionState: SessionState;
23
+ connectionState: ConnectionState;
24
+ terminated: JingleReason;
25
+ stats: StatsEvent;
26
+ endOfCandidates: void;
27
+ dataChannelMessage: JsonRpcMessage;
28
+ }
29
+ export interface IMediaSessionParams {
30
+ logger: Logger;
31
+ id: string;
32
+ fromJid: string;
33
+ peerID: string;
34
+ sessionType: SessionTypes | SessionTypesAsStrings;
35
+ allowIPv6?: boolean;
36
+ allowTCP?: boolean;
37
+ ignoreHostCandidatesFromRemote?: boolean;
38
+ optOutOfWebrtcStatsTelemetry?: boolean;
39
+ conversationId?: string;
40
+ fromUserId?: string;
41
+ originalRoomJid?: string;
42
+ meetingId?: string;
43
+ privAnswerMode?: 'Auto';
44
+ }
45
+ export interface IStanzaMediaSessionParams extends IMediaSessionParams {
46
+ options: SessionOpts;
47
+ }
48
+ export interface IGenesysCloudMediaSessionParams extends IMediaSessionParams {
49
+ iceServers: RTCIceServer[];
50
+ iceTransportPolicy: RTCIceTransportPolicy;
51
+ reinvite: boolean;
52
+ }
53
+ export interface IMediaSession extends StrictEventEmitter<EventEmitter, SessionEvents> {
54
+ conversationId: string;
55
+ id: string;
56
+ sessionType: SessionTypes;
57
+ fromUserId?: string;
58
+ peerID: string;
59
+ peerConnection: RTCPeerConnection;
60
+ pc: RTCPeerConnection;
61
+ dataChannel?: RTCDataChannel;
62
+ connectionState: ConnectionState | string;
63
+ state: SessionState | string;
64
+ reinvite: boolean;
65
+ meetingId?: string;
66
+ privAnswerMode?: 'Auto';
67
+ setupStatsGatherer(): void;
68
+ accept(opts?: RTCAnswerOptions): Promise<void>;
69
+ end(reason: JingleReasonCondition, silent?: boolean): Promise<void>;
70
+ addTrack(track: MediaStreamTrack, stream?: MediaStream): Promise<void>;
71
+ removeTrack(sender: RTCRtpSender): Promise<void>;
72
+ mute(userId: string, name?: string): Promise<void>;
73
+ unmute(userId: string, name?: string): Promise<void>;
74
+ hold(): Promise<void>;
75
+ resume(): Promise<void>;
76
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { Agent } from 'stanza';
2
+ import { Ping } from '../ping';
3
+ import { ServerMonitor } from '../server-monitor';
4
+ import { ConnectionTransfer } from '../connection-transfer';
5
+ export interface NamedAgent extends Omit<Agent, 'disconnect'> {
6
+ id: string;
7
+ channelId?: string;
8
+ originalEmitter?: Function;
9
+ pinger?: Ping;
10
+ serverMonitor?: ServerMonitor;
11
+ connectionTransfer?: ConnectionTransfer;
12
+ disconnect: () => Promise<void>;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export default class OfflineError extends Error {
2
+ }
@@ -0,0 +1,2 @@
1
+ export default class OfflineError extends Error {
2
+ }
@@ -0,0 +1,8 @@
1
+ import { SASLFailureCondition } from 'stanza/Constants';
2
+ export default class SaslError extends Error {
3
+ condition: SASLFailureCondition;
4
+ channelId: string;
5
+ stanzaInstanceId: string;
6
+ name: string;
7
+ constructor(condition: SASLFailureCondition, channelId: string, stanzaInstanceId: string);
8
+ }
@@ -0,0 +1,9 @@
1
+ export default class SaslError extends Error {
2
+ constructor(condition, channelId, stanzaInstanceId) {
3
+ super();
4
+ this.condition = condition;
5
+ this.channelId = channelId;
6
+ this.stanzaInstanceId = stanzaInstanceId;
7
+ this.name = 'SaslError';
8
+ }
9
+ }
@@ -0,0 +1,56 @@
1
+ import { MediaSession } from 'stanza/jingle';
2
+ import { JingleReasonCondition } from 'stanza/Constants';
3
+ import { ActionCallback } from 'stanza/jingle/Session';
4
+ import { JingleReason } from 'stanza/protocol';
5
+ import { IMediaSession, IStanzaMediaSessionParams } from './media-session';
6
+ import { SessionTypes } from './interfaces';
7
+ import { Jingle } from 'stanza/protocol/xep0166';
8
+ export declare class StanzaMediaSession extends MediaSession implements IMediaSession {
9
+ private statsGatherer?;
10
+ private iceCandidatesDiscovered;
11
+ private iceCandidatesReceivedFromPeer;
12
+ private interruptionStart?;
13
+ private logger;
14
+ off: any;
15
+ removeAllListeners: any;
16
+ on: any;
17
+ once: any;
18
+ setMaxListeners: any;
19
+ getMaxListeners: any;
20
+ listeners: any;
21
+ rawListeners: any;
22
+ listenerCount: any;
23
+ prependListener: any;
24
+ prependOnceListener: any;
25
+ eventNames: any;
26
+ addListener: any;
27
+ removeListener: any;
28
+ emit: any;
29
+ conversationId: string;
30
+ peerConnection: RTCPeerConnection;
31
+ id: string;
32
+ fromUserId: string;
33
+ meetingId?: string;
34
+ originalRoomJid?: string;
35
+ sessionType: SessionTypes;
36
+ ignoreHostCandidatesFromRemote: boolean;
37
+ allowIPv6: boolean;
38
+ allowTCP: boolean;
39
+ dataChannel?: RTCDataChannel;
40
+ reinvite: boolean;
41
+ privAnswerMode?: 'Auto';
42
+ constructor(params: IStanzaMediaSessionParams);
43
+ private getLogDetails;
44
+ onTransportInfo(changes: Jingle, cb: ActionCallback): Promise<void>;
45
+ protected _log(level: string, message: string, ...data: any[]): void;
46
+ end(reason?: JingleReasonCondition | JingleReason, silent?: boolean): Promise<void>;
47
+ setupStatsGatherer(): void;
48
+ onIceStateChange(): void;
49
+ onConnectionStateChange(): void;
50
+ onIceCandidateError(ev: Event): void;
51
+ onIceCandidate(e: RTCPeerConnectionIceEvent): void;
52
+ onIceEndOfCandidates(): void;
53
+ addTrack(track: MediaStreamTrack, stream?: MediaStream): Promise<void>;
54
+ _setupDataChannel(): void;
55
+ _handleDataChannelMessage(event: MessageEvent): void;
56
+ }
@@ -0,0 +1,264 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /* istanbul ignore file */
11
+ import EventEmitter from 'events';
12
+ import { MediaSession } from 'stanza/jingle';
13
+ import { JingleAction, JINGLE_INFO_ACTIVE } from 'stanza/Constants';
14
+ import StatsGatherer from 'webrtc-stats-gatherer';
15
+ import { SessionTypes } from './interfaces';
16
+ const loggingOverrides = {
17
+ 'Discovered new ICE candidate': { skipMessage: true }
18
+ };
19
+ // because we are trying to unify the interfaces between stanza and genesys media session
20
+ // we kind of have to hack the stanza one so it works with typescript
21
+ export class StanzaMediaSession extends MediaSession {
22
+ constructor(params) {
23
+ super(params.options);
24
+ this.iceCandidatesDiscovered = 0;
25
+ this.iceCandidatesReceivedFromPeer = 0;
26
+ this.reinvite = false;
27
+ this.logger = params.logger;
28
+ this.conversationId = params.conversationId;
29
+ this.peerConnection = this.pc;
30
+ this.fromUserId = params.fromUserId;
31
+ this.meetingId = params.meetingId;
32
+ this.id = this.sid;
33
+ this.originalRoomJid = params.originalRoomJid;
34
+ this.sessionType = SessionTypes[params.sessionType];
35
+ this.ignoreHostCandidatesFromRemote = !!params.ignoreHostCandidatesFromRemote;
36
+ this.allowIPv6 = !!params.allowIPv6;
37
+ this.allowTCP = !!params.allowTCP;
38
+ this.privAnswerMode = params.privAnswerMode;
39
+ // babel does not like the typescript recipe for multiple extends so we are hacking this one
40
+ // referencing https://github.com/babel/babel/issues/798
41
+ const eventEmitter = new EventEmitter();
42
+ Object.keys(eventEmitter.__proto__).forEach((name) => {
43
+ this[name] = eventEmitter[name];
44
+ });
45
+ if (!params.optOutOfWebrtcStatsTelemetry) {
46
+ this.setupStatsGatherer();
47
+ }
48
+ this.pc.addEventListener('connectionstatechange', this.onConnectionStateChange.bind(this));
49
+ this.pc.addEventListener('icecandidateerror', this.onIceCandidateError.bind(this));
50
+ }
51
+ getLogDetails() {
52
+ return {
53
+ conversationId: this.conversationId,
54
+ sessionId: this.id,
55
+ sessionType: this.sessionType
56
+ };
57
+ }
58
+ onTransportInfo(changes, cb) {
59
+ const _super = Object.create(null, {
60
+ onTransportInfo: { get: () => super.onTransportInfo }
61
+ });
62
+ var _a, _b;
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ const transport = (_a = changes.contents) === null || _a === void 0 ? void 0 : _a[0].transport;
65
+ const candidates = transport === null || transport === void 0 ? void 0 : transport.candidates;
66
+ if (this.ignoreHostCandidatesFromRemote) {
67
+ const nonHostCandidates = candidates === null || candidates === void 0 ? void 0 : candidates.filter(candidate => candidate.type !== 'host');
68
+ if ((nonHostCandidates === null || nonHostCandidates === void 0 ? void 0 : nonHostCandidates.length) !== ((_b = transport === null || transport === void 0 ? void 0 : transport.candidates) === null || _b === void 0 ? void 0 : _b.length)) {
69
+ this._log('info', 'Ignoring remote host ice candidates');
70
+ transport.candidates = nonHostCandidates;
71
+ }
72
+ }
73
+ if (candidates) {
74
+ for (const candidate of candidates) {
75
+ this._log('info', 'Received candidate from peer', { candidateType: candidate.type });
76
+ this.iceCandidatesReceivedFromPeer++;
77
+ }
78
+ }
79
+ return _super.onTransportInfo.call(this, changes, cb);
80
+ });
81
+ }
82
+ _log(level, message, ...data) {
83
+ const redactionInfo = loggingOverrides[message];
84
+ if (redactionInfo === null || redactionInfo === void 0 ? void 0 : redactionInfo.skipMessage) {
85
+ return;
86
+ }
87
+ let details;
88
+ if (data.length) {
89
+ const firstItem = data[0];
90
+ // if first item is an object, merge the details, else wrap them
91
+ if (typeof firstItem === 'object' &&
92
+ !Array.isArray(firstItem) &&
93
+ firstItem !== null) {
94
+ Object.assign(data[0], this.getLogDetails());
95
+ details = data;
96
+ }
97
+ else {
98
+ details = Object.assign(Object.assign({}, this.getLogDetails()), { data: firstItem });
99
+ }
100
+ }
101
+ else {
102
+ details = [...data, this.getLogDetails()];
103
+ }
104
+ this.logger[level](message, details);
105
+ }
106
+ end(reason = 'success', silent = false) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ this.state = 'ended';
109
+ this.processingQueue.kill();
110
+ if (typeof reason === 'string') {
111
+ reason = { condition: reason };
112
+ }
113
+ if (!silent) {
114
+ this._log('info', 'sending jingle session-terminate');
115
+ this.send('session-terminate', { reason });
116
+ }
117
+ // After sending session-terminate, wait for the peer connection to die -> if it doesn't, we will manually close it.
118
+ setTimeout(() => {
119
+ if (this.pc.connectionState === 'connected' || this.pc.connectionState === 'connecting') {
120
+ this.pc.close();
121
+ }
122
+ }, 2000);
123
+ this.parent.emit('terminated', this, reason);
124
+ this.parent.forgetSession(this);
125
+ });
126
+ }
127
+ setupStatsGatherer() {
128
+ this.statsGatherer = new StatsGatherer(this.pc);
129
+ this.statsGatherer.on('stats', this.emit.bind(this, 'stats'));
130
+ }
131
+ onIceStateChange() {
132
+ const iceState = this.pc.iceConnectionState;
133
+ const sessionId = this.id;
134
+ const conversationId = this.conversationId;
135
+ const sessionType = this.sessionType;
136
+ this._log('info', 'ICE state changed: ', { iceState, sessionId, conversationId });
137
+ if (iceState === 'disconnected') {
138
+ // this means we actually connected at one point
139
+ if (this.pc.signalingState === 'stable') {
140
+ this.interruptionStart = new Date();
141
+ this._log('info', 'Connection state is interrupted', { sessionId, conversationId, sessionType });
142
+ }
143
+ }
144
+ else if (iceState === 'connected') {
145
+ this._log('info', 'sending session-info: active');
146
+ this.send(JingleAction.SessionInfo, {
147
+ info: {
148
+ infoType: JINGLE_INFO_ACTIVE
149
+ }
150
+ });
151
+ this._setupDataChannel();
152
+ }
153
+ else if (iceState === 'failed') {
154
+ this._log('info', 'ICE connection failed', {
155
+ candidatesDiscovered: this.iceCandidatesDiscovered,
156
+ candidatesReceivedFromPeer: this.iceCandidatesReceivedFromPeer
157
+ });
158
+ }
159
+ super.onIceStateChange();
160
+ }
161
+ onConnectionStateChange() {
162
+ const connectionState = this.pc.connectionState;
163
+ const sessionId = this.id;
164
+ const conversationId = this.conversationId;
165
+ const sessionType = this.sessionType;
166
+ this._log('info', 'Connection state changed: ', { connectionState, sessionId, conversationId, sessionType });
167
+ if (this.interruptionStart) {
168
+ if (connectionState === 'connected') {
169
+ const diff = new Date().getTime() - this.interruptionStart.getTime();
170
+ this._log('info', 'Connection was interrupted but was successfully recovered/connected', { sessionId, conversationId, sessionType, timeToRecover: diff });
171
+ this.interruptionStart = undefined;
172
+ }
173
+ else if (connectionState === 'failed') {
174
+ this._log('info', 'Connection was interrupted and failed to recover', { sessionId, conversationId, sessionType });
175
+ }
176
+ }
177
+ }
178
+ onIceCandidateError(ev) {
179
+ const event = ev;
180
+ this._log('error', 'IceCandidateError', {
181
+ errorCode: event.errorCode,
182
+ errorText: event.errorText,
183
+ url: event.url
184
+ });
185
+ console.error('IceCandidateError', event);
186
+ }
187
+ onIceCandidate(e) {
188
+ if (e.candidate) {
189
+ if (!this.allowTCP && e.candidate.protocol === 'tcp') {
190
+ return;
191
+ }
192
+ if (!this.allowIPv6) {
193
+ const addressRegex = /.+udp [^ ]+ ([^ ]+).*typ host/;
194
+ const matches = addressRegex.exec(e.candidate.candidate);
195
+ const ipv4Regex = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/;
196
+ if (matches && !matches[1].match(ipv4Regex)) {
197
+ this._log('debug', 'Filtering out IPv6 candidate', e.candidate.candidate);
198
+ return;
199
+ }
200
+ }
201
+ // this has too much information and can only be logged locally (debug)
202
+ this._log('debug', 'Processing ice candidate', e.candidate.candidate);
203
+ // this one is info level so it can go to the server
204
+ this._log('info', 'Discovered ice candidate to send to peer', { type: e.candidate.type });
205
+ this.iceCandidatesDiscovered++;
206
+ }
207
+ return super.onIceCandidate(e);
208
+ }
209
+ onIceEndOfCandidates() {
210
+ super.onIceEndOfCandidates();
211
+ this.emit('endOfCandidates');
212
+ }
213
+ addTrack(track, stream) {
214
+ if (track.kind === 'audio') {
215
+ this.includesAudio = true;
216
+ }
217
+ if (track.kind === 'video') {
218
+ this.includesVideo = true;
219
+ }
220
+ return this.processLocal('addtrack', () => __awaiter(this, void 0, void 0, function* () {
221
+ // find an available sender with the correct type
222
+ const availableTransceiver = this.pc.getTransceivers().find((transceiver) => {
223
+ var _a;
224
+ return !transceiver.sender.track && ((_a = transceiver.receiver.track) === null || _a === void 0 ? void 0 : _a.kind) === track.kind;
225
+ });
226
+ if (availableTransceiver) {
227
+ return availableTransceiver.sender.replaceTrack(track);
228
+ }
229
+ this.pc.addTrack(track, stream);
230
+ return;
231
+ }));
232
+ }
233
+ _setupDataChannel() {
234
+ var _a;
235
+ // this shouldn't happen, but we shouldn't set the datachannel up more than once
236
+ if (this.dataChannel) {
237
+ return;
238
+ }
239
+ // do nothing if a datachannel wasn't offered
240
+ if ((_a = this.pc.localDescription) === null || _a === void 0 ? void 0 : _a.sdp.includes('webrtc-datachannel')) {
241
+ this._log('info', 'creating data channel');
242
+ this.dataChannel = this.pc.createDataChannel('videoConferenceControl');
243
+ this.dataChannel.addEventListener('open', () => {
244
+ this._log('info', 'data channel opened');
245
+ });
246
+ this.dataChannel.addEventListener('message', this._handleDataChannelMessage.bind(this));
247
+ this.dataChannel.addEventListener('close', () => {
248
+ this._log('info', 'closing data channel');
249
+ });
250
+ this.dataChannel.addEventListener('error', (error) => {
251
+ this._log('error', 'Error occurred with the data channel', error);
252
+ });
253
+ }
254
+ }
255
+ _handleDataChannelMessage(event) {
256
+ try {
257
+ const message = JSON.parse(event.data);
258
+ this.emit('dataChannelMessage', message);
259
+ }
260
+ catch (e) {
261
+ this._log('error', 'Failed to parse data channel message', { error: e });
262
+ }
263
+ }
264
+ }
@@ -0,0 +1,14 @@
1
+ import { TokenBucket } from 'limiter';
2
+ import { IQ, Message } from 'stanza/protocol';
3
+ import { NamedAgent } from './named-agent';
4
+ export interface StreamingClientExtension {
5
+ handleIq?: (iq: IQ) => void;
6
+ handleMessage?: (message: Message) => void;
7
+ tokenBucket?: TokenBucket;
8
+ on?: (eventName: string, ...args: any[]) => void;
9
+ expose?: {
10
+ [fnName: string]: any;
11
+ };
12
+ configureNewStanzaInstance?: (stanzaInstance: NamedAgent) => Promise<any>;
13
+ handleStanzaInstanceChange: (stanzaInstance: NamedAgent) => void;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare class TimeoutError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,5 @@
1
+ export class TimeoutError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ }
5
+ }
@@ -0,0 +1,2 @@
1
+ export default class UserCancelledError extends Error {
2
+ }
@@ -0,0 +1,2 @@
1
+ export default class UserCancelledError extends Error {
2
+ }
@@ -0,0 +1,34 @@
1
+ import { StreamingClientErrorTypes, StreamingSubscriptionErrorDetails } from './types/interfaces';
2
+ export declare class StreamingClientError extends Error {
3
+ type: StreamingClientErrorTypes;
4
+ details?: unknown;
5
+ constructor(type: StreamingClientErrorTypes | null, messageOrError: string | Error, details?: unknown);
6
+ }
7
+ export declare class StreamingSubscriptionError extends Error {
8
+ readonly topic?: string | undefined;
9
+ readonly operation?: "subscribe" | "unsubscribe" | undefined;
10
+ name: string;
11
+ missingPermissions?: string[];
12
+ constructor(message: string, topic?: string | undefined, operation?: "subscribe" | "unsubscribe" | undefined, details?: StreamingSubscriptionErrorDetails);
13
+ }
14
+ export declare function timeoutPromise(fn: Function, timeoutMs: number, msg: string, details?: any): Promise<any>;
15
+ export declare function delay(ms: number): Promise<void>;
16
+ export declare function splitIntoIndividualTopics(topicString: string): string[];
17
+ export declare const isAcdJid: (jid: string) => boolean;
18
+ export declare const isScreenRecordingJid: (jid: string) => boolean;
19
+ export declare const isLiveScreenMonitoringJid: (jid: string) => boolean;
20
+ export declare const isSoftphoneJid: (jid: string) => boolean;
21
+ export declare const isVideoJid: (jid: string) => boolean;
22
+ export declare type RetryPromise<T = any> = {
23
+ promise: Promise<T>;
24
+ cancel: (reason?: string | Error) => void;
25
+ complete: (value?: T) => void;
26
+ hasCompleted: () => boolean;
27
+ _id: string;
28
+ };
29
+ export declare function retryPromise<T = any>(promiseFn: () => Promise<T>, retryFn: (error?: Error | any) => boolean | number, retryInterval?: number, logger?: any): RetryPromise<T>;
30
+ export declare const parseJwt: (token: string) => any;
31
+ export declare function calculatePayloadSize(trace: any): number;
32
+ export declare function getUfragFromSdp(sdp: string | undefined): string | null;
33
+ export declare function getIcePwdFromSdp(sdp: string | undefined): string | null;
34
+ export declare function iceIsDifferent(sdp1: string | undefined, sdp2: string | undefined): boolean;