@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,111 @@
1
+ import { StreamClient } from './connection/client';
2
+ import { sleep } from './connection/utils';
3
+ import {
4
+ EventHandler,
5
+ StreamClientOptions,
6
+ TokenOrProvider,
7
+ UR,
8
+ User,
9
+ } from './connection/types';
10
+ import {
11
+ GetCallEdgeServerRequest,
12
+ GetCallEdgeServerResponse,
13
+ GetOrCreateCallRequest,
14
+ GetOrCreateCallResponse,
15
+ JoinCallResponse,
16
+ SendEventRequest,
17
+ } from '../gen/coordinator';
18
+
19
+ export class StreamCoordinatorClient {
20
+ private client: StreamClient;
21
+
22
+ constructor(apiKey: string, options: StreamClientOptions = {}) {
23
+ this.client = new StreamClient(apiKey, {
24
+ // baseURL: 'http://localhost:3030/video',
25
+ // baseURL: 'https://video-edge-oregon-ce3.stream-io-api.com/video',
26
+ baseURL: 'https://video-edge-frankfurt-ce1.stream-io-api.com/video',
27
+ // FIXME: OL: fix SSR.
28
+ browser: true,
29
+ persistUserOnConnectionFailure: true,
30
+ ...options,
31
+ });
32
+ }
33
+
34
+ on = (
35
+ callbackOrEventName: EventHandler | string,
36
+ callbackOrNothing?: EventHandler,
37
+ ) => {
38
+ return this.client.on(callbackOrEventName, callbackOrNothing);
39
+ };
40
+
41
+ off = (
42
+ callbackOrEventName: EventHandler | string,
43
+ callbackOrNothing?: EventHandler,
44
+ ) => {
45
+ return this.client.off(callbackOrEventName, callbackOrNothing);
46
+ };
47
+
48
+ connectUser = async (user: User, token: TokenOrProvider) => {
49
+ return this.client.connectUser(user, token);
50
+ };
51
+
52
+ disconnectUser = async (timeout?: number) => {
53
+ return this.client.disconnectUser(timeout);
54
+ };
55
+
56
+ getOrCreateCall = async (
57
+ id: string,
58
+ type: string,
59
+ data?: GetOrCreateCallRequest,
60
+ ) => {
61
+ await sleep(1000);
62
+ return this.client.post<GetOrCreateCallResponse>(
63
+ `/call/${type}/${id}`,
64
+ data,
65
+ );
66
+ };
67
+
68
+ joinCall = async (
69
+ id: string,
70
+ type: string,
71
+ data?: GetOrCreateCallRequest,
72
+ ) => {
73
+ await sleep(1000);
74
+ return this.client.post<JoinCallResponse>(`/join_call/${type}/${id}`, data);
75
+ };
76
+
77
+ getCallEdgeServer = async (
78
+ id: string,
79
+ type: string,
80
+ data: GetCallEdgeServerRequest,
81
+ ) => {
82
+ return this.client.post<GetCallEdgeServerResponse>(
83
+ `/get_call_edge_server/${type}/${id}`,
84
+ data,
85
+ );
86
+ };
87
+
88
+ queryUsers = async () => {
89
+ console.log('Querying users is not implemented yet.');
90
+ };
91
+
92
+ sendEvent = async (id: string, type: string, data: SendEventRequest) => {
93
+ return this.client.post(`/call/${type}/${id}/event`, data);
94
+ };
95
+
96
+ startRecording = async (id: string, type: string) => {
97
+ console.log('Start recording is not implemented yet.');
98
+ };
99
+
100
+ stopRecording = async (id: string, type: string) => {
101
+ console.log('Stop recording is not implemented yet.');
102
+ };
103
+
104
+ reportCallStats = async (id: string, type: string, data: UR) => {
105
+ console.log('Report call stats is not implemented yet.');
106
+ };
107
+
108
+ reportCallStatEvent = async (id: string, type: string, data: UR) => {
109
+ console.log('Report call stat event is not implemented yet.');
110
+ };
111
+ }
@@ -0,0 +1,80 @@
1
+ import { fromByteArray } from 'base64-js';
2
+
3
+ function isString<T>(arrayOrString: string | T[]): arrayOrString is string {
4
+ return typeof (arrayOrString as string) === 'string';
5
+ }
6
+
7
+ type MapGenericCallback<T, U> = (value: T, index: number, array: T[]) => U;
8
+ type MapStringCallback<U> = (value: string, index: number, string: string) => U;
9
+
10
+ function isMapStringCallback<T, U>(
11
+ arrayOrString: string | T[],
12
+ callback: MapGenericCallback<T, U> | MapStringCallback<U>,
13
+ ): callback is MapStringCallback<U> {
14
+ return !!callback && isString(arrayOrString);
15
+ }
16
+
17
+ // source - https://github.com/beatgammit/base64-js/blob/master/test/convert.js#L72
18
+ function map<T, U>(array: T[], callback: MapGenericCallback<T, U>): U[];
19
+ function map<U>(string: string, callback: MapStringCallback<U>): U[];
20
+ function map<T, U>(
21
+ arrayOrString: string | T[],
22
+ callback: MapGenericCallback<T, U> | MapStringCallback<U>,
23
+ ): U[] {
24
+ const res = [];
25
+
26
+ if (isString(arrayOrString) && isMapStringCallback(arrayOrString, callback)) {
27
+ for (let k = 0, len = arrayOrString.length; k < len; k++) {
28
+ if (arrayOrString.charAt(k)) {
29
+ const kValue = arrayOrString.charAt(k);
30
+ const mappedValue = callback(kValue, k, arrayOrString);
31
+ res[k] = mappedValue;
32
+ }
33
+ }
34
+ } else if (
35
+ !isString(arrayOrString) &&
36
+ !isMapStringCallback(arrayOrString, callback)
37
+ ) {
38
+ for (let k = 0, len = arrayOrString.length; k < len; k++) {
39
+ if (k in arrayOrString) {
40
+ const kValue = arrayOrString[k];
41
+ const mappedValue = callback(kValue, k, arrayOrString);
42
+ res[k] = mappedValue;
43
+ }
44
+ }
45
+ }
46
+
47
+ return res;
48
+ }
49
+
50
+ export const encodeBase64 = (data: string): string =>
51
+ fromByteArray(new Uint8Array(map(data, (char) => char.charCodeAt(0))));
52
+
53
+ // base-64 decoder throws exception if encoded string is not padded by '=' to make string length
54
+ // in multiples of 4. So gonna use our own method for this purpose to keep backwards compatibility
55
+ // https://github.com/beatgammit/base64-js/blob/master/index.js#L26
56
+ export const decodeBase64 = (s: string): string => {
57
+ const e = {} as { [key: string]: number },
58
+ w = String.fromCharCode,
59
+ L = s.length;
60
+ let i,
61
+ b = 0,
62
+ c,
63
+ x,
64
+ l = 0,
65
+ a,
66
+ r = '';
67
+ const A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
68
+ for (i = 0; i < 64; i++) {
69
+ e[A.charAt(i)] = i;
70
+ }
71
+ for (x = 0; x < L; x++) {
72
+ c = e[s.charAt(x)];
73
+ b = (b << 6) + c;
74
+ l += 6;
75
+ while (l >= 8) {
76
+ ((a = (b >>> (l -= 8)) & 0xff) || x < L - 2) && (r += w(a));
77
+ }
78
+ }
79
+ return r;
80
+ };