@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,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
|
+
};
|