@stream-io/video-client 0.0.45 → 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 +14 -0
- package/dist/index.browser.es.js +58 -46
- package/dist/index.browser.es.js.map +1 -1
- package/dist/index.cjs.js +58 -46
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +58 -46
- package/dist/index.es.js.map +1 -1
- package/dist/src/coordinator/connection/client.d.ts +2 -0
- package/dist/src/coordinator/connection/location.d.ts +1 -0
- package/dist/src/coordinator/connection/types.d.ts +8 -0
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/coordinator/connection/client.ts +25 -0
- package/src/coordinator/connection/location.ts +26 -0
- package/src/coordinator/connection/types.ts +8 -0
- package/src/rtc/flows/join.ts +1 -23
package/dist/index.es.js
CHANGED
|
@@ -5668,7 +5668,7 @@ const logLevels = Object.freeze({
|
|
|
5668
5668
|
warn: 3,
|
|
5669
5669
|
error: 4,
|
|
5670
5670
|
});
|
|
5671
|
-
let logger$
|
|
5671
|
+
let logger$3;
|
|
5672
5672
|
let level = 'info';
|
|
5673
5673
|
const logToConsole = (logLevel, message, ...args) => {
|
|
5674
5674
|
let logMethod;
|
|
@@ -5692,7 +5692,7 @@ const logToConsole = (logLevel, message, ...args) => {
|
|
|
5692
5692
|
logMethod(message, ...args);
|
|
5693
5693
|
};
|
|
5694
5694
|
const setLogger = (l, lvl) => {
|
|
5695
|
-
logger$
|
|
5695
|
+
logger$3 = l;
|
|
5696
5696
|
if (lvl) {
|
|
5697
5697
|
setLogLevel(lvl);
|
|
5698
5698
|
}
|
|
@@ -5701,7 +5701,7 @@ const setLogLevel = (l) => {
|
|
|
5701
5701
|
level = l;
|
|
5702
5702
|
};
|
|
5703
5703
|
const getLogger = (withTags) => {
|
|
5704
|
-
const loggerMethod = logger$
|
|
5704
|
+
const loggerMethod = logger$3 || logToConsole;
|
|
5705
5705
|
const tags = (withTags || []).join(':');
|
|
5706
5706
|
const result = (logLevel, message, ...args) => {
|
|
5707
5707
|
if (logLevels[logLevel] >= logLevels[level]) {
|
|
@@ -6494,7 +6494,7 @@ class Publisher {
|
|
|
6494
6494
|
}
|
|
6495
6495
|
}
|
|
6496
6496
|
|
|
6497
|
-
const logger$
|
|
6497
|
+
const logger$2 = getLogger(['Subscriber']);
|
|
6498
6498
|
/**
|
|
6499
6499
|
* A wrapper around the `RTCPeerConnection` that handles the incoming
|
|
6500
6500
|
* media streams from the SFU.
|
|
@@ -6570,10 +6570,10 @@ class Subscriber {
|
|
|
6570
6570
|
// that are migrating to the new subscriber.
|
|
6571
6571
|
// Once all of them are available, we can close the previous subscriber.
|
|
6572
6572
|
const handleTrackMigration = (e) => {
|
|
6573
|
-
logger$
|
|
6573
|
+
logger$2('debug', `[Migration]: Migrated track: ${e.track.id}, ${e.track.kind}`);
|
|
6574
6574
|
trackIdsToMigrate.delete(e.track.id);
|
|
6575
6575
|
if (trackIdsToMigrate.size === 0) {
|
|
6576
|
-
logger$
|
|
6576
|
+
logger$2('debug', `[Migration]: Migration complete`);
|
|
6577
6577
|
pc.removeEventListener('track', handleTrackMigration);
|
|
6578
6578
|
cleanupMigration();
|
|
6579
6579
|
}
|
|
@@ -6601,7 +6601,7 @@ class Subscriber {
|
|
|
6601
6601
|
* Restarts the ICE connection and renegotiates with the SFU.
|
|
6602
6602
|
*/
|
|
6603
6603
|
this.restartIce = () => {
|
|
6604
|
-
logger$
|
|
6604
|
+
logger$2('debug', 'Restarting ICE connection');
|
|
6605
6605
|
this.pc.restartIce();
|
|
6606
6606
|
};
|
|
6607
6607
|
this.handleOnTrack = (e) => {
|
|
@@ -6609,19 +6609,19 @@ class Subscriber {
|
|
|
6609
6609
|
// example: `e3f6aaf8-b03d-4911-be36-83f47d37a76a:TRACK_TYPE_VIDEO`
|
|
6610
6610
|
const [trackId, trackType] = primaryStream.id.split(':');
|
|
6611
6611
|
const participantToUpdate = this.state.participants.find((p) => p.trackLookupPrefix === trackId);
|
|
6612
|
-
logger$
|
|
6612
|
+
logger$2('debug', `[onTrack]: Got remote ${trackType} track for userId: ${participantToUpdate === null || participantToUpdate === void 0 ? void 0 : participantToUpdate.userId}`, e.track.id, e.track);
|
|
6613
6613
|
if (!participantToUpdate) {
|
|
6614
|
-
logger$
|
|
6614
|
+
logger$2('error', `[onTrack]: Received track for unknown participant: ${trackId}`, e);
|
|
6615
6615
|
return;
|
|
6616
6616
|
}
|
|
6617
6617
|
e.track.addEventListener('mute', () => {
|
|
6618
|
-
logger$
|
|
6618
|
+
logger$2('info', `[onTrack]: Track muted: ${participantToUpdate.userId} ${trackType}:${trackId}`);
|
|
6619
6619
|
});
|
|
6620
6620
|
e.track.addEventListener('unmute', () => {
|
|
6621
|
-
logger$
|
|
6621
|
+
logger$2('info', `[onTrack]: Track unmuted: ${participantToUpdate.userId} ${trackType}:${trackId}`);
|
|
6622
6622
|
});
|
|
6623
6623
|
e.track.addEventListener('ended', () => {
|
|
6624
|
-
logger$
|
|
6624
|
+
logger$2('info', `[onTrack]: Track ended: ${participantToUpdate.userId} ${trackType}:${trackId}`);
|
|
6625
6625
|
});
|
|
6626
6626
|
const streamKindProp = {
|
|
6627
6627
|
TRACK_TYPE_AUDIO: 'audioStream',
|
|
@@ -6629,12 +6629,12 @@ class Subscriber {
|
|
|
6629
6629
|
TRACK_TYPE_SCREEN_SHARE: 'screenShareStream',
|
|
6630
6630
|
}[trackType];
|
|
6631
6631
|
if (!streamKindProp) {
|
|
6632
|
-
logger$
|
|
6632
|
+
logger$2('error', `Unknown track type: ${trackType}`);
|
|
6633
6633
|
return;
|
|
6634
6634
|
}
|
|
6635
6635
|
const previousStream = participantToUpdate[streamKindProp];
|
|
6636
6636
|
if (previousStream) {
|
|
6637
|
-
logger$
|
|
6637
|
+
logger$2('info', `[onTrack]: Cleaning up previous remote ${e.track.kind} tracks for userId: ${participantToUpdate.userId}`);
|
|
6638
6638
|
previousStream.getTracks().forEach((t) => {
|
|
6639
6639
|
t.stop();
|
|
6640
6640
|
previousStream.removeTrack(t);
|
|
@@ -6647,7 +6647,7 @@ class Subscriber {
|
|
|
6647
6647
|
this.onIceCandidate = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
6648
6648
|
const { candidate } = e;
|
|
6649
6649
|
if (!candidate) {
|
|
6650
|
-
logger$
|
|
6650
|
+
logger$2('debug', 'null ice candidate');
|
|
6651
6651
|
return;
|
|
6652
6652
|
}
|
|
6653
6653
|
yield this.sfuClient.iceTrickle({
|
|
@@ -6656,7 +6656,7 @@ class Subscriber {
|
|
|
6656
6656
|
});
|
|
6657
6657
|
});
|
|
6658
6658
|
this.negotiate = (subscriberOffer) => __awaiter(this, void 0, void 0, function* () {
|
|
6659
|
-
logger$
|
|
6659
|
+
logger$2('info', `Received subscriberOffer`, subscriberOffer);
|
|
6660
6660
|
yield this.pc.setRemoteDescription({
|
|
6661
6661
|
type: 'offer',
|
|
6662
6662
|
sdp: subscriberOffer.sdp,
|
|
@@ -6667,7 +6667,7 @@ class Subscriber {
|
|
|
6667
6667
|
yield this.pc.addIceCandidate(iceCandidate);
|
|
6668
6668
|
}
|
|
6669
6669
|
catch (e) {
|
|
6670
|
-
logger$
|
|
6670
|
+
logger$2('error', `ICE candidate error`, [e, candidate]);
|
|
6671
6671
|
}
|
|
6672
6672
|
}));
|
|
6673
6673
|
// apply ice candidates
|
|
@@ -6679,15 +6679,15 @@ class Subscriber {
|
|
|
6679
6679
|
});
|
|
6680
6680
|
});
|
|
6681
6681
|
this.onIceConnectionStateChange = () => {
|
|
6682
|
-
logger$
|
|
6682
|
+
logger$2('info', `ICE connection state changed`, this.pc.iceConnectionState);
|
|
6683
6683
|
};
|
|
6684
6684
|
this.onIceGatheringStateChange = () => {
|
|
6685
|
-
logger$
|
|
6685
|
+
logger$2('info', `ICE gathering state changed`, this.pc.iceGatheringState);
|
|
6686
6686
|
};
|
|
6687
6687
|
this.onIceCandidateError = (e) => {
|
|
6688
6688
|
const errorMessage = e instanceof RTCPeerConnectionIceErrorEvent &&
|
|
6689
6689
|
`${e.errorCode}: ${e.errorText}`;
|
|
6690
|
-
logger$
|
|
6690
|
+
logger$2('error', `ICE Candidate error`, errorMessage);
|
|
6691
6691
|
};
|
|
6692
6692
|
this.sfuClient = sfuClient;
|
|
6693
6693
|
this.dispatcher = dispatcher;
|
|
@@ -8016,7 +8016,7 @@ const watchCallGrantsUpdated = (state) => {
|
|
|
8016
8016
|
};
|
|
8017
8017
|
};
|
|
8018
8018
|
|
|
8019
|
-
const logger = getLogger(['events']);
|
|
8019
|
+
const logger$1 = getLogger(['events']);
|
|
8020
8020
|
/**
|
|
8021
8021
|
* An event responder which handles the `changePublishQuality` event.
|
|
8022
8022
|
*/
|
|
@@ -8081,7 +8081,7 @@ const watchSfuErrorReports = (dispatcher) => {
|
|
|
8081
8081
|
if (e.eventPayload.oneofKind !== 'error' || !e.eventPayload.error.error)
|
|
8082
8082
|
return;
|
|
8083
8083
|
const error = e.eventPayload.error.error;
|
|
8084
|
-
logger('error', 'SFU reported error', {
|
|
8084
|
+
logger$1('error', 'SFU reported error', {
|
|
8085
8085
|
code: ErrorCode[error.code],
|
|
8086
8086
|
message: error.message,
|
|
8087
8087
|
shouldRetry: error.shouldRetry,
|
|
@@ -8528,7 +8528,7 @@ const join = (httpClient, type, id, data) => __awaiter(void 0, void 0, void 0, f
|
|
|
8528
8528
|
};
|
|
8529
8529
|
});
|
|
8530
8530
|
const doJoin = (httpClient, type, id, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8531
|
-
const location = yield getLocationHint();
|
|
8531
|
+
const location = yield httpClient.getLocationHint();
|
|
8532
8532
|
const request = Object.assign(Object.assign({}, data), { location });
|
|
8533
8533
|
// FIXME OL: remove this once cascading is enabled by default
|
|
8534
8534
|
const cascadingModeParams = getCascadingModeParams();
|
|
@@ -8543,28 +8543,6 @@ const doJoin = (httpClient, type, id, data) => __awaiter(void 0, void 0, void 0,
|
|
|
8543
8543
|
}
|
|
8544
8544
|
return httpClient.post(`/call/${type}/${id}/join`, request);
|
|
8545
8545
|
});
|
|
8546
|
-
const getLocationHint = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
8547
|
-
const hintURL = `https://hint.stream-io-video.com/`;
|
|
8548
|
-
const abortController = new AbortController();
|
|
8549
|
-
const timeoutId = setTimeout(() => abortController.abort(), 1000);
|
|
8550
|
-
const logger = getLogger(['call']);
|
|
8551
|
-
try {
|
|
8552
|
-
const response = yield fetch(hintURL, {
|
|
8553
|
-
method: 'HEAD',
|
|
8554
|
-
signal: abortController.signal,
|
|
8555
|
-
});
|
|
8556
|
-
const awsPop = response.headers.get('x-amz-cf-pop') || 'ERR';
|
|
8557
|
-
logger === null || logger === void 0 ? void 0 : logger('info', `Location header: ${awsPop}`);
|
|
8558
|
-
return awsPop.substring(0, 3); // AMS1-P2 -> AMS
|
|
8559
|
-
}
|
|
8560
|
-
catch (e) {
|
|
8561
|
-
logger === null || logger === void 0 ? void 0 : logger('error', `Failed to get location hint from ${hintURL}`, e);
|
|
8562
|
-
return 'ERR';
|
|
8563
|
-
}
|
|
8564
|
-
finally {
|
|
8565
|
-
clearTimeout(timeoutId);
|
|
8566
|
-
}
|
|
8567
|
-
});
|
|
8568
8546
|
const toRtcConfiguration = (config) => {
|
|
8569
8547
|
if (!config || config.length === 0)
|
|
8570
8548
|
return undefined;
|
|
@@ -11334,7 +11312,30 @@ class WSConnectionFallback {
|
|
|
11334
11312
|
}
|
|
11335
11313
|
}
|
|
11336
11314
|
|
|
11337
|
-
const version = '0.0.
|
|
11315
|
+
const version = '0.0.47';
|
|
11316
|
+
|
|
11317
|
+
const logger = getLogger(['location']);
|
|
11318
|
+
const HINT_URL = `https://hint.stream-io-video.com/`;
|
|
11319
|
+
const getLocationHint = (hintUrl = HINT_URL, timeout = 1500) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11320
|
+
const abortController = new AbortController();
|
|
11321
|
+
const timeoutId = setTimeout(() => abortController.abort(), timeout);
|
|
11322
|
+
try {
|
|
11323
|
+
const response = yield fetch(HINT_URL, {
|
|
11324
|
+
method: 'HEAD',
|
|
11325
|
+
signal: abortController.signal,
|
|
11326
|
+
});
|
|
11327
|
+
const awsPop = response.headers.get('x-amz-cf-pop') || 'ERR';
|
|
11328
|
+
logger('debug', `Location header: ${awsPop}`);
|
|
11329
|
+
return awsPop.substring(0, 3); // AMS1-P2 -> AMS
|
|
11330
|
+
}
|
|
11331
|
+
catch (e) {
|
|
11332
|
+
logger('error', `Failed to get location hint from ${HINT_URL}`, e);
|
|
11333
|
+
return 'ERR';
|
|
11334
|
+
}
|
|
11335
|
+
finally {
|
|
11336
|
+
clearTimeout(timeoutId);
|
|
11337
|
+
}
|
|
11338
|
+
});
|
|
11338
11339
|
|
|
11339
11340
|
class StreamClient {
|
|
11340
11341
|
/**
|
|
@@ -11364,6 +11365,14 @@ class StreamClient {
|
|
|
11364
11365
|
.replace('http', 'ws')
|
|
11365
11366
|
.replace(':3030', ':8800');
|
|
11366
11367
|
};
|
|
11368
|
+
this.getLocationHint = (hintUrl, timeout) => __awaiter(this, void 0, void 0, function* () {
|
|
11369
|
+
const hint = yield this.locationHint;
|
|
11370
|
+
if (!hint || hint === 'ERR') {
|
|
11371
|
+
this.locationHint = getLocationHint(hintUrl !== null && hintUrl !== void 0 ? hintUrl : this.options.locationHintUrl, timeout !== null && timeout !== void 0 ? timeout : this.options.locationHintTimeout);
|
|
11372
|
+
return this.locationHint;
|
|
11373
|
+
}
|
|
11374
|
+
return hint;
|
|
11375
|
+
});
|
|
11367
11376
|
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); };
|
|
11368
11377
|
this._hasConnectionID = () => Boolean(this._getConnectionID());
|
|
11369
11378
|
/**
|
|
@@ -11884,6 +11893,9 @@ class StreamClient {
|
|
|
11884
11893
|
};
|
|
11885
11894
|
this.browser = inputOptions.browser || typeof window !== 'undefined';
|
|
11886
11895
|
this.node = !this.browser;
|
|
11896
|
+
if (this.browser) {
|
|
11897
|
+
this.locationHint = getLocationHint(options === null || options === void 0 ? void 0 : options.locationHintUrl, options === null || options === void 0 ? void 0 : options.locationHintTimeout);
|
|
11898
|
+
}
|
|
11887
11899
|
this.options = Object.assign({ timeout: 5000, withCredentials: false, warmUp: false }, inputOptions);
|
|
11888
11900
|
if (this.node && !this.options.httpsAgent) {
|
|
11889
11901
|
this.options.httpsAgent = new https.Agent({
|