@stream-io/video-client 0.0.1-alpha.7
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/LICENSE +219 -0
- package/README.md +14 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +14663 -0
- package/dist/index.js.map +1 -0
- package/dist/src/Batcher.d.ts +12 -0
- package/dist/src/CallDropScheduler.d.ts +44 -0
- package/dist/src/StreamSfuClient.d.ts +25 -0
- package/dist/src/StreamVideoClient.d.ts +145 -0
- package/dist/src/__tests__/StreamVideoClient.test.d.ts +1 -0
- package/dist/src/config/defaultConfigs.d.ts +2 -0
- package/dist/src/config/types.d.ts +29 -0
- package/dist/src/coordinator/StreamCoordinatorClient.d.ts +19 -0
- package/dist/src/coordinator/connection/base64.d.ts +2 -0
- package/dist/src/coordinator/connection/client.d.ts +174 -0
- package/dist/src/coordinator/connection/connection.d.ts +139 -0
- package/dist/src/coordinator/connection/connection_fallback.d.ts +38 -0
- package/dist/src/coordinator/connection/errors.d.ts +16 -0
- package/dist/src/coordinator/connection/events.d.ts +7 -0
- package/dist/src/coordinator/connection/insights.d.ts +58 -0
- package/dist/src/coordinator/connection/signing.d.ts +30 -0
- package/dist/src/coordinator/connection/token_manager.d.ts +39 -0
- package/dist/src/coordinator/connection/types.d.ts +96 -0
- package/dist/src/coordinator/connection/utils.d.ts +25 -0
- package/dist/src/devices.d.ts +79 -0
- package/dist/src/events/call.d.ts +26 -0
- package/dist/src/events/internal.d.ts +8 -0
- package/dist/src/events/participant.d.ts +21 -0
- package/dist/src/events/speaker.d.ts +10 -0
- package/dist/src/gen/coordinator/index.d.ts +1664 -0
- package/dist/src/gen/google/protobuf/descriptor.d.ts +1650 -0
- package/dist/src/gen/google/protobuf/duration.d.ts +113 -0
- package/dist/src/gen/google/protobuf/struct.d.ts +184 -0
- package/dist/src/gen/google/protobuf/timestamp.d.ts +158 -0
- package/dist/src/gen/video/coordinator/broadcast_v1/broadcast.d.ts +66 -0
- package/dist/src/gen/video/coordinator/call_v1/call.d.ts +254 -0
- package/dist/src/gen/video/coordinator/client_v1_rpc/client_rpc.client.d.ts +351 -0
- package/dist/src/gen/video/coordinator/client_v1_rpc/client_rpc.d.ts +1488 -0
- package/dist/src/gen/video/coordinator/client_v1_rpc/envelopes.d.ts +143 -0
- package/dist/src/gen/video/coordinator/client_v1_rpc/websocket.d.ts +292 -0
- package/dist/src/gen/video/coordinator/edge_v1/edge.d.ts +183 -0
- package/dist/src/gen/video/coordinator/event_v1/event.d.ts +411 -0
- package/dist/src/gen/video/coordinator/geofence_v1/geofence.d.ts +63 -0
- package/dist/src/gen/video/coordinator/member_v1/member.d.ts +59 -0
- package/dist/src/gen/video/coordinator/participant_v1/participant.d.ts +103 -0
- package/dist/src/gen/video/coordinator/push_v1/push.d.ts +240 -0
- package/dist/src/gen/video/coordinator/stat_v1/stat.d.ts +308 -0
- package/dist/src/gen/video/coordinator/user_v1/user.d.ts +112 -0
- package/dist/src/gen/video/coordinator/utils_v1/utils.d.ts +47 -0
- package/dist/src/gen/video/sfu/event/events.d.ts +736 -0
- package/dist/src/gen/video/sfu/models/models.d.ts +460 -0
- package/dist/src/gen/video/sfu/signal_rpc/signal.client.d.ts +89 -0
- package/dist/src/gen/video/sfu/signal_rpc/signal.d.ts +320 -0
- package/dist/src/helpers/browsers.d.ts +8 -0
- package/dist/src/helpers/sound-detector.d.ts +34 -0
- package/dist/src/rpc/createClient.d.ts +10 -0
- package/dist/src/rpc/index.d.ts +2 -0
- package/dist/src/rpc/latency.d.ts +9 -0
- package/dist/src/rtc/Call.d.ts +180 -0
- package/dist/src/rtc/CallMetadata.d.ts +9 -0
- package/dist/src/rtc/Dispatcher.d.ts +9 -0
- package/dist/src/rtc/IceTrickleBuffer.d.ts +11 -0
- package/dist/src/rtc/callEventHandlers.d.ts +5 -0
- package/dist/src/rtc/codecs.d.ts +2 -0
- package/dist/src/rtc/helpers/iceCandidate.d.ts +2 -0
- package/dist/src/rtc/helpers/tracks.d.ts +3 -0
- package/dist/src/rtc/publisher.d.ts +53 -0
- package/dist/src/rtc/signal.d.ts +5 -0
- package/dist/src/rtc/subscriber.d.ts +7 -0
- package/dist/src/rtc/types.d.ts +84 -0
- package/dist/src/rtc/videoLayers.d.ts +17 -0
- package/dist/src/stats/coordinator-stats-reporter.d.ts +10 -0
- package/dist/src/stats/state-store-stats-reporter.d.ts +57 -0
- package/dist/src/stats/types.d.ts +42 -0
- package/dist/src/store/index.d.ts +2 -0
- package/dist/src/store/rxUtils.d.ts +18 -0
- package/dist/src/store/stateStore.d.ts +182 -0
- package/generate-openapi.sh +32 -0
- package/index.ts +30 -0
- package/openapitools.json +7 -0
- package/package.json +54 -0
- package/rollup.config.mjs +48 -0
- package/src/Batcher.ts +43 -0
- package/src/CallDropScheduler.ts +192 -0
- package/src/StreamSfuClient.ts +185 -0
- package/src/StreamVideoClient.ts +487 -0
- package/src/__tests__/StreamVideoClient.test.ts +83 -0
- package/src/config/defaultConfigs.ts +15 -0
- package/src/config/types.ts +30 -0
- package/src/coordinator/StreamCoordinatorClient.ts +111 -0
- package/src/coordinator/connection/base64.ts +80 -0
- package/src/coordinator/connection/client.ts +815 -0
- package/src/coordinator/connection/connection.ts +750 -0
- package/src/coordinator/connection/connection_fallback.ts +239 -0
- package/src/coordinator/connection/errors.ts +70 -0
- package/src/coordinator/connection/events.ts +10 -0
- package/src/coordinator/connection/insights.ts +88 -0
- package/src/coordinator/connection/signing.ts +104 -0
- package/src/coordinator/connection/token_manager.ts +160 -0
- package/src/coordinator/connection/types.ts +120 -0
- package/src/coordinator/connection/utils.ts +148 -0
- package/src/devices.ts +266 -0
- package/src/events/call.ts +166 -0
- package/src/events/internal.ts +47 -0
- package/src/events/participant.ts +97 -0
- package/src/events/speaker.ts +62 -0
- package/src/gen/coordinator/index.ts +1653 -0
- package/src/gen/google/protobuf/descriptor.ts +3466 -0
- package/src/gen/google/protobuf/duration.ts +232 -0
- package/src/gen/google/protobuf/struct.ts +481 -0
- package/src/gen/google/protobuf/timestamp.ts +291 -0
- package/src/gen/video/coordinator/broadcast_v1/broadcast.ts +154 -0
- package/src/gen/video/coordinator/call_v1/call.ts +651 -0
- package/src/gen/video/coordinator/client_v1_rpc/client_rpc.client.ts +463 -0
- package/src/gen/video/coordinator/client_v1_rpc/client_rpc.ts +3819 -0
- package/src/gen/video/coordinator/client_v1_rpc/envelopes.ts +424 -0
- package/src/gen/video/coordinator/client_v1_rpc/websocket.ts +719 -0
- package/src/gen/video/coordinator/edge_v1/edge.ts +532 -0
- package/src/gen/video/coordinator/event_v1/event.ts +1171 -0
- package/src/gen/video/coordinator/geofence_v1/geofence.ts +128 -0
- package/src/gen/video/coordinator/member_v1/member.ts +138 -0
- package/src/gen/video/coordinator/participant_v1/participant.ts +261 -0
- package/src/gen/video/coordinator/push_v1/push.ts +651 -0
- package/src/gen/video/coordinator/stat_v1/stat.ts +656 -0
- package/src/gen/video/coordinator/user_v1/user.ts +277 -0
- package/src/gen/video/coordinator/utils_v1/utils.ts +98 -0
- package/src/gen/video/sfu/event/events.ts +1962 -0
- package/src/gen/video/sfu/models/models.ts +1062 -0
- package/src/gen/video/sfu/signal_rpc/signal.client.ts +108 -0
- package/src/gen/video/sfu/signal_rpc/signal.ts +906 -0
- package/src/helpers/browsers.ts +13 -0
- package/src/helpers/sound-detector.ts +85 -0
- package/src/rpc/createClient.ts +50 -0
- package/src/rpc/index.ts +2 -0
- package/src/rpc/latency.ts +43 -0
- package/src/rtc/Call.ts +585 -0
- package/src/rtc/CallMetadata.ts +24 -0
- package/src/rtc/Dispatcher.ts +46 -0
- package/src/rtc/IceTrickleBuffer.ts +21 -0
- package/src/rtc/callEventHandlers.ts +37 -0
- package/src/rtc/codecs.ts +61 -0
- package/src/rtc/helpers/iceCandidate.ts +16 -0
- package/src/rtc/helpers/tracks.ts +18 -0
- package/src/rtc/publisher.ts +305 -0
- package/src/rtc/signal.ts +34 -0
- package/src/rtc/subscriber.ts +85 -0
- package/src/rtc/types.ts +105 -0
- package/src/rtc/videoLayers.ts +103 -0
- package/src/stats/coordinator-stats-reporter.ts +167 -0
- package/src/stats/state-store-stats-reporter.ts +364 -0
- package/src/stats/types.ts +46 -0
- package/src/store/index.ts +2 -0
- package/src/store/rxUtils.ts +42 -0
- package/src/store/stateStore.ts +341 -0
- package/tsconfig.json +25 -0
- package/typedoc.json +11 -0
- package/vite.config.ts +11 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { StreamSfuClient } from '../StreamSfuClient';
|
|
2
|
+
import { TrackType } from '../gen/video/sfu/models/models';
|
|
3
|
+
import { PublishOptions } from './types';
|
|
4
|
+
export type PublisherOpts = {
|
|
5
|
+
rpcClient: StreamSfuClient;
|
|
6
|
+
connectionConfig?: RTCConfiguration;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
* The `Publisher` is responsible for publishing/unpublishing media streams to/from the SFU
|
|
11
|
+
*/
|
|
12
|
+
export declare class Publisher {
|
|
13
|
+
private readonly publisher;
|
|
14
|
+
private readonly rpcClient;
|
|
15
|
+
private readonly transceiverRegistry;
|
|
16
|
+
private readonly trackKindRegistry;
|
|
17
|
+
constructor({ connectionConfig, rpcClient }: PublisherOpts);
|
|
18
|
+
/**
|
|
19
|
+
* Starts publishing the given track of the given media stream.
|
|
20
|
+
*
|
|
21
|
+
* Consecutive calls to this method will replace the stream.
|
|
22
|
+
* The previous stream will be stopped.
|
|
23
|
+
* @param mediaStream
|
|
24
|
+
* @param track
|
|
25
|
+
* @param trackType
|
|
26
|
+
* @param opts
|
|
27
|
+
*/
|
|
28
|
+
publishStream: (mediaStream: MediaStream, track: MediaStreamTrack, trackType: TrackType, opts?: PublishOptions) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Stops publishing the given track type to the SFU, if it is currently being published.
|
|
31
|
+
* Underlying track will be stopped and removed from the publisher.
|
|
32
|
+
* @param trackType
|
|
33
|
+
* @returns `true` if track with the given track type was found, otherwise `false`
|
|
34
|
+
*/
|
|
35
|
+
unpublishStream: (trackType: TrackType) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Stops publishing all tracks and stop all tracks.
|
|
38
|
+
*/
|
|
39
|
+
stopPublishing: () => void;
|
|
40
|
+
updateVideoPublishQuality: (enabledRids: string[]) => Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the result of the `RTCPeerConnection.getStats()` method
|
|
43
|
+
* @param selector
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
getStats(selector?: MediaStreamTrack | null | undefined): Promise<RTCStatsReport>;
|
|
47
|
+
private onIceCandidate;
|
|
48
|
+
private onNegotiationNeeded;
|
|
49
|
+
private onIceCandidateError;
|
|
50
|
+
private onIceConnectionStateChange;
|
|
51
|
+
private onIceGatheringStateChange;
|
|
52
|
+
private ridToVideoQuality;
|
|
53
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StreamSfuClient } from '../StreamSfuClient';
|
|
2
|
+
export type SubscriberOpts = {
|
|
3
|
+
rpcClient: StreamSfuClient;
|
|
4
|
+
connectionConfig?: RTCConfiguration;
|
|
5
|
+
onTrack?: (e: RTCTrackEvent) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const createSubscriber: ({ rpcClient, connectionConfig, onTrack, }: SubscriberOpts) => RTCPeerConnection;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { UserResponse } from '../gen/coordinator';
|
|
2
|
+
import type { Participant, VideoDimension } from '../gen/video/sfu/models/models';
|
|
3
|
+
export interface StreamVideoParticipant extends Participant {
|
|
4
|
+
/**
|
|
5
|
+
* The participant's audio stream, if they are publishing audio and
|
|
6
|
+
* we have subscribed to it.
|
|
7
|
+
*/
|
|
8
|
+
audioStream?: MediaStream;
|
|
9
|
+
/**
|
|
10
|
+
* The participant's video stream, if they are sharing their video,
|
|
11
|
+
* and we are subscribed to it.
|
|
12
|
+
*/
|
|
13
|
+
videoStream?: MediaStream;
|
|
14
|
+
/**
|
|
15
|
+
* The participant's screen share stream, if they are sharing their screen,
|
|
16
|
+
* and we are subscribed to it.
|
|
17
|
+
*/
|
|
18
|
+
screenShareStream?: MediaStream;
|
|
19
|
+
/**
|
|
20
|
+
* The preferred video dimensions for this participant.
|
|
21
|
+
* Set it to `undefined` to unsubscribe from this participant's video.
|
|
22
|
+
*/
|
|
23
|
+
videoDimension?: VideoDimension;
|
|
24
|
+
/**
|
|
25
|
+
* The preferred screen share dimensions for this participant.
|
|
26
|
+
* Set it to `undefined` to unsubscribe from this participant's screen share.
|
|
27
|
+
*/
|
|
28
|
+
screenShareDimension?: VideoDimension;
|
|
29
|
+
/**
|
|
30
|
+
* True if the participant is the local participant.
|
|
31
|
+
*/
|
|
32
|
+
isLoggedInUser?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* True when the participant is pinned
|
|
35
|
+
*/
|
|
36
|
+
isPinned?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* User metadata (profile picture, name...)
|
|
39
|
+
*/
|
|
40
|
+
user?: UserResponse;
|
|
41
|
+
}
|
|
42
|
+
export interface StreamVideoLocalParticipant extends StreamVideoParticipant {
|
|
43
|
+
/**
|
|
44
|
+
* The device ID of the currently selected audio input device of the local participant (returned by the [MediaDevices API](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia))
|
|
45
|
+
*/
|
|
46
|
+
audioDeviceId?: string;
|
|
47
|
+
/**
|
|
48
|
+
* The device ID of the currently selected video input device of the local participant (returned by the [MediaDevices API](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia))
|
|
49
|
+
*/
|
|
50
|
+
videoDeviceId?: string;
|
|
51
|
+
/**
|
|
52
|
+
* The device ID of the currently selected audio output device of the local participant (returned by the [MediaDevices API](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia))
|
|
53
|
+
*
|
|
54
|
+
* If the value is not defined, the user hasn't selected any device (in these cases the default system audio output could be used)
|
|
55
|
+
*/
|
|
56
|
+
audioOutputDeviceId?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A partial representation of the StreamVideoParticipant.
|
|
60
|
+
*/
|
|
61
|
+
export type StreamVideoParticipantPatch = Partial<StreamVideoParticipant | StreamVideoLocalParticipant>;
|
|
62
|
+
/**
|
|
63
|
+
* A collection of {@link StreamVideoParticipantPatch} organized by sessionId.
|
|
64
|
+
*/
|
|
65
|
+
export type StreamVideoParticipantPatches = {
|
|
66
|
+
[sessionId: string]: StreamVideoParticipantPatch;
|
|
67
|
+
};
|
|
68
|
+
export type SubscriptionChange = {
|
|
69
|
+
/**
|
|
70
|
+
* The video dimension to request.
|
|
71
|
+
* Set it to `undefined` in case you want to unsubscribe.
|
|
72
|
+
*/
|
|
73
|
+
dimension: VideoDimension | undefined;
|
|
74
|
+
};
|
|
75
|
+
export type SubscriptionChanges = {
|
|
76
|
+
[sessionId: string]: SubscriptionChange;
|
|
77
|
+
};
|
|
78
|
+
export type CallOptions = {
|
|
79
|
+
connectionConfig?: RTCConfiguration;
|
|
80
|
+
edgeName?: string;
|
|
81
|
+
};
|
|
82
|
+
export type PublishOptions = {
|
|
83
|
+
preferredCodec?: string | null;
|
|
84
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type OptimalVideoLayer = RTCRtpEncodingParameters & {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
maxFramerate?: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const findOptimalVideoLayers: (videoTrack: MediaStreamTrack) => {
|
|
7
|
+
rid: string;
|
|
8
|
+
active?: boolean | undefined;
|
|
9
|
+
maxBitrate?: number | undefined;
|
|
10
|
+
maxFramerate?: number | undefined;
|
|
11
|
+
networkPriority?: RTCPriorityType | undefined;
|
|
12
|
+
priority?: RTCPriorityType | undefined;
|
|
13
|
+
scaleResolutionDownBy?: number | undefined;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
}[];
|
|
17
|
+
export declare const findOptimalScreenSharingLayers: (videoTrack: MediaStreamTrack) => OptimalVideoLayer[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StreamVideoReadOnlyStateStore } from '../store';
|
|
2
|
+
import { ReportCallStatEventRequest, ReportCallStatEventResponse, ReportCallStatsResponse } from '../gen/video/coordinator/client_v1_rpc/client_rpc';
|
|
3
|
+
/**
|
|
4
|
+
* Collects stat metrics and events from the state store and sends them to the Coordinator API
|
|
5
|
+
* @param readOnlyStateStore
|
|
6
|
+
* @param sendStatMetrics
|
|
7
|
+
* @param sendStatEvent
|
|
8
|
+
*/
|
|
9
|
+
export declare const reportStats: (readOnlyStateStore: StreamVideoReadOnlyStateStore, sendStatMetrics: (stats: Object) => Promise<ReportCallStatsResponse | void>, sendStatEvent: (statEvent: ReportCallStatEventRequest['event']) => Promise<ReportCallStatEventResponse | void>) => void;
|
|
10
|
+
export declare const reportStatEvents: (store: StreamVideoReadOnlyStateStore, sendStatEvent: (statEvent: ReportCallStatEventRequest['event']) => Promise<ReportCallStatEventResponse | void>) => void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { StatsReport } from './types';
|
|
2
|
+
import { StreamVideoWriteableStateStore } from '../store';
|
|
3
|
+
import { Publisher } from '../rtc/publisher';
|
|
4
|
+
export type StatsReporterOpts = {
|
|
5
|
+
subscriber: RTCPeerConnection;
|
|
6
|
+
publisher: Publisher;
|
|
7
|
+
store: StreamVideoWriteableStateStore;
|
|
8
|
+
pollingIntervalInMs?: number;
|
|
9
|
+
edgeName?: string;
|
|
10
|
+
};
|
|
11
|
+
export type StatsReporter = {
|
|
12
|
+
/**
|
|
13
|
+
* Will turn on stats reporting for a given sessionId.
|
|
14
|
+
*
|
|
15
|
+
* @param sessionId the session id.
|
|
16
|
+
*/
|
|
17
|
+
startReportingStatsFor: (sessionId: string) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Will turn off stats reporting for a given sessionId.
|
|
20
|
+
*
|
|
21
|
+
* @param sessionId the session id.
|
|
22
|
+
*/
|
|
23
|
+
stopReportingStatsFor: (sessionId: string) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Helper method for retrieving stats for a given peer connection kind
|
|
26
|
+
* and media stream flowing through it.
|
|
27
|
+
*
|
|
28
|
+
* @param kind the peer connection kind (subscriber or publisher).
|
|
29
|
+
* @param mediaStream the media stream.
|
|
30
|
+
*/
|
|
31
|
+
getStatsForStream: (kind: 'subscriber' | 'publisher', mediaStream: MediaStream) => Promise<StatsReport[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Helper method for retrieving raw stats for a given peer connection kind.
|
|
34
|
+
*
|
|
35
|
+
* @param kind the peer connection kind (subscriber or publisher).
|
|
36
|
+
* @param selector the track selector. If not provided, stats for all tracks will be returned.
|
|
37
|
+
*/
|
|
38
|
+
getRawStatsForTrack: (kind: 'subscriber' | 'publisher', selector?: MediaStreamTrack) => Promise<RTCStatsReport | undefined>;
|
|
39
|
+
/**
|
|
40
|
+
* Stops the stats reporter and releases all resources.
|
|
41
|
+
*/
|
|
42
|
+
stop: () => void;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new StatsReporter instance that collects metrics about the ongoing call and reports them to the state store
|
|
46
|
+
*/
|
|
47
|
+
export declare const createStatsReporter: ({ subscriber, publisher, store, edgeName, pollingIntervalInMs, }: StatsReporterOpts) => StatsReporter;
|
|
48
|
+
export type StatsTransformOpts = {
|
|
49
|
+
/**
|
|
50
|
+
* The kind of track we are transforming stats for.
|
|
51
|
+
*/
|
|
52
|
+
trackKind: 'audio' | 'video';
|
|
53
|
+
/**
|
|
54
|
+
* The kind of peer connection we are transforming stats for.
|
|
55
|
+
*/
|
|
56
|
+
kind: 'subscriber' | 'publisher';
|
|
57
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type BaseStats = {
|
|
2
|
+
bytesSent?: number;
|
|
3
|
+
bytesReceived?: number;
|
|
4
|
+
codec?: string;
|
|
5
|
+
currentRoundTripTime?: number;
|
|
6
|
+
frameWidth?: number;
|
|
7
|
+
frameHeight?: number;
|
|
8
|
+
framesPerSecond?: number;
|
|
9
|
+
jitter?: number;
|
|
10
|
+
kind?: string;
|
|
11
|
+
qualityLimitationReason?: string;
|
|
12
|
+
rid?: string;
|
|
13
|
+
ssrc?: number;
|
|
14
|
+
};
|
|
15
|
+
export type StatsReport = {
|
|
16
|
+
rawStats?: RTCStatsReport;
|
|
17
|
+
streams: BaseStats[];
|
|
18
|
+
timestamp: number;
|
|
19
|
+
};
|
|
20
|
+
export type AggregatedStatsReport = {
|
|
21
|
+
totalBytesSent: number;
|
|
22
|
+
totalBytesReceived: number;
|
|
23
|
+
averageJitterInMs: number;
|
|
24
|
+
averageRoundTripTimeInMs: number;
|
|
25
|
+
qualityLimitationReasons: string;
|
|
26
|
+
highestFrameWidth: number;
|
|
27
|
+
highestFrameHeight: number;
|
|
28
|
+
highestFramesPerSecond: number;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
};
|
|
31
|
+
export type ParticipantsStatsReport = {
|
|
32
|
+
[sessionId: string]: StatsReport[] | undefined;
|
|
33
|
+
};
|
|
34
|
+
export type CallStatsReport = {
|
|
35
|
+
datacenter: string;
|
|
36
|
+
publisherStats: AggregatedStatsReport;
|
|
37
|
+
publisherRawStats?: RTCStatsReport;
|
|
38
|
+
subscriberStats: AggregatedStatsReport;
|
|
39
|
+
subscriberRawStats?: RTCStatsReport;
|
|
40
|
+
participants: ParticipantsStatsReport;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Observable, Subject } from 'rxjs';
|
|
2
|
+
/**
|
|
3
|
+
* Gets the current value of an observable, or undefined if the observable has
|
|
4
|
+
* not emitted a value yet.
|
|
5
|
+
*
|
|
6
|
+
* @param observable$ the observable to get the value from.
|
|
7
|
+
*/
|
|
8
|
+
export declare const getCurrentValue: <T>(observable$: Observable<T>) => T;
|
|
9
|
+
/**
|
|
10
|
+
* Updates the value of the provided Subject.
|
|
11
|
+
* An `update` can either be a new value or a function which takes
|
|
12
|
+
* the current value and returns a new value.
|
|
13
|
+
*
|
|
14
|
+
* @param subject the subject to update.
|
|
15
|
+
* @param update the update to apply to the subject.
|
|
16
|
+
* @return the updated value.
|
|
17
|
+
*/
|
|
18
|
+
export declare const setCurrentValue: <T>(subject: Subject<T>, update: T | ((currentValue: T) => T)) => T;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs';
|
|
2
|
+
import { Call as CallController } from '../rtc/Call';
|
|
3
|
+
import { CallMetadata } from '../rtc/CallMetadata';
|
|
4
|
+
import type { StreamVideoLocalParticipant, StreamVideoParticipant, StreamVideoParticipantPatch, StreamVideoParticipantPatches } from '../rtc/types';
|
|
5
|
+
import type { CallStatsReport } from '../stats/types';
|
|
6
|
+
import type { User } from '../coordinator/connection/types';
|
|
7
|
+
import type { CallAccepted } from '../gen/coordinator';
|
|
8
|
+
export declare class StreamVideoWriteableStateStore {
|
|
9
|
+
/**
|
|
10
|
+
* A store keeping data of a successfully connected user over WS to the coordinator server.
|
|
11
|
+
*/
|
|
12
|
+
connectedUserSubject: BehaviorSubject<User | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* A store that keeps track of all created calls that have not been yet accepted, rejected nor cancelled.
|
|
15
|
+
*/
|
|
16
|
+
pendingCallsSubject: BehaviorSubject<CallMetadata[]>;
|
|
17
|
+
/**
|
|
18
|
+
* A list of objects describing incoming calls.
|
|
19
|
+
*/
|
|
20
|
+
incomingCalls$: Observable<CallMetadata[]>;
|
|
21
|
+
/**
|
|
22
|
+
* A list of objects describing calls initiated by the current user (connectedUser).
|
|
23
|
+
*/
|
|
24
|
+
outgoingCalls$: Observable<CallMetadata[]>;
|
|
25
|
+
/**
|
|
26
|
+
* A store that keeps track of all the notifications describing accepted call.
|
|
27
|
+
*/
|
|
28
|
+
acceptedCallSubject: BehaviorSubject<CallAccepted | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* A store that keeps reference to a call controller instance.
|
|
31
|
+
*/
|
|
32
|
+
activeCallSubject: BehaviorSubject<CallController | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* All participants of the current call (including the logged-in user).
|
|
35
|
+
*/
|
|
36
|
+
participantsSubject: ReplaySubject<(StreamVideoParticipant | StreamVideoLocalParticipant)[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Remote participants of the current call (this includes every participant except the logged-in user).
|
|
39
|
+
*/
|
|
40
|
+
remoteParticipants$: Observable<StreamVideoParticipant[]>;
|
|
41
|
+
/**
|
|
42
|
+
* The local participant of the current call (the logged-in user).
|
|
43
|
+
*/
|
|
44
|
+
localParticipant$: Observable<StreamVideoLocalParticipant | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* Pinned participants of the current call.
|
|
47
|
+
*/
|
|
48
|
+
pinnedParticipants$: Observable<StreamVideoParticipant[]>;
|
|
49
|
+
/**
|
|
50
|
+
* The currently elected dominant speaker in the active call.
|
|
51
|
+
*/
|
|
52
|
+
dominantSpeaker$: Observable<StreamVideoParticipant | undefined>;
|
|
53
|
+
callStatsReportSubject: BehaviorSubject<CallStatsReport | undefined>;
|
|
54
|
+
callRecordingInProgressSubject: ReplaySubject<boolean>;
|
|
55
|
+
hasOngoingScreenShare$: Observable<boolean>;
|
|
56
|
+
constructor();
|
|
57
|
+
/**
|
|
58
|
+
* Gets the current value of an observable, or undefined if the observable has
|
|
59
|
+
* not emitted a value yet.
|
|
60
|
+
*
|
|
61
|
+
* @param observable$ the observable to get the value from.
|
|
62
|
+
*/
|
|
63
|
+
getCurrentValue: <T>(observable$: Observable<T>) => T;
|
|
64
|
+
/**
|
|
65
|
+
* Updates the value of the provided Subject.
|
|
66
|
+
* An `update` can either be a new value or a function which takes
|
|
67
|
+
* the current value and returns a new value.
|
|
68
|
+
*
|
|
69
|
+
* @param subject the subject to update.
|
|
70
|
+
* @param update the update to apply to the subject.
|
|
71
|
+
* @return the updated value.
|
|
72
|
+
*/
|
|
73
|
+
setCurrentValue: <T>(subject: import("rxjs").Subject<T>, update: T | ((currentValue: T) => T)) => T;
|
|
74
|
+
/**
|
|
75
|
+
* Will try to find the participant with the given sessionId in the active call.
|
|
76
|
+
*
|
|
77
|
+
* @param sessionId the sessionId of the participant to find.
|
|
78
|
+
* @returns the participant with the given sessionId or undefined if not found.
|
|
79
|
+
*/
|
|
80
|
+
findParticipantBySessionId: (sessionId: string) => StreamVideoParticipant | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Updates a participant in the active call identified by the given `sessionId`.
|
|
83
|
+
* If the participant can't be found, this operation is no-op.
|
|
84
|
+
*
|
|
85
|
+
* @param sessionId the session ID of the participant to update.
|
|
86
|
+
* @param patch the patch to apply to the participant.
|
|
87
|
+
* @returns the updated participant or `undefined` if the participant couldn't be found.
|
|
88
|
+
*/
|
|
89
|
+
updateParticipant: (sessionId: string, patch: StreamVideoParticipantPatch | ((p: StreamVideoParticipant) => StreamVideoParticipantPatch)) => (StreamVideoParticipant | StreamVideoLocalParticipant)[] | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* Updates all participants in the active call whose session ID is in the given `sessionIds`.
|
|
92
|
+
* If no patch are provided, this operation is no-op.
|
|
93
|
+
*
|
|
94
|
+
* @param patch the patch to apply to the participants.
|
|
95
|
+
* @returns all participants, with all patch applied.
|
|
96
|
+
*/
|
|
97
|
+
updateParticipants: (patch: StreamVideoParticipantPatches) => (StreamVideoParticipant | StreamVideoLocalParticipant)[] | undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A reactive store that exposes state variables in a reactive manner - you can subscribe to changes of the different state variables. This central store contains all the state variables related to [`StreamVideoClient`](./StreamVideClient.md) and [`Call`](./Call.md).
|
|
101
|
+
*
|
|
102
|
+
*/
|
|
103
|
+
export declare class StreamVideoReadOnlyStateStore {
|
|
104
|
+
/**
|
|
105
|
+
* Data describing a user successfully connected over WS to coordinator server.
|
|
106
|
+
*/
|
|
107
|
+
connectedUser$: Observable<User | undefined>;
|
|
108
|
+
/**
|
|
109
|
+
* A list of objects describing all created calls that have not been yet accepted, rejected nor cancelled.
|
|
110
|
+
*/
|
|
111
|
+
pendingCalls$: Observable<CallMetadata[]>;
|
|
112
|
+
/**
|
|
113
|
+
* A list of objects describing calls initiated by the current user (connectedUser).
|
|
114
|
+
*/
|
|
115
|
+
outgoingCalls$: Observable<CallMetadata[]>;
|
|
116
|
+
/**
|
|
117
|
+
* A list of objects describing incoming calls.
|
|
118
|
+
*/
|
|
119
|
+
incomingCalls$: Observable<CallMetadata[]>;
|
|
120
|
+
/**
|
|
121
|
+
* The call data describing an incoming call accepted by a participant.
|
|
122
|
+
* Serves as a flag decide, whether an incoming call should be joined.
|
|
123
|
+
*/
|
|
124
|
+
acceptedCall$: Observable<CallAccepted | undefined>;
|
|
125
|
+
/**
|
|
126
|
+
* The call controller instance representing the call the user attends.
|
|
127
|
+
* The controller instance exposes call metadata as well.
|
|
128
|
+
* `activeCall$` will be set after calling [`join` on a `Call` instance](./Call.md/#join) and cleared after calling [`leave`](./Call.md/#leave).
|
|
129
|
+
*/
|
|
130
|
+
activeCall$: Observable<CallController | undefined>;
|
|
131
|
+
/**
|
|
132
|
+
* The currently elected dominant speaker in the active call.
|
|
133
|
+
*/
|
|
134
|
+
dominantSpeaker$: Observable<StreamVideoParticipant | undefined>;
|
|
135
|
+
/**
|
|
136
|
+
* All participants of the current call (this includes the current user and other participants as well).
|
|
137
|
+
*/
|
|
138
|
+
participants$: Observable<(StreamVideoParticipant | StreamVideoLocalParticipant)[]>;
|
|
139
|
+
/**
|
|
140
|
+
* The local participant of the current call (the logged-in user).
|
|
141
|
+
*/
|
|
142
|
+
localParticipant$: Observable<StreamVideoLocalParticipant | undefined>;
|
|
143
|
+
/**
|
|
144
|
+
* Remote participants of the current call (this includes every participant except the logged-in user).
|
|
145
|
+
*/
|
|
146
|
+
remoteParticipants$: Observable<StreamVideoParticipant[]>;
|
|
147
|
+
/**
|
|
148
|
+
* Pinned participants of the current call.
|
|
149
|
+
*/
|
|
150
|
+
pinnedParticipants$: Observable<StreamVideoParticipant[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Emits true whenever there is an active screen sharing session within
|
|
153
|
+
* the current call. Useful for displaying a "screen sharing" indicator and
|
|
154
|
+
* switching the layout to a screen sharing layout.
|
|
155
|
+
*
|
|
156
|
+
* The actual screen sharing track isn't exposed here, but can be retrieved
|
|
157
|
+
* from the list of call participants. We also don't want to be limiting
|
|
158
|
+
* to the number of share screen tracks are displayed in a call.
|
|
159
|
+
*/
|
|
160
|
+
hasOngoingScreenShare$: Observable<boolean>;
|
|
161
|
+
/**
|
|
162
|
+
* The latest stats report of the current call.
|
|
163
|
+
* When stats gathering is enabled, this observable will emit a new value
|
|
164
|
+
* at a regular (configurable) interval.
|
|
165
|
+
*
|
|
166
|
+
* Consumers of this observable can implement their own batching logic
|
|
167
|
+
* in case they want to show historical stats data.
|
|
168
|
+
*/
|
|
169
|
+
callStatsReport$: Observable<CallStatsReport | undefined>;
|
|
170
|
+
/**
|
|
171
|
+
* Emits a boolean indicating whether a call recording is currently in progress.
|
|
172
|
+
*/
|
|
173
|
+
callRecordingInProgress$: Observable<boolean>;
|
|
174
|
+
/**
|
|
175
|
+
* This method allows you the get the current value of a state variable.
|
|
176
|
+
*
|
|
177
|
+
* @param observable the observable to get the current value of.
|
|
178
|
+
* @returns the current value of the observable.
|
|
179
|
+
*/
|
|
180
|
+
getCurrentValue: <T>(observable: Observable<T>) => T;
|
|
181
|
+
constructor(store: StreamVideoWriteableStateStore);
|
|
182
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
CHAT_REPO_ROOT_DIR="../../../chat"
|
|
5
|
+
SCHEMA_FILE="$CHAT_REPO_ROOT_DIR/releases/video-openapi.yaml"
|
|
6
|
+
OUTPUT_DIR="./src/gen/coordinator"
|
|
7
|
+
TEMP_OUTPUT_DIR="./src/gen/openapi-temp"
|
|
8
|
+
|
|
9
|
+
# Generate the Coordinator OpenAPI schema
|
|
10
|
+
make -C $CHAT_REPO_ROOT_DIR video-openapi-yaml
|
|
11
|
+
|
|
12
|
+
# Clean previous output
|
|
13
|
+
rm -rf $TEMP_OUTPUT_DIR
|
|
14
|
+
rm -rf $OUTPUT_DIR
|
|
15
|
+
|
|
16
|
+
# NOTE: https://openapi-generator.tech/docs/generators/typescript-fetch/
|
|
17
|
+
# Generate the Coordinator API models
|
|
18
|
+
yarn openapi-generator-cli generate \
|
|
19
|
+
-i "$SCHEMA_FILE" \
|
|
20
|
+
-g typescript-fetch \
|
|
21
|
+
-o "$TEMP_OUTPUT_DIR" \
|
|
22
|
+
--skip-validate-spec \
|
|
23
|
+
--additional-properties=supportsES6=true \
|
|
24
|
+
--additional-properties=modelPropertyNaming=original \
|
|
25
|
+
--additional-properties=enumPropertyNaming=original \
|
|
26
|
+
--additional-properties=withoutRuntimeChecks=true
|
|
27
|
+
|
|
28
|
+
# Remove the generated API client, just keep the models
|
|
29
|
+
cp -r $TEMP_OUTPUT_DIR/models $OUTPUT_DIR
|
|
30
|
+
rm -rf $TEMP_OUTPUT_DIR
|
|
31
|
+
|
|
32
|
+
yarn prettier --write $OUTPUT_DIR
|
package/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import 'webrtc-adapter';
|
|
2
|
+
|
|
3
|
+
export * as CoordinatorModels from './src/gen/coordinator';
|
|
4
|
+
export * from './src/coordinator/connection/types';
|
|
5
|
+
|
|
6
|
+
export * as SfuEvents from './src/gen/video/sfu/event/events';
|
|
7
|
+
export * as SfuModels from './src/gen/video/sfu/models/models';
|
|
8
|
+
// due to name collision with `/rtc/Call.ts`
|
|
9
|
+
export * as CallMeta from './src/gen/video/coordinator/call_v1/call';
|
|
10
|
+
|
|
11
|
+
export * from './src/gen/google/protobuf/timestamp';
|
|
12
|
+
export * from './src/gen/video/coordinator/client_v1_rpc/client_rpc';
|
|
13
|
+
export * from './src/gen/video/coordinator/edge_v1/edge';
|
|
14
|
+
export * from './src/gen/video/coordinator/event_v1/event';
|
|
15
|
+
export * from './src/gen/video/coordinator/stat_v1/stat';
|
|
16
|
+
|
|
17
|
+
export * from './src/config/types';
|
|
18
|
+
export * from './src/config/defaultConfigs';
|
|
19
|
+
export * from './src/rtc/types';
|
|
20
|
+
export * from './src/stats/types';
|
|
21
|
+
|
|
22
|
+
export * from './src/rtc/Call';
|
|
23
|
+
export * from './src/rtc/CallMetadata';
|
|
24
|
+
export * from './src/StreamVideoClient';
|
|
25
|
+
export * from './src/StreamSfuClient';
|
|
26
|
+
export * from './src/devices';
|
|
27
|
+
export * from './src/store';
|
|
28
|
+
|
|
29
|
+
export * from './src/helpers/sound-detector';
|
|
30
|
+
export * as Browsers from './src/helpers/browsers';
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stream-io/video-client",
|
|
3
|
+
"packageManager": "yarn@3.2.4",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"license": "See license in LICENSE",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"clean": "rimraf dist",
|
|
10
|
+
"start": "rollup -w -c",
|
|
11
|
+
"build": "yarn clean && rollup -c",
|
|
12
|
+
"test": "vitest",
|
|
13
|
+
"clean:docs": "rimraf generated-docs",
|
|
14
|
+
"generate-docs": "yarn clean:docs && yarn generate-docs:classes && yarn generate-docs:utils",
|
|
15
|
+
"test-ci": "vitest --coverage",
|
|
16
|
+
"generate:open-api": "./generate-openapi.sh",
|
|
17
|
+
"generate-docs:classes": "typedoc --options typedoc.json --exclude '!**/*(Call|StreamVideoClient).ts' ./index.ts && replace-in-file '# Class: ' '# ' temp-docs/** && cp -a temp-docs/classes/. generated-docs && rm -r temp-docs",
|
|
18
|
+
"generate-docs:utils": "typedoc --options typedoc.json --exclude '!**/*(devices).ts' ./index.ts && replace-in-file '# @stream-io/video-client' '# Utilities' temp-docs/** && cp temp-docs/modules.md generated-docs/utilities.md && rm -r temp-docs"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@protobuf-ts/runtime": "^2.8.2",
|
|
22
|
+
"@protobuf-ts/runtime-rpc": "^2.8.2",
|
|
23
|
+
"@protobuf-ts/twirp-transport": "^2.8.2",
|
|
24
|
+
"axios": "^1.3.2",
|
|
25
|
+
"base64-js": "^1.5.1",
|
|
26
|
+
"isomorphic-ws": "^5.0.0",
|
|
27
|
+
"jsonwebtoken": "^9.0.0",
|
|
28
|
+
"rxjs": "~7.5.7",
|
|
29
|
+
"uuid": "^9.0.0",
|
|
30
|
+
"webrtc-adapter": "^8.2.0",
|
|
31
|
+
"ws": "^8.12.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@openapitools/openapi-generator-cli": "^2.5.2",
|
|
35
|
+
"@rollup/plugin-replace": "^5.0.2",
|
|
36
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
37
|
+
"@types/jsonwebtoken": "^9.0.1",
|
|
38
|
+
"@types/rimraf": "^3.0.2",
|
|
39
|
+
"@types/uuid": "^9.0.0",
|
|
40
|
+
"@types/ws": "^8.5.4",
|
|
41
|
+
"@vitest/coverage-c8": "^0.25.3",
|
|
42
|
+
"prettier": "^2.8.3",
|
|
43
|
+
"replace-in-file": "^6.3.5",
|
|
44
|
+
"rimraf": "^3.0.2",
|
|
45
|
+
"rollup": "^3.14.0",
|
|
46
|
+
"typedoc": "^0.23.23",
|
|
47
|
+
"typedoc-plugin-markdown": "^3.13.6",
|
|
48
|
+
"typescript": "^4.9.4",
|
|
49
|
+
"vite": "^3.2.5",
|
|
50
|
+
"vitest": "^0.25.4",
|
|
51
|
+
"vitest-mock-extended": "^1.0.7"
|
|
52
|
+
},
|
|
53
|
+
"version": "0.0.1-alpha.7"
|
|
54
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import typescript from '@rollup/plugin-typescript';
|
|
2
|
+
import replace from '@rollup/plugin-replace';
|
|
3
|
+
|
|
4
|
+
import pkg from './package.json' assert { type: 'json' };
|
|
5
|
+
|
|
6
|
+
// these modules are used only in nodejs and are not needed in the browser
|
|
7
|
+
const browserIgnoredModules = [
|
|
8
|
+
'jsonwebtoken',
|
|
9
|
+
'https',
|
|
10
|
+
'crypto',
|
|
11
|
+
'util',
|
|
12
|
+
'stream',
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A plugin which converts the nodejs modules to empty modules for the browser.
|
|
17
|
+
*
|
|
18
|
+
* @type {import('rollup').Plugin}
|
|
19
|
+
*/
|
|
20
|
+
const browserIgnorePlugin = {
|
|
21
|
+
name: 'browser-remapper',
|
|
22
|
+
resolveId: (importee) =>
|
|
23
|
+
browserIgnoredModules.includes(importee) ? importee : null,
|
|
24
|
+
load: (id) =>
|
|
25
|
+
browserIgnoredModules.includes(id) ? 'export default null;' : null,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @type {import('rollup').RollupOptions}
|
|
30
|
+
*/
|
|
31
|
+
const rollupConfig = {
|
|
32
|
+
input: 'index.ts',
|
|
33
|
+
output: {
|
|
34
|
+
dir: 'dist',
|
|
35
|
+
format: 'es',
|
|
36
|
+
sourcemap: true,
|
|
37
|
+
},
|
|
38
|
+
plugins: [
|
|
39
|
+
replace({
|
|
40
|
+
preventAssignment: true,
|
|
41
|
+
'process.env.PKG_VERSION': JSON.stringify(pkg.version),
|
|
42
|
+
}),
|
|
43
|
+
browserIgnorePlugin,
|
|
44
|
+
typescript(),
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default rollupConfig;
|