@vonage/client-sdk 2.3.1 → 2.4.0-alpha.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.
@@ -33784,26 +33784,26 @@
33784
33784
  initMetadataForCompanion(Companion_149);
33785
33785
  initMetadataForObject($serializer_174, '$serializer', VOID, VOID, [GeneratedSerializer]);
33786
33786
  initMetadataForClass(SessionTerminatedEvent, 'SessionTerminatedEvent', VOID, VOID, [SocketEvent], VOID, VOID, {0: $serializer_getInstance_174});
33787
- function onAudioSay() {
33788
- }
33789
- function onAudioMuteUpdate(conversationId, legId, isMuted) {
33787
+ function onRTCHangup(conversationId, legId, hangup) {
33790
33788
  }
33791
- function onAudioEarmuffUpdate(conversationId, legId, earmuffStatus) {
33789
+ function onRTCTransfer(conversationId, legId) {
33792
33790
  }
33793
- function onAudioDTMFUpdate(conversationId, legId, digits) {
33791
+ function onLegStatusUpdate(conversationId, legId, fromUserId, status) {
33794
33792
  }
33795
- initMetadataForInterface(AudioEventListener, 'AudioEventListener');
33793
+ initMetadataForInterface(RTCEventListener, 'RTCEventListener');
33796
33794
  function onConversationEvent(event) {
33797
33795
  }
33798
33796
  initMetadataForInterface(ConversationEventListener, 'ConversationEventListener');
33799
- function onRTCHangup(conversationId, legId, hangup) {
33797
+ function onAudioSay() {
33800
33798
  }
33801
- function onRTCTransfer(conversationId, legId) {
33799
+ function onAudioMuteUpdate(conversationId, legId, isMuted) {
33802
33800
  }
33803
- function onLegStatusUpdate(conversationId, legId, fromUserId, status) {
33801
+ function onAudioEarmuffUpdate(conversationId, legId, earmuffStatus) {
33804
33802
  }
33805
- initMetadataForInterface(RTCEventListener, 'RTCEventListener');
33806
- initMetadataForClass(ChatAPIImpl$1, VOID, VOID, VOID, [AudioEventListener, ConversationEventListener, RTCEventListener]);
33803
+ function onAudioDTMFUpdate(conversationId, legId, digits) {
33804
+ }
33805
+ initMetadataForInterface(AudioEventListener, 'AudioEventListener');
33806
+ initMetadataForClass(ChatAPIImpl$1, VOID, VOID, VOID, [RTCEventListener, ConversationEventListener, AudioEventListener]);
33807
33807
  initMetadataForClass(ChatAPIImpl, 'ChatAPIImpl', VOID, VOID, [ChatAPI]);
33808
33808
  initMetadataForClass(LoggingLevel, 'LoggingLevel', VOID, Enum);
33809
33809
  initMetadataForObject(DefaultConfig, 'DefaultConfig');
@@ -33937,7 +33937,7 @@
33937
33937
  initMetadataForClass(HangupReason, 'HangupReason', VOID, Enum);
33938
33938
  initMetadataForClass(LegStatus, 'LegStatus', VOID, Enum);
33939
33939
  initMetadataForClass(CallDisconnectReason, 'CallDisconnectReason', VOID, Enum);
33940
- initMetadataForClass(VoiceAPIImpl$1, VOID, VOID, VOID, [AudioEventListener, ConversationEventListener, RTCEventListener]);
33940
+ initMetadataForClass(VoiceAPIImpl$1, VOID, VOID, VOID, [RTCEventListener, ConversationEventListener, AudioEventListener]);
33941
33941
  initMetadataForClass(VoiceAPIImpl, 'VoiceAPIImpl');
33942
33942
  initMetadataForInterface(CallEvent, 'CallEvent');
33943
33943
  initMetadataForClass(SetupOutboundCall, 'SetupOutboundCall', VOID, VOID, [CallEvent]);
@@ -34156,7 +34156,7 @@
34156
34156
  initMetadataForClass(runAfterDelay$1);
34157
34157
  //endregion
34158
34158
  function BuildKonfig() {
34159
- this.t1e_1 = '2.3.1';
34159
+ this.t1e_1 = '2.4.0-alpha.1';
34160
34160
  }
34161
34161
  var BuildKonfig_instance;
34162
34162
  function EmergencyCallOptions(ringbackTone) {
@@ -91902,15 +91902,23 @@
91902
91902
 
91903
91903
  var libExports = requireLib();
91904
91904
 
91905
+ const ICE_GATHERING_TIMEOUT_MS = 10000;
91905
91906
  const waitFirstICEGatheringComplete = (peerConnection) => __awaiter(void 0, void 0, void 0, function* () {
91906
91907
  let offer_sent = false;
91907
- return new Promise((resolve) => {
91908
- peerConnection.onicecandidate = (event) => {
91908
+ return new Promise((resolve, reject) => {
91909
+ const handler = (event) => {
91909
91910
  if (event.candidate && !offer_sent) {
91910
91911
  offer_sent = true;
91912
+ clearTimeout(timeoutId);
91913
+ peerConnection.removeEventListener('icecandidate', handler);
91911
91914
  resolve();
91912
91915
  }
91913
91916
  };
91917
+ peerConnection.addEventListener('icecandidate', handler);
91918
+ const timeoutId = setTimeout(() => {
91919
+ peerConnection.removeEventListener('icecandidate', handler);
91920
+ reject(new Error(`ICE gathering timed out after ${ICE_GATHERING_TIMEOUT_MS}ms`));
91921
+ }, ICE_GATHERING_TIMEOUT_MS);
91914
91922
  });
91915
91923
  });
91916
91924
  function createDummyCandidateSDP(pc) {
@@ -92165,8 +92173,25 @@
92165
92173
  class MediaClient {
92166
92174
  constructor() {
92167
92175
  this.pcs = new Map();
92176
+ this.pcListeners = new WeakMap();
92168
92177
  this.audio = undefined;
92169
92178
  }
92179
+ setPeerConnectionCreatedCallback(callback) {
92180
+ this.peerConnectionCreatedCallback = callback;
92181
+ }
92182
+ addPCListener(pc, type, listener) {
92183
+ var _a;
92184
+ pc.addEventListener(type, listener);
92185
+ const list = (_a = this.pcListeners.get(pc)) !== null && _a !== void 0 ? _a : [];
92186
+ list.push({ type, listener });
92187
+ this.pcListeners.set(pc, list);
92188
+ }
92189
+ removeAllPCListeners(pc) {
92190
+ var _a;
92191
+ (_a = this.pcListeners
92192
+ .get(pc)) === null || _a === void 0 ? void 0 : _a.forEach(({ type, listener }) => pc.removeEventListener(type, listener));
92193
+ this.pcListeners.delete(pc);
92194
+ }
92170
92195
  enableRtcStatsCollection(id, interval, closure) {
92171
92196
  const pc = this.pcs.get(id);
92172
92197
  if (!pc) {
@@ -92191,11 +92216,11 @@
92191
92216
  enableMediaInbound(rtcId, offerSDP, closure) {
92192
92217
  return __awaiter(this, void 0, void 0, function* () {
92193
92218
  try {
92194
- const pc = yield this.getNewPC();
92195
- pc.onconnectionstatechange = () => {
92219
+ const pc = yield this.getNewPC(rtcId);
92220
+ this.addPCListener(pc, 'connectionstatechange', (() => {
92196
92221
  var _a;
92197
92222
  (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onConnectionChange(rtcId, pc.connectionState);
92198
- };
92223
+ }));
92199
92224
  this.pcs.set(rtcId, pc);
92200
92225
  const sdp = yield createAnswer(pc, offerSDP);
92201
92226
  closure(null, sdp);
@@ -92208,8 +92233,9 @@
92208
92233
  }
92209
92234
  enableMediaOutbound(closure) {
92210
92235
  return __awaiter(this, void 0, void 0, function* () {
92236
+ let pc;
92211
92237
  try {
92212
- const pc = yield this.getNewPC();
92238
+ pc = yield this.getNewPC(null);
92213
92239
  const sdp = yield createOffer(pc);
92214
92240
  closure(null, sdp, (legId) => {
92215
92241
  if (!legId) {
@@ -92218,13 +92244,15 @@
92218
92244
  return;
92219
92245
  }
92220
92246
  this.pcs.set(legId, pc);
92221
- pc.onconnectionstatechange = () => {
92247
+ this.addPCListener(pc, 'connectionstatechange', (() => {
92222
92248
  var _a;
92223
92249
  (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onConnectionChange(legId, pc.connectionState);
92224
- };
92250
+ }));
92225
92251
  });
92226
92252
  }
92227
92253
  catch (err) {
92254
+ if (pc)
92255
+ this.closePeerConnection(pc);
92228
92256
  const message = err instanceof Error ? err.message : null;
92229
92257
  closure(new clientsdkClientcore_jsExports.vonage.CreateOfferErrorJS(message), null, () => {
92230
92258
  throw new Error('Callback not implemented, and should never get called');
@@ -92232,10 +92260,11 @@
92232
92260
  }
92233
92261
  });
92234
92262
  }
92235
- getNewPC() {
92263
+ getNewPC(callId) {
92264
+ var _a;
92236
92265
  return __awaiter(this, void 0, void 0, function* () {
92237
92266
  const pc = yield createRtcAudioConnection();
92238
- pc.ontrack = (evt) => {
92267
+ this.addPCListener(pc, 'track', ((evt) => {
92239
92268
  const stream = evt.streams[0];
92240
92269
  if (stream) {
92241
92270
  const audio = new Audio();
@@ -92243,7 +92272,8 @@
92243
92272
  audio.autoplay = true;
92244
92273
  this.audio = audio;
92245
92274
  }
92246
- };
92275
+ }));
92276
+ (_a = this.peerConnectionCreatedCallback) === null || _a === void 0 ? void 0 : _a.call(this, callId, pc);
92247
92277
  return pc;
92248
92278
  });
92249
92279
  }
@@ -92331,6 +92361,7 @@
92331
92361
  // Private Methods
92332
92362
  closePeerConnection(pc) {
92333
92363
  var _a;
92364
+ this.removeAllPCListeners(pc);
92334
92365
  pc.close();
92335
92366
  pc.getSenders().forEach((sender) => {
92336
92367
  var _a;
@@ -96848,7 +96879,8 @@
96848
96879
  super.emitter = value;
96849
96880
  }
96850
96881
  constructor(config = new ClientInitConfig()) {
96851
- super(convertInitConfig(config), new HttpClient(), new SocketClient(), new MediaClient());
96882
+ const mediaClient = new MediaClient();
96883
+ super(convertInitConfig(config), new HttpClient(), new SocketClient(), mediaClient);
96852
96884
  /**
96853
96885
  * Proxy object to allow for registering callbacks via `on()`
96854
96886
  * @internal
@@ -96878,13 +96910,17 @@
96878
96910
  };
96879
96911
  }
96880
96912
  });
96913
+ mediaClient.setPeerConnectionCreatedCallback((callId, pc) => {
96914
+ var _a, _b;
96915
+ (_b = (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.peerConnectionCreated) === null || _b === void 0 ? void 0 : _b.call(_a, callId, pc);
96916
+ });
96881
96917
  this.setConfig(config);
96882
96918
  }
96883
96919
  /**
96884
96920
  * Set a configuration for the client SDK
96885
96921
  *
96886
96922
  * @example
96887
- * [[include: snippet_SetClientConfig.txt]]
96923
+ * [[include: snippet_Config.txt]]
96888
96924
  *
96889
96925
  * @param config - A configuration object
96890
96926
  * @returns void
@@ -96960,17 +96996,24 @@
96960
96996
  callbacks.clear();
96961
96997
  }
96962
96998
  /**
96963
- * Create a session with a token and optional sessionId
96964
- * If no sessionId is provided, a new one will be generated
96965
- * and returned. If a sessionId is provided, it will be used
96966
- * to resume an existing session.
96999
+ * Create (or reconnect to) a session.
97000
+ *
97001
+ * When `sessionId` is omitted or `null`, a completely new session is created.
97002
+ *
97003
+ * When `sessionId` is set to the value returned by a **previous** `createSession` call, the
97004
+ * Conversation Service will replay any pending events into the new session. In particular, an
97005
+ * unanswered inbound call invite that arrived before a page refresh will be re-delivered so that
97006
+ * `onCallInvite` fires automatically — no extra API call is needed.
97007
+ *
97008
+ * **Important:** The Conversation Service retains pending events for approximately 30 seconds.
97009
+ * Persist the session ID (e.g. in `sessionStorage`) and pass it back within that window.
96967
97010
  *
96968
97011
  * @example
96969
97012
  * [[include: snippet_SessionCreate.txt]]
96970
97013
  *
96971
- * @param token
96972
- * @param sessionId - optional sessionId to use
96973
- * @returns the `sessionId` of the session
97014
+ * @param token - JWT token of the user.
97015
+ * @param sessionId - Optional previous session ID. Omit or pass `null` for a fresh session.
97016
+ * @returns The `sessionId` of the newly established session.
96974
97017
  */
96975
97018
  createSession(token, sessionId) {
96976
97019
  const _super = Object.create(null, {