@vonage/client-sdk 2.3.1 → 2.4.0-alpha.0

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.
@@ -33778,15 +33778,6 @@ function requireClientsdkClientcore () {
33778
33778
  initMetadataForCompanion(Companion_149);
33779
33779
  initMetadataForObject($serializer_174, '$serializer', VOID, VOID, [GeneratedSerializer]);
33780
33780
  initMetadataForClass(SessionTerminatedEvent, 'SessionTerminatedEvent', VOID, VOID, [SocketEvent], VOID, VOID, {0: $serializer_getInstance_174});
33781
- function onAudioSay() {
33782
- }
33783
- function onAudioMuteUpdate(conversationId, legId, isMuted) {
33784
- }
33785
- function onAudioEarmuffUpdate(conversationId, legId, earmuffStatus) {
33786
- }
33787
- function onAudioDTMFUpdate(conversationId, legId, digits) {
33788
- }
33789
- initMetadataForInterface(AudioEventListener, 'AudioEventListener');
33790
33781
  function onConversationEvent(event) {
33791
33782
  }
33792
33783
  initMetadataForInterface(ConversationEventListener, 'ConversationEventListener');
@@ -33797,7 +33788,16 @@ function requireClientsdkClientcore () {
33797
33788
  function onLegStatusUpdate(conversationId, legId, fromUserId, status) {
33798
33789
  }
33799
33790
  initMetadataForInterface(RTCEventListener, 'RTCEventListener');
33800
- initMetadataForClass(ChatAPIImpl$1, VOID, VOID, VOID, [AudioEventListener, ConversationEventListener, RTCEventListener]);
33791
+ function onAudioSay() {
33792
+ }
33793
+ function onAudioMuteUpdate(conversationId, legId, isMuted) {
33794
+ }
33795
+ function onAudioEarmuffUpdate(conversationId, legId, earmuffStatus) {
33796
+ }
33797
+ function onAudioDTMFUpdate(conversationId, legId, digits) {
33798
+ }
33799
+ initMetadataForInterface(AudioEventListener, 'AudioEventListener');
33800
+ initMetadataForClass(ChatAPIImpl$1, VOID, VOID, VOID, [ConversationEventListener, RTCEventListener, AudioEventListener]);
33801
33801
  initMetadataForClass(ChatAPIImpl, 'ChatAPIImpl', VOID, VOID, [ChatAPI]);
33802
33802
  initMetadataForClass(LoggingLevel, 'LoggingLevel', VOID, Enum);
33803
33803
  initMetadataForObject(DefaultConfig, 'DefaultConfig');
@@ -33931,7 +33931,7 @@ function requireClientsdkClientcore () {
33931
33931
  initMetadataForClass(HangupReason, 'HangupReason', VOID, Enum);
33932
33932
  initMetadataForClass(LegStatus, 'LegStatus', VOID, Enum);
33933
33933
  initMetadataForClass(CallDisconnectReason, 'CallDisconnectReason', VOID, Enum);
33934
- initMetadataForClass(VoiceAPIImpl$1, VOID, VOID, VOID, [AudioEventListener, ConversationEventListener, RTCEventListener]);
33934
+ initMetadataForClass(VoiceAPIImpl$1, VOID, VOID, VOID, [ConversationEventListener, RTCEventListener, AudioEventListener]);
33935
33935
  initMetadataForClass(VoiceAPIImpl, 'VoiceAPIImpl');
33936
33936
  initMetadataForInterface(CallEvent, 'CallEvent');
33937
33937
  initMetadataForClass(SetupOutboundCall, 'SetupOutboundCall', VOID, VOID, [CallEvent]);
@@ -34150,7 +34150,7 @@ function requireClientsdkClientcore () {
34150
34150
  initMetadataForClass(runAfterDelay$1);
34151
34151
  //endregion
34152
34152
  function BuildKonfig() {
34153
- this.t1e_1 = '2.3.1';
34153
+ this.t1e_1 = '2.4.0-alpha.0';
34154
34154
  }
34155
34155
  var BuildKonfig_instance;
34156
34156
  function EmergencyCallOptions(ringbackTone) {
@@ -91896,15 +91896,23 @@ function requireLib () {
91896
91896
 
91897
91897
  var libExports = requireLib();
91898
91898
 
91899
+ const ICE_GATHERING_TIMEOUT_MS = 10000;
91899
91900
  const waitFirstICEGatheringComplete = (peerConnection) => __awaiter(void 0, void 0, void 0, function* () {
91900
91901
  let offer_sent = false;
91901
- return new Promise((resolve) => {
91902
- peerConnection.onicecandidate = (event) => {
91902
+ return new Promise((resolve, reject) => {
91903
+ const handler = (event) => {
91903
91904
  if (event.candidate && !offer_sent) {
91904
91905
  offer_sent = true;
91906
+ clearTimeout(timeoutId);
91907
+ peerConnection.removeEventListener('icecandidate', handler);
91905
91908
  resolve();
91906
91909
  }
91907
91910
  };
91911
+ peerConnection.addEventListener('icecandidate', handler);
91912
+ const timeoutId = setTimeout(() => {
91913
+ peerConnection.removeEventListener('icecandidate', handler);
91914
+ reject(new Error(`ICE gathering timed out after ${ICE_GATHERING_TIMEOUT_MS}ms`));
91915
+ }, ICE_GATHERING_TIMEOUT_MS);
91908
91916
  });
91909
91917
  });
91910
91918
  function createDummyCandidateSDP(pc) {
@@ -92159,8 +92167,25 @@ const TrackType = {
92159
92167
  class MediaClient {
92160
92168
  constructor() {
92161
92169
  this.pcs = new Map();
92170
+ this.pcListeners = new WeakMap();
92162
92171
  this.audio = undefined;
92163
92172
  }
92173
+ setPeerConnectionCreatedCallback(callback) {
92174
+ this.peerConnectionCreatedCallback = callback;
92175
+ }
92176
+ addPCListener(pc, type, listener) {
92177
+ var _a;
92178
+ pc.addEventListener(type, listener);
92179
+ const list = (_a = this.pcListeners.get(pc)) !== null && _a !== void 0 ? _a : [];
92180
+ list.push({ type, listener });
92181
+ this.pcListeners.set(pc, list);
92182
+ }
92183
+ removeAllPCListeners(pc) {
92184
+ var _a;
92185
+ (_a = this.pcListeners
92186
+ .get(pc)) === null || _a === void 0 ? void 0 : _a.forEach(({ type, listener }) => pc.removeEventListener(type, listener));
92187
+ this.pcListeners.delete(pc);
92188
+ }
92164
92189
  enableRtcStatsCollection(id, interval, closure) {
92165
92190
  const pc = this.pcs.get(id);
92166
92191
  if (!pc) {
@@ -92185,11 +92210,11 @@ class MediaClient {
92185
92210
  enableMediaInbound(rtcId, offerSDP, closure) {
92186
92211
  return __awaiter(this, void 0, void 0, function* () {
92187
92212
  try {
92188
- const pc = yield this.getNewPC();
92189
- pc.onconnectionstatechange = () => {
92213
+ const pc = yield this.getNewPC(rtcId);
92214
+ this.addPCListener(pc, 'connectionstatechange', (() => {
92190
92215
  var _a;
92191
92216
  (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onConnectionChange(rtcId, pc.connectionState);
92192
- };
92217
+ }));
92193
92218
  this.pcs.set(rtcId, pc);
92194
92219
  const sdp = yield createAnswer(pc, offerSDP);
92195
92220
  closure(null, sdp);
@@ -92202,8 +92227,9 @@ class MediaClient {
92202
92227
  }
92203
92228
  enableMediaOutbound(closure) {
92204
92229
  return __awaiter(this, void 0, void 0, function* () {
92230
+ let pc;
92205
92231
  try {
92206
- const pc = yield this.getNewPC();
92232
+ pc = yield this.getNewPC(null);
92207
92233
  const sdp = yield createOffer(pc);
92208
92234
  closure(null, sdp, (legId) => {
92209
92235
  if (!legId) {
@@ -92212,13 +92238,15 @@ class MediaClient {
92212
92238
  return;
92213
92239
  }
92214
92240
  this.pcs.set(legId, pc);
92215
- pc.onconnectionstatechange = () => {
92241
+ this.addPCListener(pc, 'connectionstatechange', (() => {
92216
92242
  var _a;
92217
92243
  (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onConnectionChange(legId, pc.connectionState);
92218
- };
92244
+ }));
92219
92245
  });
92220
92246
  }
92221
92247
  catch (err) {
92248
+ if (pc)
92249
+ this.closePeerConnection(pc);
92222
92250
  const message = err instanceof Error ? err.message : null;
92223
92251
  closure(new clientsdkClientcore_jsExports.vonage.CreateOfferErrorJS(message), null, () => {
92224
92252
  throw new Error('Callback not implemented, and should never get called');
@@ -92226,10 +92254,11 @@ class MediaClient {
92226
92254
  }
92227
92255
  });
92228
92256
  }
92229
- getNewPC() {
92257
+ getNewPC(callId) {
92258
+ var _a;
92230
92259
  return __awaiter(this, void 0, void 0, function* () {
92231
92260
  const pc = yield createRtcAudioConnection();
92232
- pc.ontrack = (evt) => {
92261
+ this.addPCListener(pc, 'track', ((evt) => {
92233
92262
  const stream = evt.streams[0];
92234
92263
  if (stream) {
92235
92264
  const audio = new Audio();
@@ -92237,7 +92266,8 @@ class MediaClient {
92237
92266
  audio.autoplay = true;
92238
92267
  this.audio = audio;
92239
92268
  }
92240
- };
92269
+ }));
92270
+ (_a = this.peerConnectionCreatedCallback) === null || _a === void 0 ? void 0 : _a.call(this, callId, pc);
92241
92271
  return pc;
92242
92272
  });
92243
92273
  }
@@ -92325,6 +92355,7 @@ class MediaClient {
92325
92355
  // Private Methods
92326
92356
  closePeerConnection(pc) {
92327
92357
  var _a;
92358
+ this.removeAllPCListeners(pc);
92328
92359
  pc.close();
92329
92360
  pc.getSenders().forEach((sender) => {
92330
92361
  var _a;
@@ -96842,7 +96873,8 @@ class VonageClient extends clientsdkClientcore_jsExports.vonage.CombinedClientJS
96842
96873
  super.emitter = value;
96843
96874
  }
96844
96875
  constructor(config = new ClientInitConfig()) {
96845
- super(convertInitConfig(config), new HttpClient(), new SocketClient(), new MediaClient());
96876
+ const mediaClient = new MediaClient();
96877
+ super(convertInitConfig(config), new HttpClient(), new SocketClient(), mediaClient);
96846
96878
  /**
96847
96879
  * Proxy object to allow for registering callbacks via `on()`
96848
96880
  * @internal
@@ -96872,13 +96904,17 @@ class VonageClient extends clientsdkClientcore_jsExports.vonage.CombinedClientJS
96872
96904
  };
96873
96905
  }
96874
96906
  });
96907
+ mediaClient.setPeerConnectionCreatedCallback((callId, pc) => {
96908
+ var _a, _b;
96909
+ (_b = (_a = this.emitter) === null || _a === void 0 ? void 0 : _a.peerConnectionCreated) === null || _b === void 0 ? void 0 : _b.call(_a, callId, pc);
96910
+ });
96875
96911
  this.setConfig(config);
96876
96912
  }
96877
96913
  /**
96878
96914
  * Set a configuration for the client SDK
96879
96915
  *
96880
96916
  * @example
96881
- * [[include: snippet_SetClientConfig.txt]]
96917
+ * [[include: snippet_Config.txt]]
96882
96918
  *
96883
96919
  * @param config - A configuration object
96884
96920
  * @returns void
@@ -96954,17 +96990,24 @@ class VonageClient extends clientsdkClientcore_jsExports.vonage.CombinedClientJS
96954
96990
  callbacks.clear();
96955
96991
  }
96956
96992
  /**
96957
- * Create a session with a token and optional sessionId
96958
- * If no sessionId is provided, a new one will be generated
96959
- * and returned. If a sessionId is provided, it will be used
96960
- * to resume an existing session.
96993
+ * Create (or reconnect to) a session.
96994
+ *
96995
+ * When `sessionId` is omitted or `null`, a completely new session is created.
96996
+ *
96997
+ * When `sessionId` is set to the value returned by a **previous** `createSession` call, the
96998
+ * Conversation Service will replay any pending events into the new session. In particular, an
96999
+ * unanswered inbound call invite that arrived before a page refresh will be re-delivered so that
97000
+ * `onCallInvite` fires automatically — no extra API call is needed.
97001
+ *
97002
+ * **Important:** The Conversation Service retains pending events for approximately 30 seconds.
97003
+ * Persist the session ID (e.g. in `sessionStorage`) and pass it back within that window.
96961
97004
  *
96962
97005
  * @example
96963
97006
  * [[include: snippet_SessionCreate.txt]]
96964
97007
  *
96965
- * @param token
96966
- * @param sessionId - optional sessionId to use
96967
- * @returns the `sessionId` of the session
97008
+ * @param token - JWT token of the user.
97009
+ * @param sessionId - Optional previous session ID. Omit or pass `null` for a fresh session.
97010
+ * @returns The `sessionId` of the newly established session.
96968
97011
  */
96969
97012
  createSession(token, sessionId) {
96970
97013
  const _super = Object.create(null, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vonage/client-sdk",
3
- "version": "2.3.1",
3
+ "version": "2.4.0-alpha.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "module": "dist/client/index.mjs",