@stream-io/video-client 0.5.1 → 0.5.2
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 +7 -0
- package/dist/index.browser.es.js +159 -159
- package/dist/index.browser.es.js.map +1 -1
- package/dist/index.cjs.js +158 -158
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +159 -159
- package/dist/index.es.js.map +1 -1
- package/dist/src/Call.d.ts +7 -2
- package/dist/src/store/stateStore.d.ts +1 -1
- package/package.json +1 -1
- package/src/Call.ts +25 -41
- package/src/__tests__/server-side/call.test.ts +5 -1
- package/src/rtc/Publisher.ts +3 -19
- package/src/store/stateStore.ts +9 -6
package/dist/index.es.js
CHANGED
|
@@ -4,7 +4,7 @@ import { ServiceType, stackIntercept } from '@protobuf-ts/runtime-rpc';
|
|
|
4
4
|
import axios, { AxiosHeaders } from 'axios';
|
|
5
5
|
export { AxiosError } from 'axios';
|
|
6
6
|
import { TwirpFetchTransport } from '@protobuf-ts/twirp-transport';
|
|
7
|
-
import { ReplaySubject, combineLatest, BehaviorSubject, map as map$1, shareReplay, distinctUntilChanged, takeWhile, distinctUntilKeyChanged, merge, from, Observable, debounceTime, concatMap, pairwise, of, filter,
|
|
7
|
+
import { ReplaySubject, combineLatest, BehaviorSubject, map as map$1, shareReplay, distinctUntilChanged, takeWhile, distinctUntilKeyChanged, merge, from, Observable, debounceTime, concatMap, pairwise, of, filter, debounce, timer } from 'rxjs';
|
|
8
8
|
import * as SDP from 'sdp-transform';
|
|
9
9
|
import { UAParser } from 'ua-parser-js';
|
|
10
10
|
import WebSocket from 'isomorphic-ws';
|
|
@@ -6495,7 +6495,7 @@ class Publisher {
|
|
|
6495
6495
|
*/
|
|
6496
6496
|
const handleTrackEnded = async () => {
|
|
6497
6497
|
logger$3('info', `Track ${TrackType[trackType]} has ended, notifying the SFU`);
|
|
6498
|
-
await this.notifyTrackMuteStateChanged(mediaStream,
|
|
6498
|
+
await this.notifyTrackMuteStateChanged(mediaStream, trackType, true);
|
|
6499
6499
|
// clean-up, this event listener needs to run only once.
|
|
6500
6500
|
track.removeEventListener('ended', handleTrackEnded);
|
|
6501
6501
|
};
|
|
@@ -6551,7 +6551,7 @@ class Publisher {
|
|
|
6551
6551
|
}
|
|
6552
6552
|
await transceiver.sender.replaceTrack(track);
|
|
6553
6553
|
}
|
|
6554
|
-
await this.notifyTrackMuteStateChanged(mediaStream,
|
|
6554
|
+
await this.notifyTrackMuteStateChanged(mediaStream, trackType, false);
|
|
6555
6555
|
};
|
|
6556
6556
|
/**
|
|
6557
6557
|
* Stops publishing the given track type to the SFU, if it is currently being published.
|
|
@@ -6573,7 +6573,7 @@ class Publisher {
|
|
|
6573
6573
|
: (transceiver.sender.track.enabled = false);
|
|
6574
6574
|
// We don't need to notify SFU if unpublishing in response to remote soft mute
|
|
6575
6575
|
if (this.state.localParticipant?.publishedTracks.includes(trackType)) {
|
|
6576
|
-
await this.notifyTrackMuteStateChanged(undefined,
|
|
6576
|
+
await this.notifyTrackMuteStateChanged(undefined, trackType, true);
|
|
6577
6577
|
}
|
|
6578
6578
|
}
|
|
6579
6579
|
};
|
|
@@ -6605,7 +6605,7 @@ class Publisher {
|
|
|
6605
6605
|
}
|
|
6606
6606
|
return false;
|
|
6607
6607
|
};
|
|
6608
|
-
this.notifyTrackMuteStateChanged = async (mediaStream,
|
|
6608
|
+
this.notifyTrackMuteStateChanged = async (mediaStream, trackType, isMuted) => {
|
|
6609
6609
|
await this.sfuClient.updateMuteState(trackType, isMuted);
|
|
6610
6610
|
const audioOrVideoOrScreenShareStream = trackTypeToParticipantStreamKey(trackType);
|
|
6611
6611
|
if (isMuted) {
|
|
@@ -7649,131 +7649,6 @@ var rxUtils = /*#__PURE__*/Object.freeze({
|
|
|
7649
7649
|
setCurrentValue: setCurrentValue
|
|
7650
7650
|
});
|
|
7651
7651
|
|
|
7652
|
-
class StreamVideoWriteableStateStore {
|
|
7653
|
-
constructor() {
|
|
7654
|
-
/**
|
|
7655
|
-
* A store keeping data of a successfully connected user over WS to the coordinator server.
|
|
7656
|
-
*/
|
|
7657
|
-
this.connectedUserSubject = new BehaviorSubject(undefined);
|
|
7658
|
-
/**
|
|
7659
|
-
* A list of {@link Call} objects created/tracked by this client.
|
|
7660
|
-
*/
|
|
7661
|
-
this.callsSubject = new BehaviorSubject([]);
|
|
7662
|
-
/**
|
|
7663
|
-
* Gets the current value of an observable, or undefined if the observable has
|
|
7664
|
-
* not emitted a value yet.
|
|
7665
|
-
*
|
|
7666
|
-
* @param observable$ the observable to get the value from.
|
|
7667
|
-
*/
|
|
7668
|
-
this.getCurrentValue = getCurrentValue;
|
|
7669
|
-
/**
|
|
7670
|
-
* Updates the value of the provided Subject.
|
|
7671
|
-
* An `update` can either be a new value or a function which takes
|
|
7672
|
-
* the current value and returns a new value.
|
|
7673
|
-
*
|
|
7674
|
-
* @param subject the subject to update.
|
|
7675
|
-
* @param update the update to apply to the subject.
|
|
7676
|
-
* @return the updated value.
|
|
7677
|
-
*/
|
|
7678
|
-
this.setCurrentValue = setCurrentValue;
|
|
7679
|
-
/**
|
|
7680
|
-
* Sets the currently connected user.
|
|
7681
|
-
*
|
|
7682
|
-
* @internal
|
|
7683
|
-
* @param user the user to set as connected.
|
|
7684
|
-
*/
|
|
7685
|
-
this.setConnectedUser = (user) => {
|
|
7686
|
-
return this.setCurrentValue(this.connectedUserSubject, user);
|
|
7687
|
-
};
|
|
7688
|
-
/**
|
|
7689
|
-
* Sets the list of {@link Call} objects created/tracked by this client.
|
|
7690
|
-
* @param calls
|
|
7691
|
-
*/
|
|
7692
|
-
this.setCalls = (calls) => {
|
|
7693
|
-
return this.setCurrentValue(this.callsSubject, calls);
|
|
7694
|
-
};
|
|
7695
|
-
/**
|
|
7696
|
-
* Adds a {@link Call} object to the list of {@link Call} objects created/tracked by this client.
|
|
7697
|
-
*
|
|
7698
|
-
* @param call the call to add.
|
|
7699
|
-
*/
|
|
7700
|
-
this.registerCall = (call) => {
|
|
7701
|
-
if (!this.calls.find((c) => c.cid === call.cid)) {
|
|
7702
|
-
this.setCalls((calls) => [...calls, call]);
|
|
7703
|
-
}
|
|
7704
|
-
};
|
|
7705
|
-
/**
|
|
7706
|
-
* Removes a {@link Call} object from the list of {@link Call} objects created/tracked by this client.
|
|
7707
|
-
*
|
|
7708
|
-
* @param call the call to remove
|
|
7709
|
-
*/
|
|
7710
|
-
this.unregisterCall = (call) => {
|
|
7711
|
-
return this.setCalls((calls) => calls.filter((c) => c !== call));
|
|
7712
|
-
};
|
|
7713
|
-
/**
|
|
7714
|
-
* Finds a {@link Call} object in the list of {@link Call} objects created/tracked by this client.
|
|
7715
|
-
*
|
|
7716
|
-
* @param type the type of call to find.
|
|
7717
|
-
* @param id the id of the call to find.
|
|
7718
|
-
*/
|
|
7719
|
-
this.findCall = (type, id) => {
|
|
7720
|
-
return this.calls.find((c) => c.type === type && c.id === id);
|
|
7721
|
-
};
|
|
7722
|
-
this.connectedUserSubject.subscribe(async (user) => {
|
|
7723
|
-
// leave all calls when the user disconnects.
|
|
7724
|
-
if (!user) {
|
|
7725
|
-
for (const call of this.calls) {
|
|
7726
|
-
getLogger(['client-state'])('info', `User disconnected, leaving call: ${call.cid}`);
|
|
7727
|
-
await call.leave();
|
|
7728
|
-
}
|
|
7729
|
-
}
|
|
7730
|
-
});
|
|
7731
|
-
}
|
|
7732
|
-
/**
|
|
7733
|
-
* The currently connected user.
|
|
7734
|
-
*/
|
|
7735
|
-
get connectedUser() {
|
|
7736
|
-
return this.getCurrentValue(this.connectedUserSubject);
|
|
7737
|
-
}
|
|
7738
|
-
/**
|
|
7739
|
-
* A list of {@link Call} objects created/tracked by this client.
|
|
7740
|
-
*/
|
|
7741
|
-
get calls() {
|
|
7742
|
-
return this.getCurrentValue(this.callsSubject);
|
|
7743
|
-
}
|
|
7744
|
-
}
|
|
7745
|
-
/**
|
|
7746
|
-
* A reactive store that exposes state variables in a reactive manner.
|
|
7747
|
-
* You can subscribe to changes of the different state variables.
|
|
7748
|
-
* This central store contains all the state variables related to [`StreamVideoClient`](./StreamVideClient.md) and [`Call`](./Call.md).
|
|
7749
|
-
*/
|
|
7750
|
-
class StreamVideoReadOnlyStateStore {
|
|
7751
|
-
constructor(store) {
|
|
7752
|
-
/**
|
|
7753
|
-
* This method allows you the get the current value of a state variable.
|
|
7754
|
-
*
|
|
7755
|
-
* @param observable the observable to get the current value of.
|
|
7756
|
-
* @returns the current value of the observable.
|
|
7757
|
-
*/
|
|
7758
|
-
this.getCurrentValue = getCurrentValue;
|
|
7759
|
-
// convert and expose subjects as observables
|
|
7760
|
-
this.connectedUser$ = store.connectedUserSubject.asObservable();
|
|
7761
|
-
this.calls$ = store.callsSubject.asObservable();
|
|
7762
|
-
}
|
|
7763
|
-
/**
|
|
7764
|
-
* The current user connected over WS to the backend.
|
|
7765
|
-
*/
|
|
7766
|
-
get connectedUser() {
|
|
7767
|
-
return getCurrentValue(this.connectedUser$);
|
|
7768
|
-
}
|
|
7769
|
-
/**
|
|
7770
|
-
* A list of {@link Call} objects created/tracked by this client.
|
|
7771
|
-
*/
|
|
7772
|
-
get calls() {
|
|
7773
|
-
return getCurrentValue(this.calls$);
|
|
7774
|
-
}
|
|
7775
|
-
}
|
|
7776
|
-
|
|
7777
7652
|
/**
|
|
7778
7653
|
* Creates a new combined {@link Comparator<T>} which sorts items by the given comparators.
|
|
7779
7654
|
* The comparators are applied in the order they are given (left -> right).
|
|
@@ -8732,6 +8607,136 @@ class CallState {
|
|
|
8732
8607
|
}
|
|
8733
8608
|
}
|
|
8734
8609
|
|
|
8610
|
+
class StreamVideoWriteableStateStore {
|
|
8611
|
+
constructor() {
|
|
8612
|
+
/**
|
|
8613
|
+
* A store keeping data of a successfully connected user over WS to the coordinator server.
|
|
8614
|
+
*/
|
|
8615
|
+
this.connectedUserSubject = new BehaviorSubject(undefined);
|
|
8616
|
+
/**
|
|
8617
|
+
* A list of {@link Call} objects created/tracked by this client.
|
|
8618
|
+
*/
|
|
8619
|
+
this.callsSubject = new BehaviorSubject([]);
|
|
8620
|
+
/**
|
|
8621
|
+
* Gets the current value of an observable, or undefined if the observable has
|
|
8622
|
+
* not emitted a value yet.
|
|
8623
|
+
*
|
|
8624
|
+
* @param observable$ the observable to get the value from.
|
|
8625
|
+
*/
|
|
8626
|
+
this.getCurrentValue = getCurrentValue;
|
|
8627
|
+
/**
|
|
8628
|
+
* Updates the value of the provided Subject.
|
|
8629
|
+
* An `update` can either be a new value or a function which takes
|
|
8630
|
+
* the current value and returns a new value.
|
|
8631
|
+
*
|
|
8632
|
+
* @param subject the subject to update.
|
|
8633
|
+
* @param update the update to apply to the subject.
|
|
8634
|
+
* @return the updated value.
|
|
8635
|
+
*/
|
|
8636
|
+
this.setCurrentValue = setCurrentValue;
|
|
8637
|
+
/**
|
|
8638
|
+
* Sets the currently connected user.
|
|
8639
|
+
*
|
|
8640
|
+
* @internal
|
|
8641
|
+
* @param user the user to set as connected.
|
|
8642
|
+
*/
|
|
8643
|
+
this.setConnectedUser = (user) => {
|
|
8644
|
+
return this.setCurrentValue(this.connectedUserSubject, user);
|
|
8645
|
+
};
|
|
8646
|
+
/**
|
|
8647
|
+
* Sets the list of {@link Call} objects created/tracked by this client.
|
|
8648
|
+
* @param calls
|
|
8649
|
+
*/
|
|
8650
|
+
this.setCalls = (calls) => {
|
|
8651
|
+
return this.setCurrentValue(this.callsSubject, calls);
|
|
8652
|
+
};
|
|
8653
|
+
/**
|
|
8654
|
+
* Adds a {@link Call} object to the list of {@link Call} objects created/tracked by this client.
|
|
8655
|
+
*
|
|
8656
|
+
* @param call the call to add.
|
|
8657
|
+
*/
|
|
8658
|
+
this.registerCall = (call) => {
|
|
8659
|
+
if (!this.calls.find((c) => c.cid === call.cid)) {
|
|
8660
|
+
this.setCalls((calls) => [...calls, call]);
|
|
8661
|
+
}
|
|
8662
|
+
};
|
|
8663
|
+
/**
|
|
8664
|
+
* Removes a {@link Call} object from the list of {@link Call} objects created/tracked by this client.
|
|
8665
|
+
*
|
|
8666
|
+
* @param call the call to remove
|
|
8667
|
+
*/
|
|
8668
|
+
this.unregisterCall = (call) => {
|
|
8669
|
+
return this.setCalls((calls) => calls.filter((c) => c !== call));
|
|
8670
|
+
};
|
|
8671
|
+
/**
|
|
8672
|
+
* Finds a {@link Call} object in the list of {@link Call} objects created/tracked by this client.
|
|
8673
|
+
*
|
|
8674
|
+
* @param type the type of call to find.
|
|
8675
|
+
* @param id the id of the call to find.
|
|
8676
|
+
*/
|
|
8677
|
+
this.findCall = (type, id) => {
|
|
8678
|
+
return this.calls.find((c) => c.type === type && c.id === id);
|
|
8679
|
+
};
|
|
8680
|
+
this.connectedUserSubject.subscribe(async (user) => {
|
|
8681
|
+
// leave all calls when the user disconnects.
|
|
8682
|
+
if (!user) {
|
|
8683
|
+
const logger = getLogger(['client-state']);
|
|
8684
|
+
for (const call of this.calls) {
|
|
8685
|
+
if (call.state.callingState === CallingState.LEFT)
|
|
8686
|
+
continue;
|
|
8687
|
+
logger('info', `User disconnected, leaving call: ${call.cid}`);
|
|
8688
|
+
await call.leave().catch((err) => {
|
|
8689
|
+
logger('error', `Error leaving call: ${call.cid}`, err);
|
|
8690
|
+
});
|
|
8691
|
+
}
|
|
8692
|
+
}
|
|
8693
|
+
});
|
|
8694
|
+
}
|
|
8695
|
+
/**
|
|
8696
|
+
* The currently connected user.
|
|
8697
|
+
*/
|
|
8698
|
+
get connectedUser() {
|
|
8699
|
+
return this.getCurrentValue(this.connectedUserSubject);
|
|
8700
|
+
}
|
|
8701
|
+
/**
|
|
8702
|
+
* A list of {@link Call} objects created/tracked by this client.
|
|
8703
|
+
*/
|
|
8704
|
+
get calls() {
|
|
8705
|
+
return this.getCurrentValue(this.callsSubject);
|
|
8706
|
+
}
|
|
8707
|
+
}
|
|
8708
|
+
/**
|
|
8709
|
+
* A reactive store that exposes state variables in a reactive manner.
|
|
8710
|
+
* You can subscribe to changes of the different state variables.
|
|
8711
|
+
* This central store contains all the state variables related to [`StreamVideoClient`](./StreamVideClient.md) and [`Call`](./Call.md).
|
|
8712
|
+
*/
|
|
8713
|
+
class StreamVideoReadOnlyStateStore {
|
|
8714
|
+
constructor(store) {
|
|
8715
|
+
/**
|
|
8716
|
+
* This method allows you the get the current value of a state variable.
|
|
8717
|
+
*
|
|
8718
|
+
* @param observable the observable to get the current value of.
|
|
8719
|
+
* @returns the current value of the observable.
|
|
8720
|
+
*/
|
|
8721
|
+
this.getCurrentValue = getCurrentValue;
|
|
8722
|
+
// convert and expose subjects as observables
|
|
8723
|
+
this.connectedUser$ = store.connectedUserSubject.asObservable();
|
|
8724
|
+
this.calls$ = store.callsSubject.asObservable();
|
|
8725
|
+
}
|
|
8726
|
+
/**
|
|
8727
|
+
* The current user connected over WS to the backend.
|
|
8728
|
+
*/
|
|
8729
|
+
get connectedUser() {
|
|
8730
|
+
return getCurrentValue(this.connectedUser$);
|
|
8731
|
+
}
|
|
8732
|
+
/**
|
|
8733
|
+
* A list of {@link Call} objects created/tracked by this client.
|
|
8734
|
+
*/
|
|
8735
|
+
get calls() {
|
|
8736
|
+
return getCurrentValue(this.calls$);
|
|
8737
|
+
}
|
|
8738
|
+
}
|
|
8739
|
+
|
|
8735
8740
|
/**
|
|
8736
8741
|
* Event handler that watched the delivery of `call.accepted`.
|
|
8737
8742
|
* Once the event is received, the call is joined.
|
|
@@ -11918,9 +11923,10 @@ class Call {
|
|
|
11918
11923
|
return this.state.setSortParticipantsBy(criteria);
|
|
11919
11924
|
};
|
|
11920
11925
|
/**
|
|
11926
|
+
* Updates the list of video layers to publish.
|
|
11927
|
+
*
|
|
11921
11928
|
* @internal
|
|
11922
|
-
* @param
|
|
11923
|
-
* @returns
|
|
11929
|
+
* @param enabledLayers the list of layers to enable.
|
|
11924
11930
|
*/
|
|
11925
11931
|
this.updatePublishQuality = async (enabledLayers) => {
|
|
11926
11932
|
return this.publisher?.updateVideoPublishQuality(enabledLayers);
|
|
@@ -12192,35 +12198,29 @@ class Call {
|
|
|
12192
12198
|
this.updateCallMembers = async (data) => {
|
|
12193
12199
|
return this.streamClient.post(`${this.streamClientBasePath}/members`, data);
|
|
12194
12200
|
};
|
|
12201
|
+
/**
|
|
12202
|
+
* Schedules an auto-drop timeout based on the call settings.
|
|
12203
|
+
* Applicable only for ringing calls.
|
|
12204
|
+
*/
|
|
12195
12205
|
this.scheduleAutoDrop = () => {
|
|
12196
|
-
|
|
12197
|
-
|
|
12198
|
-
|
|
12199
|
-
.pipe(pairwise(), tap(([prevSettings, currentSettings]) => {
|
|
12200
|
-
if (!currentSettings || !this.clientStore.connectedUser)
|
|
12206
|
+
clearTimeout(this.dropTimeout);
|
|
12207
|
+
this.leaveCallHooks.add(createSubscription(this.state.settings$, (settings) => {
|
|
12208
|
+
if (!settings)
|
|
12201
12209
|
return;
|
|
12202
|
-
|
|
12203
|
-
|
|
12204
|
-
? [
|
|
12205
|
-
prevSettings?.ring.auto_cancel_timeout_ms,
|
|
12206
|
-
currentSettings.ring.auto_cancel_timeout_ms,
|
|
12207
|
-
]
|
|
12208
|
-
: [
|
|
12209
|
-
prevSettings?.ring.incoming_call_timeout_ms,
|
|
12210
|
-
currentSettings.ring.incoming_call_timeout_ms,
|
|
12211
|
-
];
|
|
12212
|
-
if (typeof timeoutMs === 'undefined' ||
|
|
12213
|
-
timeoutMs === prevTimeoutMs ||
|
|
12214
|
-
timeoutMs === 0)
|
|
12210
|
+
// ignore if the call is not ringing
|
|
12211
|
+
if (this.state.callingState !== CallingState.RINGING)
|
|
12215
12212
|
return;
|
|
12216
|
-
|
|
12217
|
-
|
|
12218
|
-
|
|
12219
|
-
|
|
12220
|
-
.
|
|
12221
|
-
|
|
12222
|
-
|
|
12223
|
-
|
|
12213
|
+
const timeoutInMs = settings.ring.auto_cancel_timeout_ms;
|
|
12214
|
+
// 0 means no auto-drop
|
|
12215
|
+
if (timeoutInMs <= 0)
|
|
12216
|
+
return;
|
|
12217
|
+
clearTimeout(this.dropTimeout);
|
|
12218
|
+
this.dropTimeout = setTimeout(() => {
|
|
12219
|
+
this.leave().catch((err) => {
|
|
12220
|
+
this.logger('error', 'Failed to drop call', err);
|
|
12221
|
+
});
|
|
12222
|
+
}, timeoutInMs);
|
|
12223
|
+
}));
|
|
12224
12224
|
};
|
|
12225
12225
|
/**
|
|
12226
12226
|
* Retrieves the list of recordings for the current call or call session.
|
|
@@ -14145,7 +14145,7 @@ class StreamClient {
|
|
|
14145
14145
|
});
|
|
14146
14146
|
};
|
|
14147
14147
|
this.getUserAgent = () => {
|
|
14148
|
-
const version = "0.5.
|
|
14148
|
+
const version = "0.5.2" ;
|
|
14149
14149
|
return (this.userAgent ||
|
|
14150
14150
|
`stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${version}`);
|
|
14151
14151
|
};
|