@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.
Files changed (157) hide show
  1. package/LICENSE +219 -0
  2. package/README.md +14 -0
  3. package/dist/index.d.ts +23 -0
  4. package/dist/index.js +14663 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/src/Batcher.d.ts +12 -0
  7. package/dist/src/CallDropScheduler.d.ts +44 -0
  8. package/dist/src/StreamSfuClient.d.ts +25 -0
  9. package/dist/src/StreamVideoClient.d.ts +145 -0
  10. package/dist/src/__tests__/StreamVideoClient.test.d.ts +1 -0
  11. package/dist/src/config/defaultConfigs.d.ts +2 -0
  12. package/dist/src/config/types.d.ts +29 -0
  13. package/dist/src/coordinator/StreamCoordinatorClient.d.ts +19 -0
  14. package/dist/src/coordinator/connection/base64.d.ts +2 -0
  15. package/dist/src/coordinator/connection/client.d.ts +174 -0
  16. package/dist/src/coordinator/connection/connection.d.ts +139 -0
  17. package/dist/src/coordinator/connection/connection_fallback.d.ts +38 -0
  18. package/dist/src/coordinator/connection/errors.d.ts +16 -0
  19. package/dist/src/coordinator/connection/events.d.ts +7 -0
  20. package/dist/src/coordinator/connection/insights.d.ts +58 -0
  21. package/dist/src/coordinator/connection/signing.d.ts +30 -0
  22. package/dist/src/coordinator/connection/token_manager.d.ts +39 -0
  23. package/dist/src/coordinator/connection/types.d.ts +96 -0
  24. package/dist/src/coordinator/connection/utils.d.ts +25 -0
  25. package/dist/src/devices.d.ts +79 -0
  26. package/dist/src/events/call.d.ts +26 -0
  27. package/dist/src/events/internal.d.ts +8 -0
  28. package/dist/src/events/participant.d.ts +21 -0
  29. package/dist/src/events/speaker.d.ts +10 -0
  30. package/dist/src/gen/coordinator/index.d.ts +1664 -0
  31. package/dist/src/gen/google/protobuf/descriptor.d.ts +1650 -0
  32. package/dist/src/gen/google/protobuf/duration.d.ts +113 -0
  33. package/dist/src/gen/google/protobuf/struct.d.ts +184 -0
  34. package/dist/src/gen/google/protobuf/timestamp.d.ts +158 -0
  35. package/dist/src/gen/video/coordinator/broadcast_v1/broadcast.d.ts +66 -0
  36. package/dist/src/gen/video/coordinator/call_v1/call.d.ts +254 -0
  37. package/dist/src/gen/video/coordinator/client_v1_rpc/client_rpc.client.d.ts +351 -0
  38. package/dist/src/gen/video/coordinator/client_v1_rpc/client_rpc.d.ts +1488 -0
  39. package/dist/src/gen/video/coordinator/client_v1_rpc/envelopes.d.ts +143 -0
  40. package/dist/src/gen/video/coordinator/client_v1_rpc/websocket.d.ts +292 -0
  41. package/dist/src/gen/video/coordinator/edge_v1/edge.d.ts +183 -0
  42. package/dist/src/gen/video/coordinator/event_v1/event.d.ts +411 -0
  43. package/dist/src/gen/video/coordinator/geofence_v1/geofence.d.ts +63 -0
  44. package/dist/src/gen/video/coordinator/member_v1/member.d.ts +59 -0
  45. package/dist/src/gen/video/coordinator/participant_v1/participant.d.ts +103 -0
  46. package/dist/src/gen/video/coordinator/push_v1/push.d.ts +240 -0
  47. package/dist/src/gen/video/coordinator/stat_v1/stat.d.ts +308 -0
  48. package/dist/src/gen/video/coordinator/user_v1/user.d.ts +112 -0
  49. package/dist/src/gen/video/coordinator/utils_v1/utils.d.ts +47 -0
  50. package/dist/src/gen/video/sfu/event/events.d.ts +736 -0
  51. package/dist/src/gen/video/sfu/models/models.d.ts +460 -0
  52. package/dist/src/gen/video/sfu/signal_rpc/signal.client.d.ts +89 -0
  53. package/dist/src/gen/video/sfu/signal_rpc/signal.d.ts +320 -0
  54. package/dist/src/helpers/browsers.d.ts +8 -0
  55. package/dist/src/helpers/sound-detector.d.ts +34 -0
  56. package/dist/src/rpc/createClient.d.ts +10 -0
  57. package/dist/src/rpc/index.d.ts +2 -0
  58. package/dist/src/rpc/latency.d.ts +9 -0
  59. package/dist/src/rtc/Call.d.ts +180 -0
  60. package/dist/src/rtc/CallMetadata.d.ts +9 -0
  61. package/dist/src/rtc/Dispatcher.d.ts +9 -0
  62. package/dist/src/rtc/IceTrickleBuffer.d.ts +11 -0
  63. package/dist/src/rtc/callEventHandlers.d.ts +5 -0
  64. package/dist/src/rtc/codecs.d.ts +2 -0
  65. package/dist/src/rtc/helpers/iceCandidate.d.ts +2 -0
  66. package/dist/src/rtc/helpers/tracks.d.ts +3 -0
  67. package/dist/src/rtc/publisher.d.ts +53 -0
  68. package/dist/src/rtc/signal.d.ts +5 -0
  69. package/dist/src/rtc/subscriber.d.ts +7 -0
  70. package/dist/src/rtc/types.d.ts +84 -0
  71. package/dist/src/rtc/videoLayers.d.ts +17 -0
  72. package/dist/src/stats/coordinator-stats-reporter.d.ts +10 -0
  73. package/dist/src/stats/state-store-stats-reporter.d.ts +57 -0
  74. package/dist/src/stats/types.d.ts +42 -0
  75. package/dist/src/store/index.d.ts +2 -0
  76. package/dist/src/store/rxUtils.d.ts +18 -0
  77. package/dist/src/store/stateStore.d.ts +182 -0
  78. package/generate-openapi.sh +32 -0
  79. package/index.ts +30 -0
  80. package/openapitools.json +7 -0
  81. package/package.json +54 -0
  82. package/rollup.config.mjs +48 -0
  83. package/src/Batcher.ts +43 -0
  84. package/src/CallDropScheduler.ts +192 -0
  85. package/src/StreamSfuClient.ts +185 -0
  86. package/src/StreamVideoClient.ts +487 -0
  87. package/src/__tests__/StreamVideoClient.test.ts +83 -0
  88. package/src/config/defaultConfigs.ts +15 -0
  89. package/src/config/types.ts +30 -0
  90. package/src/coordinator/StreamCoordinatorClient.ts +111 -0
  91. package/src/coordinator/connection/base64.ts +80 -0
  92. package/src/coordinator/connection/client.ts +815 -0
  93. package/src/coordinator/connection/connection.ts +750 -0
  94. package/src/coordinator/connection/connection_fallback.ts +239 -0
  95. package/src/coordinator/connection/errors.ts +70 -0
  96. package/src/coordinator/connection/events.ts +10 -0
  97. package/src/coordinator/connection/insights.ts +88 -0
  98. package/src/coordinator/connection/signing.ts +104 -0
  99. package/src/coordinator/connection/token_manager.ts +160 -0
  100. package/src/coordinator/connection/types.ts +120 -0
  101. package/src/coordinator/connection/utils.ts +148 -0
  102. package/src/devices.ts +266 -0
  103. package/src/events/call.ts +166 -0
  104. package/src/events/internal.ts +47 -0
  105. package/src/events/participant.ts +97 -0
  106. package/src/events/speaker.ts +62 -0
  107. package/src/gen/coordinator/index.ts +1653 -0
  108. package/src/gen/google/protobuf/descriptor.ts +3466 -0
  109. package/src/gen/google/protobuf/duration.ts +232 -0
  110. package/src/gen/google/protobuf/struct.ts +481 -0
  111. package/src/gen/google/protobuf/timestamp.ts +291 -0
  112. package/src/gen/video/coordinator/broadcast_v1/broadcast.ts +154 -0
  113. package/src/gen/video/coordinator/call_v1/call.ts +651 -0
  114. package/src/gen/video/coordinator/client_v1_rpc/client_rpc.client.ts +463 -0
  115. package/src/gen/video/coordinator/client_v1_rpc/client_rpc.ts +3819 -0
  116. package/src/gen/video/coordinator/client_v1_rpc/envelopes.ts +424 -0
  117. package/src/gen/video/coordinator/client_v1_rpc/websocket.ts +719 -0
  118. package/src/gen/video/coordinator/edge_v1/edge.ts +532 -0
  119. package/src/gen/video/coordinator/event_v1/event.ts +1171 -0
  120. package/src/gen/video/coordinator/geofence_v1/geofence.ts +128 -0
  121. package/src/gen/video/coordinator/member_v1/member.ts +138 -0
  122. package/src/gen/video/coordinator/participant_v1/participant.ts +261 -0
  123. package/src/gen/video/coordinator/push_v1/push.ts +651 -0
  124. package/src/gen/video/coordinator/stat_v1/stat.ts +656 -0
  125. package/src/gen/video/coordinator/user_v1/user.ts +277 -0
  126. package/src/gen/video/coordinator/utils_v1/utils.ts +98 -0
  127. package/src/gen/video/sfu/event/events.ts +1962 -0
  128. package/src/gen/video/sfu/models/models.ts +1062 -0
  129. package/src/gen/video/sfu/signal_rpc/signal.client.ts +108 -0
  130. package/src/gen/video/sfu/signal_rpc/signal.ts +906 -0
  131. package/src/helpers/browsers.ts +13 -0
  132. package/src/helpers/sound-detector.ts +85 -0
  133. package/src/rpc/createClient.ts +50 -0
  134. package/src/rpc/index.ts +2 -0
  135. package/src/rpc/latency.ts +43 -0
  136. package/src/rtc/Call.ts +585 -0
  137. package/src/rtc/CallMetadata.ts +24 -0
  138. package/src/rtc/Dispatcher.ts +46 -0
  139. package/src/rtc/IceTrickleBuffer.ts +21 -0
  140. package/src/rtc/callEventHandlers.ts +37 -0
  141. package/src/rtc/codecs.ts +61 -0
  142. package/src/rtc/helpers/iceCandidate.ts +16 -0
  143. package/src/rtc/helpers/tracks.ts +18 -0
  144. package/src/rtc/publisher.ts +305 -0
  145. package/src/rtc/signal.ts +34 -0
  146. package/src/rtc/subscriber.ts +85 -0
  147. package/src/rtc/types.ts +105 -0
  148. package/src/rtc/videoLayers.ts +103 -0
  149. package/src/stats/coordinator-stats-reporter.ts +167 -0
  150. package/src/stats/state-store-stats-reporter.ts +364 -0
  151. package/src/stats/types.ts +46 -0
  152. package/src/store/index.ts +2 -0
  153. package/src/store/rxUtils.ts +42 -0
  154. package/src/store/stateStore.ts +341 -0
  155. package/tsconfig.json +25 -0
  156. package/typedoc.json +11 -0
  157. 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,5 @@
1
+ import { SfuEvent } from '../gen/video/sfu/event/events';
2
+ export declare const createWebSocketSignalChannel: (opts: {
3
+ endpoint: string;
4
+ onMessage?: ((message: SfuEvent) => void) | undefined;
5
+ }) => Promise<WebSocket>;
@@ -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,2 @@
1
+ export * as RxUtils from './rxUtils';
2
+ export * from './stateStore';
@@ -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';
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
3
+ "spaces": 2,
4
+ "generator-cli": {
5
+ "version": "6.2.1"
6
+ }
7
+ }
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;