@stream-io/video-client 0.0.46 → 0.0.47

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ### [0.0.47](https://github.com/GetStream/stream-video-js/compare/client0.0.46...client0.0.47) (2023-07-14)
6
+
7
+
8
+ ### Features
9
+
10
+ * take the location-hint on SDK init ([#799](https://github.com/GetStream/stream-video-js/issues/799)) ([ee5b170](https://github.com/GetStream/stream-video-js/commit/ee5b170337278a7063a368790f46b270647abf71))
11
+
5
12
  ### [0.0.46](https://github.com/GetStream/stream-video-js/compare/client0.0.45...client0.0.46) (2023-07-14)
6
13
 
7
14
 
@@ -5665,7 +5665,7 @@ const logLevels = Object.freeze({
5665
5665
  warn: 3,
5666
5666
  error: 4,
5667
5667
  });
5668
- let logger$2;
5668
+ let logger$3;
5669
5669
  let level = 'info';
5670
5670
  const logToConsole = (logLevel, message, ...args) => {
5671
5671
  let logMethod;
@@ -5689,7 +5689,7 @@ const logToConsole = (logLevel, message, ...args) => {
5689
5689
  logMethod(message, ...args);
5690
5690
  };
5691
5691
  const setLogger = (l, lvl) => {
5692
- logger$2 = l;
5692
+ logger$3 = l;
5693
5693
  if (lvl) {
5694
5694
  setLogLevel(lvl);
5695
5695
  }
@@ -5698,7 +5698,7 @@ const setLogLevel = (l) => {
5698
5698
  level = l;
5699
5699
  };
5700
5700
  const getLogger = (withTags) => {
5701
- const loggerMethod = logger$2 || logToConsole;
5701
+ const loggerMethod = logger$3 || logToConsole;
5702
5702
  const tags = (withTags || []).join(':');
5703
5703
  const result = (logLevel, message, ...args) => {
5704
5704
  if (logLevels[logLevel] >= logLevels[level]) {
@@ -6491,7 +6491,7 @@ class Publisher {
6491
6491
  }
6492
6492
  }
6493
6493
 
6494
- const logger$1 = getLogger(['Subscriber']);
6494
+ const logger$2 = getLogger(['Subscriber']);
6495
6495
  /**
6496
6496
  * A wrapper around the `RTCPeerConnection` that handles the incoming
6497
6497
  * media streams from the SFU.
@@ -6567,10 +6567,10 @@ class Subscriber {
6567
6567
  // that are migrating to the new subscriber.
6568
6568
  // Once all of them are available, we can close the previous subscriber.
6569
6569
  const handleTrackMigration = (e) => {
6570
- logger$1('debug', `[Migration]: Migrated track: ${e.track.id}, ${e.track.kind}`);
6570
+ logger$2('debug', `[Migration]: Migrated track: ${e.track.id}, ${e.track.kind}`);
6571
6571
  trackIdsToMigrate.delete(e.track.id);
6572
6572
  if (trackIdsToMigrate.size === 0) {
6573
- logger$1('debug', `[Migration]: Migration complete`);
6573
+ logger$2('debug', `[Migration]: Migration complete`);
6574
6574
  pc.removeEventListener('track', handleTrackMigration);
6575
6575
  cleanupMigration();
6576
6576
  }
@@ -6598,7 +6598,7 @@ class Subscriber {
6598
6598
  * Restarts the ICE connection and renegotiates with the SFU.
6599
6599
  */
6600
6600
  this.restartIce = () => {
6601
- logger$1('debug', 'Restarting ICE connection');
6601
+ logger$2('debug', 'Restarting ICE connection');
6602
6602
  this.pc.restartIce();
6603
6603
  };
6604
6604
  this.handleOnTrack = (e) => {
@@ -6606,19 +6606,19 @@ class Subscriber {
6606
6606
  // example: `e3f6aaf8-b03d-4911-be36-83f47d37a76a:TRACK_TYPE_VIDEO`
6607
6607
  const [trackId, trackType] = primaryStream.id.split(':');
6608
6608
  const participantToUpdate = this.state.participants.find((p) => p.trackLookupPrefix === trackId);
6609
- logger$1('debug', `[onTrack]: Got remote ${trackType} track for userId: ${participantToUpdate === null || participantToUpdate === void 0 ? void 0 : participantToUpdate.userId}`, e.track.id, e.track);
6609
+ logger$2('debug', `[onTrack]: Got remote ${trackType} track for userId: ${participantToUpdate === null || participantToUpdate === void 0 ? void 0 : participantToUpdate.userId}`, e.track.id, e.track);
6610
6610
  if (!participantToUpdate) {
6611
- logger$1('error', `[onTrack]: Received track for unknown participant: ${trackId}`, e);
6611
+ logger$2('error', `[onTrack]: Received track for unknown participant: ${trackId}`, e);
6612
6612
  return;
6613
6613
  }
6614
6614
  e.track.addEventListener('mute', () => {
6615
- logger$1('info', `[onTrack]: Track muted: ${participantToUpdate.userId} ${trackType}:${trackId}`);
6615
+ logger$2('info', `[onTrack]: Track muted: ${participantToUpdate.userId} ${trackType}:${trackId}`);
6616
6616
  });
6617
6617
  e.track.addEventListener('unmute', () => {
6618
- logger$1('info', `[onTrack]: Track unmuted: ${participantToUpdate.userId} ${trackType}:${trackId}`);
6618
+ logger$2('info', `[onTrack]: Track unmuted: ${participantToUpdate.userId} ${trackType}:${trackId}`);
6619
6619
  });
6620
6620
  e.track.addEventListener('ended', () => {
6621
- logger$1('info', `[onTrack]: Track ended: ${participantToUpdate.userId} ${trackType}:${trackId}`);
6621
+ logger$2('info', `[onTrack]: Track ended: ${participantToUpdate.userId} ${trackType}:${trackId}`);
6622
6622
  });
6623
6623
  const streamKindProp = {
6624
6624
  TRACK_TYPE_AUDIO: 'audioStream',
@@ -6626,12 +6626,12 @@ class Subscriber {
6626
6626
  TRACK_TYPE_SCREEN_SHARE: 'screenShareStream',
6627
6627
  }[trackType];
6628
6628
  if (!streamKindProp) {
6629
- logger$1('error', `Unknown track type: ${trackType}`);
6629
+ logger$2('error', `Unknown track type: ${trackType}`);
6630
6630
  return;
6631
6631
  }
6632
6632
  const previousStream = participantToUpdate[streamKindProp];
6633
6633
  if (previousStream) {
6634
- logger$1('info', `[onTrack]: Cleaning up previous remote ${e.track.kind} tracks for userId: ${participantToUpdate.userId}`);
6634
+ logger$2('info', `[onTrack]: Cleaning up previous remote ${e.track.kind} tracks for userId: ${participantToUpdate.userId}`);
6635
6635
  previousStream.getTracks().forEach((t) => {
6636
6636
  t.stop();
6637
6637
  previousStream.removeTrack(t);
@@ -6644,7 +6644,7 @@ class Subscriber {
6644
6644
  this.onIceCandidate = (e) => __awaiter(this, void 0, void 0, function* () {
6645
6645
  const { candidate } = e;
6646
6646
  if (!candidate) {
6647
- logger$1('debug', 'null ice candidate');
6647
+ logger$2('debug', 'null ice candidate');
6648
6648
  return;
6649
6649
  }
6650
6650
  yield this.sfuClient.iceTrickle({
@@ -6653,7 +6653,7 @@ class Subscriber {
6653
6653
  });
6654
6654
  });
6655
6655
  this.negotiate = (subscriberOffer) => __awaiter(this, void 0, void 0, function* () {
6656
- logger$1('info', `Received subscriberOffer`, subscriberOffer);
6656
+ logger$2('info', `Received subscriberOffer`, subscriberOffer);
6657
6657
  yield this.pc.setRemoteDescription({
6658
6658
  type: 'offer',
6659
6659
  sdp: subscriberOffer.sdp,
@@ -6664,7 +6664,7 @@ class Subscriber {
6664
6664
  yield this.pc.addIceCandidate(iceCandidate);
6665
6665
  }
6666
6666
  catch (e) {
6667
- logger$1('error', `ICE candidate error`, [e, candidate]);
6667
+ logger$2('error', `ICE candidate error`, [e, candidate]);
6668
6668
  }
6669
6669
  }));
6670
6670
  // apply ice candidates
@@ -6676,15 +6676,15 @@ class Subscriber {
6676
6676
  });
6677
6677
  });
6678
6678
  this.onIceConnectionStateChange = () => {
6679
- logger$1('info', `ICE connection state changed`, this.pc.iceConnectionState);
6679
+ logger$2('info', `ICE connection state changed`, this.pc.iceConnectionState);
6680
6680
  };
6681
6681
  this.onIceGatheringStateChange = () => {
6682
- logger$1('info', `ICE gathering state changed`, this.pc.iceGatheringState);
6682
+ logger$2('info', `ICE gathering state changed`, this.pc.iceGatheringState);
6683
6683
  };
6684
6684
  this.onIceCandidateError = (e) => {
6685
6685
  const errorMessage = e instanceof RTCPeerConnectionIceErrorEvent &&
6686
6686
  `${e.errorCode}: ${e.errorText}`;
6687
- logger$1('error', `ICE Candidate error`, errorMessage);
6687
+ logger$2('error', `ICE Candidate error`, errorMessage);
6688
6688
  };
6689
6689
  this.sfuClient = sfuClient;
6690
6690
  this.dispatcher = dispatcher;
@@ -8013,7 +8013,7 @@ const watchCallGrantsUpdated = (state) => {
8013
8013
  };
8014
8014
  };
8015
8015
 
8016
- const logger = getLogger(['events']);
8016
+ const logger$1 = getLogger(['events']);
8017
8017
  /**
8018
8018
  * An event responder which handles the `changePublishQuality` event.
8019
8019
  */
@@ -8078,7 +8078,7 @@ const watchSfuErrorReports = (dispatcher) => {
8078
8078
  if (e.eventPayload.oneofKind !== 'error' || !e.eventPayload.error.error)
8079
8079
  return;
8080
8080
  const error = e.eventPayload.error.error;
8081
- logger('error', 'SFU reported error', {
8081
+ logger$1('error', 'SFU reported error', {
8082
8082
  code: ErrorCode[error.code],
8083
8083
  message: error.message,
8084
8084
  shouldRetry: error.shouldRetry,
@@ -8525,7 +8525,7 @@ const join = (httpClient, type, id, data) => __awaiter(void 0, void 0, void 0, f
8525
8525
  };
8526
8526
  });
8527
8527
  const doJoin = (httpClient, type, id, data) => __awaiter(void 0, void 0, void 0, function* () {
8528
- const location = yield getLocationHint();
8528
+ const location = yield httpClient.getLocationHint();
8529
8529
  const request = Object.assign(Object.assign({}, data), { location });
8530
8530
  // FIXME OL: remove this once cascading is enabled by default
8531
8531
  const cascadingModeParams = getCascadingModeParams();
@@ -8540,28 +8540,6 @@ const doJoin = (httpClient, type, id, data) => __awaiter(void 0, void 0, void 0,
8540
8540
  }
8541
8541
  return httpClient.post(`/call/${type}/${id}/join`, request);
8542
8542
  });
8543
- const getLocationHint = () => __awaiter(void 0, void 0, void 0, function* () {
8544
- const hintURL = `https://hint.stream-io-video.com/`;
8545
- const abortController = new AbortController();
8546
- const timeoutId = setTimeout(() => abortController.abort(), 1000);
8547
- const logger = getLogger(['call']);
8548
- try {
8549
- const response = yield fetch(hintURL, {
8550
- method: 'HEAD',
8551
- signal: abortController.signal,
8552
- });
8553
- const awsPop = response.headers.get('x-amz-cf-pop') || 'ERR';
8554
- logger === null || logger === void 0 ? void 0 : logger('info', `Location header: ${awsPop}`);
8555
- return awsPop.substring(0, 3); // AMS1-P2 -> AMS
8556
- }
8557
- catch (e) {
8558
- logger === null || logger === void 0 ? void 0 : logger('error', `Failed to get location hint from ${hintURL}`, e);
8559
- return 'ERR';
8560
- }
8561
- finally {
8562
- clearTimeout(timeoutId);
8563
- }
8564
- });
8565
8543
  const toRtcConfiguration = (config) => {
8566
8544
  if (!config || config.length === 0)
8567
8545
  return undefined;
@@ -11330,7 +11308,30 @@ class WSConnectionFallback {
11330
11308
  }
11331
11309
  }
11332
11310
 
11333
- const version = '0.0.46';
11311
+ const version = '0.0.47';
11312
+
11313
+ const logger = getLogger(['location']);
11314
+ const HINT_URL = `https://hint.stream-io-video.com/`;
11315
+ const getLocationHint = (hintUrl = HINT_URL, timeout = 1500) => __awaiter(void 0, void 0, void 0, function* () {
11316
+ const abortController = new AbortController();
11317
+ const timeoutId = setTimeout(() => abortController.abort(), timeout);
11318
+ try {
11319
+ const response = yield fetch(HINT_URL, {
11320
+ method: 'HEAD',
11321
+ signal: abortController.signal,
11322
+ });
11323
+ const awsPop = response.headers.get('x-amz-cf-pop') || 'ERR';
11324
+ logger('debug', `Location header: ${awsPop}`);
11325
+ return awsPop.substring(0, 3); // AMS1-P2 -> AMS
11326
+ }
11327
+ catch (e) {
11328
+ logger('error', `Failed to get location hint from ${HINT_URL}`, e);
11329
+ return 'ERR';
11330
+ }
11331
+ finally {
11332
+ clearTimeout(timeoutId);
11333
+ }
11334
+ });
11334
11335
 
11335
11336
  class StreamClient {
11336
11337
  /**
@@ -11360,6 +11361,14 @@ class StreamClient {
11360
11361
  .replace('http', 'ws')
11361
11362
  .replace(':3030', ':8800');
11362
11363
  };
11364
+ this.getLocationHint = (hintUrl, timeout) => __awaiter(this, void 0, void 0, function* () {
11365
+ const hint = yield this.locationHint;
11366
+ if (!hint || hint === 'ERR') {
11367
+ this.locationHint = getLocationHint(hintUrl !== null && hintUrl !== void 0 ? hintUrl : this.options.locationHintUrl, timeout !== null && timeout !== void 0 ? timeout : this.options.locationHintTimeout);
11368
+ return this.locationHint;
11369
+ }
11370
+ return hint;
11371
+ });
11363
11372
  this._getConnectionID = () => { var _a, _b; return ((_a = this.wsConnection) === null || _a === void 0 ? void 0 : _a.connectionID) || ((_b = this.wsFallback) === null || _b === void 0 ? void 0 : _b.connectionID); };
11364
11373
  this._hasConnectionID = () => Boolean(this._getConnectionID());
11365
11374
  /**
@@ -11880,6 +11889,9 @@ class StreamClient {
11880
11889
  };
11881
11890
  this.browser = inputOptions.browser || typeof window !== 'undefined';
11882
11891
  this.node = !this.browser;
11892
+ if (this.browser) {
11893
+ this.locationHint = getLocationHint(options === null || options === void 0 ? void 0 : options.locationHintUrl, options === null || options === void 0 ? void 0 : options.locationHintTimeout);
11894
+ }
11883
11895
  this.options = Object.assign({ timeout: 5000, withCredentials: false, warmUp: false }, inputOptions);
11884
11896
  if (this.node && !this.options.httpsAgent) {
11885
11897
  this.options.httpsAgent = new https.Agent({