@fishjam-cloud/ts-client 0.5.1
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/README.md +134 -0
- package/dist/src/FishjamClient.d.ts +523 -0
- package/dist/src/FishjamClient.js +666 -0
- package/dist/src/auth.d.ts +3 -0
- package/dist/src/auth.js +8 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +3 -0
- package/dist/src/protos/fishjam/peer_notifications.d.ts +78 -0
- package/dist/src/protos/fishjam/peer_notifications.js +302 -0
- package/dist/src/protos/index.d.ts +1 -0
- package/dist/src/protos/index.js +1 -0
- package/dist/src/reconnection.d.ts +27 -0
- package/dist/src/reconnection.js +121 -0
- package/dist/src/webrtc/CommandsQueue.d.ts +23 -0
- package/dist/src/webrtc/CommandsQueue.js +102 -0
- package/dist/src/webrtc/ConnectionManager.d.ts +29 -0
- package/dist/src/webrtc/ConnectionManager.js +82 -0
- package/dist/src/webrtc/bitrate.d.ts +12 -0
- package/dist/src/webrtc/bitrate.js +12 -0
- package/dist/src/webrtc/deferred.d.ts +8 -0
- package/dist/src/webrtc/deferred.js +17 -0
- package/dist/src/webrtc/index.d.ts +3 -0
- package/dist/src/webrtc/index.js +1 -0
- package/dist/src/webrtc/internal.d.ts +26 -0
- package/dist/src/webrtc/internal.js +34 -0
- package/dist/src/webrtc/mediaEvent.d.ts +10 -0
- package/dist/src/webrtc/mediaEvent.js +16 -0
- package/dist/src/webrtc/tracks/Local.d.ts +51 -0
- package/dist/src/webrtc/tracks/Local.js +289 -0
- package/dist/src/webrtc/tracks/LocalTrack.d.ts +62 -0
- package/dist/src/webrtc/tracks/LocalTrack.js +235 -0
- package/dist/src/webrtc/tracks/LocalTrackManager.d.ts +38 -0
- package/dist/src/webrtc/tracks/LocalTrackManager.js +83 -0
- package/dist/src/webrtc/tracks/Remote.d.ts +38 -0
- package/dist/src/webrtc/tracks/Remote.js +200 -0
- package/dist/src/webrtc/tracks/RemoteTrack.d.ts +39 -0
- package/dist/src/webrtc/tracks/RemoteTrack.js +64 -0
- package/dist/src/webrtc/tracks/TrackCommon.d.ts +8 -0
- package/dist/src/webrtc/tracks/TrackCommon.js +1 -0
- package/dist/src/webrtc/tracks/bandwidth.d.ts +1 -0
- package/dist/src/webrtc/tracks/bandwidth.js +27 -0
- package/dist/src/webrtc/tracks/encodings.d.ts +1 -0
- package/dist/src/webrtc/tracks/encodings.js +7 -0
- package/dist/src/webrtc/tracks/transceivers.d.ts +2 -0
- package/dist/src/webrtc/tracks/transceivers.js +78 -0
- package/dist/src/webrtc/types.d.ts +306 -0
- package/dist/src/webrtc/types.js +2 -0
- package/dist/src/webrtc/voiceActivityDetection.d.ts +2 -0
- package/dist/src/webrtc/voiceActivityDetection.js +2 -0
- package/dist/src/webrtc/webRTCEndpoint.d.ts +299 -0
- package/dist/src/webrtc/webRTCEndpoint.js +730 -0
- package/package.json +82 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as _m0 from "protobufjs/minimal";
|
|
2
|
+
export declare const protobufPackage = "fishjam";
|
|
3
|
+
/** Defines any type of message sent between FJ and a peer */
|
|
4
|
+
export interface PeerMessage {
|
|
5
|
+
authenticated?: PeerMessage_Authenticated | undefined;
|
|
6
|
+
authRequest?: PeerMessage_AuthRequest | undefined;
|
|
7
|
+
mediaEvent?: PeerMessage_MediaEvent | undefined;
|
|
8
|
+
rtcStatsReport?: PeerMessage_RTCStatsReport | undefined;
|
|
9
|
+
}
|
|
10
|
+
/** Response sent by FJ, confirming successfull authentication */
|
|
11
|
+
export interface PeerMessage_Authenticated {
|
|
12
|
+
}
|
|
13
|
+
/** Request sent by peer, to authenticate to FJ server */
|
|
14
|
+
export interface PeerMessage_AuthRequest {
|
|
15
|
+
token: string;
|
|
16
|
+
}
|
|
17
|
+
/** Any type of WebRTC messages passed betweend FJ and peer */
|
|
18
|
+
export interface PeerMessage_MediaEvent {
|
|
19
|
+
data: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* PeerConnection stats sent by peer
|
|
23
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport#the_statistic_types
|
|
24
|
+
*/
|
|
25
|
+
export interface PeerMessage_RTCStatsReport {
|
|
26
|
+
data: string;
|
|
27
|
+
}
|
|
28
|
+
export declare const PeerMessage: {
|
|
29
|
+
encode(message: PeerMessage, writer?: _m0.Writer): _m0.Writer;
|
|
30
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): PeerMessage;
|
|
31
|
+
fromJSON(object: any): PeerMessage;
|
|
32
|
+
toJSON(message: PeerMessage): unknown;
|
|
33
|
+
create<I extends Exact<DeepPartial<PeerMessage>, I>>(base?: I): PeerMessage;
|
|
34
|
+
fromPartial<I extends Exact<DeepPartial<PeerMessage>, I>>(object: I): PeerMessage;
|
|
35
|
+
};
|
|
36
|
+
export declare const PeerMessage_Authenticated: {
|
|
37
|
+
encode(_: PeerMessage_Authenticated, writer?: _m0.Writer): _m0.Writer;
|
|
38
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): PeerMessage_Authenticated;
|
|
39
|
+
fromJSON(_: any): PeerMessage_Authenticated;
|
|
40
|
+
toJSON(_: PeerMessage_Authenticated): unknown;
|
|
41
|
+
create<I extends Exact<DeepPartial<PeerMessage_Authenticated>, I>>(base?: I): PeerMessage_Authenticated;
|
|
42
|
+
fromPartial<I extends Exact<DeepPartial<PeerMessage_Authenticated>, I>>(_: I): PeerMessage_Authenticated;
|
|
43
|
+
};
|
|
44
|
+
export declare const PeerMessage_AuthRequest: {
|
|
45
|
+
encode(message: PeerMessage_AuthRequest, writer?: _m0.Writer): _m0.Writer;
|
|
46
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): PeerMessage_AuthRequest;
|
|
47
|
+
fromJSON(object: any): PeerMessage_AuthRequest;
|
|
48
|
+
toJSON(message: PeerMessage_AuthRequest): unknown;
|
|
49
|
+
create<I extends Exact<DeepPartial<PeerMessage_AuthRequest>, I>>(base?: I): PeerMessage_AuthRequest;
|
|
50
|
+
fromPartial<I extends Exact<DeepPartial<PeerMessage_AuthRequest>, I>>(object: I): PeerMessage_AuthRequest;
|
|
51
|
+
};
|
|
52
|
+
export declare const PeerMessage_MediaEvent: {
|
|
53
|
+
encode(message: PeerMessage_MediaEvent, writer?: _m0.Writer): _m0.Writer;
|
|
54
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): PeerMessage_MediaEvent;
|
|
55
|
+
fromJSON(object: any): PeerMessage_MediaEvent;
|
|
56
|
+
toJSON(message: PeerMessage_MediaEvent): unknown;
|
|
57
|
+
create<I extends Exact<DeepPartial<PeerMessage_MediaEvent>, I>>(base?: I): PeerMessage_MediaEvent;
|
|
58
|
+
fromPartial<I extends Exact<DeepPartial<PeerMessage_MediaEvent>, I>>(object: I): PeerMessage_MediaEvent;
|
|
59
|
+
};
|
|
60
|
+
export declare const PeerMessage_RTCStatsReport: {
|
|
61
|
+
encode(message: PeerMessage_RTCStatsReport, writer?: _m0.Writer): _m0.Writer;
|
|
62
|
+
decode(input: _m0.Reader | Uint8Array, length?: number): PeerMessage_RTCStatsReport;
|
|
63
|
+
fromJSON(object: any): PeerMessage_RTCStatsReport;
|
|
64
|
+
toJSON(message: PeerMessage_RTCStatsReport): unknown;
|
|
65
|
+
create<I extends Exact<DeepPartial<PeerMessage_RTCStatsReport>, I>>(base?: I): PeerMessage_RTCStatsReport;
|
|
66
|
+
fromPartial<I extends Exact<DeepPartial<PeerMessage_RTCStatsReport>, I>>(object: I): PeerMessage_RTCStatsReport;
|
|
67
|
+
};
|
|
68
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
69
|
+
export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
70
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
71
|
+
} : Partial<T>;
|
|
72
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
73
|
+
export type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
74
|
+
[K in keyof P]: Exact<P[K], I[K]>;
|
|
75
|
+
} & {
|
|
76
|
+
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
|
|
77
|
+
};
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
2
|
+
// versions:
|
|
3
|
+
// protoc-gen-ts_proto v1.181.1
|
|
4
|
+
// protoc v4.25.1
|
|
5
|
+
// source: protos/fishjam/peer_notifications.proto
|
|
6
|
+
/* eslint-disable */
|
|
7
|
+
import * as _m0 from "protobufjs/minimal";
|
|
8
|
+
export const protobufPackage = "fishjam";
|
|
9
|
+
function createBasePeerMessage() {
|
|
10
|
+
return { authenticated: undefined, authRequest: undefined, mediaEvent: undefined, rtcStatsReport: undefined };
|
|
11
|
+
}
|
|
12
|
+
export const PeerMessage = {
|
|
13
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
14
|
+
if (message.authenticated !== undefined) {
|
|
15
|
+
PeerMessage_Authenticated.encode(message.authenticated, writer.uint32(10).fork()).ldelim();
|
|
16
|
+
}
|
|
17
|
+
if (message.authRequest !== undefined) {
|
|
18
|
+
PeerMessage_AuthRequest.encode(message.authRequest, writer.uint32(18).fork()).ldelim();
|
|
19
|
+
}
|
|
20
|
+
if (message.mediaEvent !== undefined) {
|
|
21
|
+
PeerMessage_MediaEvent.encode(message.mediaEvent, writer.uint32(26).fork()).ldelim();
|
|
22
|
+
}
|
|
23
|
+
if (message.rtcStatsReport !== undefined) {
|
|
24
|
+
PeerMessage_RTCStatsReport.encode(message.rtcStatsReport, writer.uint32(34).fork()).ldelim();
|
|
25
|
+
}
|
|
26
|
+
return writer;
|
|
27
|
+
},
|
|
28
|
+
decode(input, length) {
|
|
29
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
30
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
31
|
+
const message = createBasePeerMessage();
|
|
32
|
+
while (reader.pos < end) {
|
|
33
|
+
const tag = reader.uint32();
|
|
34
|
+
switch (tag >>> 3) {
|
|
35
|
+
case 1:
|
|
36
|
+
if (tag !== 10) {
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
message.authenticated = PeerMessage_Authenticated.decode(reader, reader.uint32());
|
|
40
|
+
continue;
|
|
41
|
+
case 2:
|
|
42
|
+
if (tag !== 18) {
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
message.authRequest = PeerMessage_AuthRequest.decode(reader, reader.uint32());
|
|
46
|
+
continue;
|
|
47
|
+
case 3:
|
|
48
|
+
if (tag !== 26) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
message.mediaEvent = PeerMessage_MediaEvent.decode(reader, reader.uint32());
|
|
52
|
+
continue;
|
|
53
|
+
case 4:
|
|
54
|
+
if (tag !== 34) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
message.rtcStatsReport = PeerMessage_RTCStatsReport.decode(reader, reader.uint32());
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
reader.skipType(tag & 7);
|
|
64
|
+
}
|
|
65
|
+
return message;
|
|
66
|
+
},
|
|
67
|
+
fromJSON(object) {
|
|
68
|
+
return {
|
|
69
|
+
authenticated: isSet(object.authenticated) ? PeerMessage_Authenticated.fromJSON(object.authenticated) : undefined,
|
|
70
|
+
authRequest: isSet(object.authRequest) ? PeerMessage_AuthRequest.fromJSON(object.authRequest) : undefined,
|
|
71
|
+
mediaEvent: isSet(object.mediaEvent) ? PeerMessage_MediaEvent.fromJSON(object.mediaEvent) : undefined,
|
|
72
|
+
rtcStatsReport: isSet(object.rtcStatsReport)
|
|
73
|
+
? PeerMessage_RTCStatsReport.fromJSON(object.rtcStatsReport)
|
|
74
|
+
: undefined,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
toJSON(message) {
|
|
78
|
+
const obj = {};
|
|
79
|
+
if (message.authenticated !== undefined) {
|
|
80
|
+
obj.authenticated = PeerMessage_Authenticated.toJSON(message.authenticated);
|
|
81
|
+
}
|
|
82
|
+
if (message.authRequest !== undefined) {
|
|
83
|
+
obj.authRequest = PeerMessage_AuthRequest.toJSON(message.authRequest);
|
|
84
|
+
}
|
|
85
|
+
if (message.mediaEvent !== undefined) {
|
|
86
|
+
obj.mediaEvent = PeerMessage_MediaEvent.toJSON(message.mediaEvent);
|
|
87
|
+
}
|
|
88
|
+
if (message.rtcStatsReport !== undefined) {
|
|
89
|
+
obj.rtcStatsReport = PeerMessage_RTCStatsReport.toJSON(message.rtcStatsReport);
|
|
90
|
+
}
|
|
91
|
+
return obj;
|
|
92
|
+
},
|
|
93
|
+
create(base) {
|
|
94
|
+
return PeerMessage.fromPartial(base ?? {});
|
|
95
|
+
},
|
|
96
|
+
fromPartial(object) {
|
|
97
|
+
const message = createBasePeerMessage();
|
|
98
|
+
message.authenticated = (object.authenticated !== undefined && object.authenticated !== null)
|
|
99
|
+
? PeerMessage_Authenticated.fromPartial(object.authenticated)
|
|
100
|
+
: undefined;
|
|
101
|
+
message.authRequest = (object.authRequest !== undefined && object.authRequest !== null)
|
|
102
|
+
? PeerMessage_AuthRequest.fromPartial(object.authRequest)
|
|
103
|
+
: undefined;
|
|
104
|
+
message.mediaEvent = (object.mediaEvent !== undefined && object.mediaEvent !== null)
|
|
105
|
+
? PeerMessage_MediaEvent.fromPartial(object.mediaEvent)
|
|
106
|
+
: undefined;
|
|
107
|
+
message.rtcStatsReport = (object.rtcStatsReport !== undefined && object.rtcStatsReport !== null)
|
|
108
|
+
? PeerMessage_RTCStatsReport.fromPartial(object.rtcStatsReport)
|
|
109
|
+
: undefined;
|
|
110
|
+
return message;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
function createBasePeerMessage_Authenticated() {
|
|
114
|
+
return {};
|
|
115
|
+
}
|
|
116
|
+
export const PeerMessage_Authenticated = {
|
|
117
|
+
encode(_, writer = _m0.Writer.create()) {
|
|
118
|
+
return writer;
|
|
119
|
+
},
|
|
120
|
+
decode(input, length) {
|
|
121
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
122
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
123
|
+
const message = createBasePeerMessage_Authenticated();
|
|
124
|
+
while (reader.pos < end) {
|
|
125
|
+
const tag = reader.uint32();
|
|
126
|
+
switch (tag >>> 3) {
|
|
127
|
+
}
|
|
128
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
reader.skipType(tag & 7);
|
|
132
|
+
}
|
|
133
|
+
return message;
|
|
134
|
+
},
|
|
135
|
+
fromJSON(_) {
|
|
136
|
+
return {};
|
|
137
|
+
},
|
|
138
|
+
toJSON(_) {
|
|
139
|
+
const obj = {};
|
|
140
|
+
return obj;
|
|
141
|
+
},
|
|
142
|
+
create(base) {
|
|
143
|
+
return PeerMessage_Authenticated.fromPartial(base ?? {});
|
|
144
|
+
},
|
|
145
|
+
fromPartial(_) {
|
|
146
|
+
const message = createBasePeerMessage_Authenticated();
|
|
147
|
+
return message;
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
function createBasePeerMessage_AuthRequest() {
|
|
151
|
+
return { token: "" };
|
|
152
|
+
}
|
|
153
|
+
export const PeerMessage_AuthRequest = {
|
|
154
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
155
|
+
if (message.token !== "") {
|
|
156
|
+
writer.uint32(10).string(message.token);
|
|
157
|
+
}
|
|
158
|
+
return writer;
|
|
159
|
+
},
|
|
160
|
+
decode(input, length) {
|
|
161
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
162
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
163
|
+
const message = createBasePeerMessage_AuthRequest();
|
|
164
|
+
while (reader.pos < end) {
|
|
165
|
+
const tag = reader.uint32();
|
|
166
|
+
switch (tag >>> 3) {
|
|
167
|
+
case 1:
|
|
168
|
+
if (tag !== 10) {
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
message.token = reader.string();
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
reader.skipType(tag & 7);
|
|
178
|
+
}
|
|
179
|
+
return message;
|
|
180
|
+
},
|
|
181
|
+
fromJSON(object) {
|
|
182
|
+
return { token: isSet(object.token) ? globalThis.String(object.token) : "" };
|
|
183
|
+
},
|
|
184
|
+
toJSON(message) {
|
|
185
|
+
const obj = {};
|
|
186
|
+
if (message.token !== "") {
|
|
187
|
+
obj.token = message.token;
|
|
188
|
+
}
|
|
189
|
+
return obj;
|
|
190
|
+
},
|
|
191
|
+
create(base) {
|
|
192
|
+
return PeerMessage_AuthRequest.fromPartial(base ?? {});
|
|
193
|
+
},
|
|
194
|
+
fromPartial(object) {
|
|
195
|
+
const message = createBasePeerMessage_AuthRequest();
|
|
196
|
+
message.token = object.token ?? "";
|
|
197
|
+
return message;
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
function createBasePeerMessage_MediaEvent() {
|
|
201
|
+
return { data: "" };
|
|
202
|
+
}
|
|
203
|
+
export const PeerMessage_MediaEvent = {
|
|
204
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
205
|
+
if (message.data !== "") {
|
|
206
|
+
writer.uint32(10).string(message.data);
|
|
207
|
+
}
|
|
208
|
+
return writer;
|
|
209
|
+
},
|
|
210
|
+
decode(input, length) {
|
|
211
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
212
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
213
|
+
const message = createBasePeerMessage_MediaEvent();
|
|
214
|
+
while (reader.pos < end) {
|
|
215
|
+
const tag = reader.uint32();
|
|
216
|
+
switch (tag >>> 3) {
|
|
217
|
+
case 1:
|
|
218
|
+
if (tag !== 10) {
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
message.data = reader.string();
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
reader.skipType(tag & 7);
|
|
228
|
+
}
|
|
229
|
+
return message;
|
|
230
|
+
},
|
|
231
|
+
fromJSON(object) {
|
|
232
|
+
return { data: isSet(object.data) ? globalThis.String(object.data) : "" };
|
|
233
|
+
},
|
|
234
|
+
toJSON(message) {
|
|
235
|
+
const obj = {};
|
|
236
|
+
if (message.data !== "") {
|
|
237
|
+
obj.data = message.data;
|
|
238
|
+
}
|
|
239
|
+
return obj;
|
|
240
|
+
},
|
|
241
|
+
create(base) {
|
|
242
|
+
return PeerMessage_MediaEvent.fromPartial(base ?? {});
|
|
243
|
+
},
|
|
244
|
+
fromPartial(object) {
|
|
245
|
+
const message = createBasePeerMessage_MediaEvent();
|
|
246
|
+
message.data = object.data ?? "";
|
|
247
|
+
return message;
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
function createBasePeerMessage_RTCStatsReport() {
|
|
251
|
+
return { data: "" };
|
|
252
|
+
}
|
|
253
|
+
export const PeerMessage_RTCStatsReport = {
|
|
254
|
+
encode(message, writer = _m0.Writer.create()) {
|
|
255
|
+
if (message.data !== "") {
|
|
256
|
+
writer.uint32(10).string(message.data);
|
|
257
|
+
}
|
|
258
|
+
return writer;
|
|
259
|
+
},
|
|
260
|
+
decode(input, length) {
|
|
261
|
+
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
|
|
262
|
+
let end = length === undefined ? reader.len : reader.pos + length;
|
|
263
|
+
const message = createBasePeerMessage_RTCStatsReport();
|
|
264
|
+
while (reader.pos < end) {
|
|
265
|
+
const tag = reader.uint32();
|
|
266
|
+
switch (tag >>> 3) {
|
|
267
|
+
case 1:
|
|
268
|
+
if (tag !== 10) {
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
message.data = reader.string();
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
reader.skipType(tag & 7);
|
|
278
|
+
}
|
|
279
|
+
return message;
|
|
280
|
+
},
|
|
281
|
+
fromJSON(object) {
|
|
282
|
+
return { data: isSet(object.data) ? globalThis.String(object.data) : "" };
|
|
283
|
+
},
|
|
284
|
+
toJSON(message) {
|
|
285
|
+
const obj = {};
|
|
286
|
+
if (message.data !== "") {
|
|
287
|
+
obj.data = message.data;
|
|
288
|
+
}
|
|
289
|
+
return obj;
|
|
290
|
+
},
|
|
291
|
+
create(base) {
|
|
292
|
+
return PeerMessage_RTCStatsReport.fromPartial(base ?? {});
|
|
293
|
+
},
|
|
294
|
+
fromPartial(object) {
|
|
295
|
+
const message = createBasePeerMessage_RTCStatsReport();
|
|
296
|
+
message.data = object.data ?? "";
|
|
297
|
+
return message;
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
function isSet(value) {
|
|
301
|
+
return value !== null && value !== undefined;
|
|
302
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fishjam/peer_notifications';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './fishjam/peer_notifications';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { FishjamClient } from './FishjamClient';
|
|
2
|
+
export type ReconnectionStatus = 'reconnecting' | 'idle' | 'error';
|
|
3
|
+
export type ReconnectConfig = {
|
|
4
|
+
maxAttempts?: number;
|
|
5
|
+
initialDelay?: number;
|
|
6
|
+
delay?: number;
|
|
7
|
+
addTracksOnReconnect?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare class ReconnectManager<PeerMetadata, TrackMetadata> {
|
|
10
|
+
private readonly reconnectConfig;
|
|
11
|
+
private readonly connect;
|
|
12
|
+
private readonly client;
|
|
13
|
+
private initialMetadata;
|
|
14
|
+
private reconnectAttempt;
|
|
15
|
+
private reconnectTimeoutId;
|
|
16
|
+
private status;
|
|
17
|
+
private lastLocalEndpoint;
|
|
18
|
+
private removeEventListeners;
|
|
19
|
+
constructor(client: FishjamClient<PeerMetadata, TrackMetadata>, connect: (metadata: PeerMetadata) => void, config?: ReconnectConfig | boolean);
|
|
20
|
+
isReconnecting(): boolean;
|
|
21
|
+
reset(initialMetadata: PeerMetadata): void;
|
|
22
|
+
private getLastPeerMetadata;
|
|
23
|
+
private reconnect;
|
|
24
|
+
handleReconnect(): Promise<void>;
|
|
25
|
+
cleanup(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare const createReconnectConfig: (config?: ReconnectConfig | boolean) => Required<ReconnectConfig>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { isAuthError } from './auth';
|
|
2
|
+
const DISABLED_RECONNECT_CONFIG = {
|
|
3
|
+
maxAttempts: 0,
|
|
4
|
+
initialDelay: 0,
|
|
5
|
+
delay: 0,
|
|
6
|
+
addTracksOnReconnect: false,
|
|
7
|
+
};
|
|
8
|
+
const DEFAULT_RECONNECT_CONFIG = {
|
|
9
|
+
maxAttempts: 3,
|
|
10
|
+
initialDelay: 500,
|
|
11
|
+
delay: 500,
|
|
12
|
+
addTracksOnReconnect: true,
|
|
13
|
+
};
|
|
14
|
+
export class ReconnectManager {
|
|
15
|
+
reconnectConfig;
|
|
16
|
+
connect;
|
|
17
|
+
client;
|
|
18
|
+
initialMetadata = undefined;
|
|
19
|
+
reconnectAttempt = 0;
|
|
20
|
+
reconnectTimeoutId = null;
|
|
21
|
+
status = 'idle';
|
|
22
|
+
lastLocalEndpoint = null;
|
|
23
|
+
removeEventListeners = () => { };
|
|
24
|
+
constructor(client, connect, config) {
|
|
25
|
+
this.client = client;
|
|
26
|
+
this.connect = connect;
|
|
27
|
+
this.reconnectConfig = createReconnectConfig(config);
|
|
28
|
+
const onSocketError = () => {
|
|
29
|
+
this.reconnect();
|
|
30
|
+
};
|
|
31
|
+
this.client.on('socketError', onSocketError);
|
|
32
|
+
const onConnectionError = () => {
|
|
33
|
+
this.reconnect();
|
|
34
|
+
};
|
|
35
|
+
this.client.on('connectionError', onConnectionError);
|
|
36
|
+
const onSocketClose = (event) => {
|
|
37
|
+
if (isAuthError(event.reason))
|
|
38
|
+
return;
|
|
39
|
+
this.reconnect();
|
|
40
|
+
};
|
|
41
|
+
this.client.on('socketClose', onSocketClose);
|
|
42
|
+
const onAuthSuccess = () => {
|
|
43
|
+
this.reset(this.initialMetadata);
|
|
44
|
+
};
|
|
45
|
+
this.client.on('authSuccess', onAuthSuccess);
|
|
46
|
+
this.removeEventListeners = () => {
|
|
47
|
+
this.client.off('socketError', onSocketError);
|
|
48
|
+
this.client.off('connectionError', onConnectionError);
|
|
49
|
+
this.client.off('socketClose', onSocketClose);
|
|
50
|
+
this.client.off('authSuccess', onAuthSuccess);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
isReconnecting() {
|
|
54
|
+
return this.status === 'reconnecting';
|
|
55
|
+
}
|
|
56
|
+
reset(initialMetadata) {
|
|
57
|
+
this.initialMetadata = initialMetadata;
|
|
58
|
+
this.reconnectAttempt = 0;
|
|
59
|
+
if (this.reconnectTimeoutId)
|
|
60
|
+
clearTimeout(this.reconnectTimeoutId);
|
|
61
|
+
this.reconnectTimeoutId = null;
|
|
62
|
+
}
|
|
63
|
+
getLastPeerMetadata() {
|
|
64
|
+
return this.lastLocalEndpoint?.metadata;
|
|
65
|
+
}
|
|
66
|
+
reconnect() {
|
|
67
|
+
if (this.reconnectTimeoutId)
|
|
68
|
+
return;
|
|
69
|
+
if (this.reconnectAttempt >= this.reconnectConfig.maxAttempts) {
|
|
70
|
+
if (this.status === 'reconnecting') {
|
|
71
|
+
this.status = 'error';
|
|
72
|
+
this.client.emit('reconnectionRetriesLimitReached');
|
|
73
|
+
}
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (this.status !== 'reconnecting') {
|
|
77
|
+
this.status = 'reconnecting';
|
|
78
|
+
this.client.emit('reconnectionStarted');
|
|
79
|
+
this.lastLocalEndpoint = this.client.getLocalPeer() || null;
|
|
80
|
+
}
|
|
81
|
+
const timeout = this.reconnectConfig.initialDelay +
|
|
82
|
+
this.reconnectAttempt * this.reconnectConfig.delay;
|
|
83
|
+
this.reconnectAttempt += 1;
|
|
84
|
+
this.reconnectTimeoutId = setTimeout(() => {
|
|
85
|
+
this.reconnectTimeoutId = null;
|
|
86
|
+
this.connect(this.getLastPeerMetadata() ?? this.initialMetadata);
|
|
87
|
+
}, timeout);
|
|
88
|
+
}
|
|
89
|
+
async handleReconnect() {
|
|
90
|
+
if (this.status !== 'reconnecting')
|
|
91
|
+
return;
|
|
92
|
+
if (this.lastLocalEndpoint && this.reconnectConfig.addTracksOnReconnect) {
|
|
93
|
+
for await (const element of this.lastLocalEndpoint.tracks) {
|
|
94
|
+
const [_, track] = element;
|
|
95
|
+
if (!track.track || track.track.readyState !== 'live')
|
|
96
|
+
return;
|
|
97
|
+
await this.client.addTrack(track.track, track.rawMetadata, track.simulcastConfig, track.maxBandwidth);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
this.lastLocalEndpoint = null;
|
|
101
|
+
this.status = 'idle';
|
|
102
|
+
this.client.emit('reconnected');
|
|
103
|
+
}
|
|
104
|
+
cleanup() {
|
|
105
|
+
this.removeEventListeners();
|
|
106
|
+
this.removeEventListeners = () => { };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export const createReconnectConfig = (config) => {
|
|
110
|
+
if (!config)
|
|
111
|
+
return DISABLED_RECONNECT_CONFIG;
|
|
112
|
+
if (config === true)
|
|
113
|
+
return DEFAULT_RECONNECT_CONFIG;
|
|
114
|
+
return {
|
|
115
|
+
maxAttempts: config?.maxAttempts ?? DEFAULT_RECONNECT_CONFIG.maxAttempts,
|
|
116
|
+
initialDelay: config?.initialDelay ?? DEFAULT_RECONNECT_CONFIG.initialDelay,
|
|
117
|
+
delay: config?.delay ?? DEFAULT_RECONNECT_CONFIG.delay,
|
|
118
|
+
addTracksOnReconnect: config?.addTracksOnReconnect ??
|
|
119
|
+
DEFAULT_RECONNECT_CONFIG.addTracksOnReconnect,
|
|
120
|
+
};
|
|
121
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Deferred } from './deferred';
|
|
2
|
+
import type { LocalTrackManager } from './tracks/LocalTrackManager';
|
|
3
|
+
import type { ConnectionManager } from './ConnectionManager';
|
|
4
|
+
export type Command = {
|
|
5
|
+
handler: () => void;
|
|
6
|
+
parse?: () => void;
|
|
7
|
+
resolutionNotifier: Deferred<void>;
|
|
8
|
+
resolve: 'after-renegotiation' | 'immediately';
|
|
9
|
+
};
|
|
10
|
+
export declare class CommandsQueue<EndpointMetadata, TrackMetadata> {
|
|
11
|
+
private readonly localTrackManager;
|
|
12
|
+
private connection;
|
|
13
|
+
private clearConnectionCallbacks;
|
|
14
|
+
constructor(localTrackManager: LocalTrackManager<EndpointMetadata, TrackMetadata>);
|
|
15
|
+
initConnection: (connection: ConnectionManager) => void;
|
|
16
|
+
private commandsQueue;
|
|
17
|
+
private commandResolutionNotifier;
|
|
18
|
+
pushCommand: (command: Command) => void;
|
|
19
|
+
processNextCommand: () => void;
|
|
20
|
+
private handleCommand;
|
|
21
|
+
private resolvePreviousCommand;
|
|
22
|
+
cleanUp: () => void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export class CommandsQueue {
|
|
2
|
+
localTrackManager;
|
|
3
|
+
connection = null;
|
|
4
|
+
clearConnectionCallbacks = null;
|
|
5
|
+
constructor(localTrackManager) {
|
|
6
|
+
this.localTrackManager = localTrackManager;
|
|
7
|
+
}
|
|
8
|
+
initConnection = (connection) => {
|
|
9
|
+
this.connection = connection;
|
|
10
|
+
const onSignalingStateChange = () => {
|
|
11
|
+
if (connection.getConnection().signalingState === 'stable') {
|
|
12
|
+
this.processNextCommand();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const onIceGatheringStateChange = () => {
|
|
16
|
+
if (connection.getConnection().iceGatheringState === 'complete') {
|
|
17
|
+
this.processNextCommand();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const onConnectionStateChange = () => {
|
|
21
|
+
if (connection.getConnection().connectionState === 'connected') {
|
|
22
|
+
this.processNextCommand();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const onIceConnectionStateChange = () => {
|
|
26
|
+
if (connection.getConnection().iceConnectionState === 'connected') {
|
|
27
|
+
this.processNextCommand();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
this.clearConnectionCallbacks = () => {
|
|
31
|
+
connection
|
|
32
|
+
.getConnection()
|
|
33
|
+
.removeEventListener('signalingstatechange', onSignalingStateChange);
|
|
34
|
+
connection
|
|
35
|
+
.getConnection()
|
|
36
|
+
.removeEventListener('icegatheringstatechange', onIceGatheringStateChange);
|
|
37
|
+
connection
|
|
38
|
+
.getConnection()
|
|
39
|
+
.removeEventListener('connectionstatechange', onConnectionStateChange);
|
|
40
|
+
connection
|
|
41
|
+
.getConnection()
|
|
42
|
+
.removeEventListener('iceconnectionstatechange', onIceConnectionStateChange);
|
|
43
|
+
};
|
|
44
|
+
connection
|
|
45
|
+
.getConnection()
|
|
46
|
+
.addEventListener('icegatheringstatechange', onIceConnectionStateChange);
|
|
47
|
+
connection
|
|
48
|
+
.getConnection()
|
|
49
|
+
.addEventListener('connectionstatechange', onConnectionStateChange);
|
|
50
|
+
connection
|
|
51
|
+
.getConnection()
|
|
52
|
+
.addEventListener('iceconnectionstatechange', onIceConnectionStateChange);
|
|
53
|
+
connection
|
|
54
|
+
.getConnection()
|
|
55
|
+
.addEventListener('signalingstatechange', onSignalingStateChange);
|
|
56
|
+
};
|
|
57
|
+
commandsQueue = [];
|
|
58
|
+
commandResolutionNotifier = null;
|
|
59
|
+
pushCommand = (command) => {
|
|
60
|
+
this.commandsQueue.push(command);
|
|
61
|
+
this.processNextCommand();
|
|
62
|
+
};
|
|
63
|
+
processNextCommand = () => {
|
|
64
|
+
if (this.localTrackManager.isNegotiationInProgress())
|
|
65
|
+
return;
|
|
66
|
+
if (this.connection?.isConnectionUnstable())
|
|
67
|
+
return;
|
|
68
|
+
this.resolvePreviousCommand();
|
|
69
|
+
const command = this.commandsQueue.shift();
|
|
70
|
+
if (!command)
|
|
71
|
+
return;
|
|
72
|
+
this.commandResolutionNotifier = command.resolutionNotifier;
|
|
73
|
+
this.handleCommand(command);
|
|
74
|
+
};
|
|
75
|
+
handleCommand = (command) => {
|
|
76
|
+
try {
|
|
77
|
+
command.parse?.();
|
|
78
|
+
command.handler();
|
|
79
|
+
if (command.resolve === 'immediately') {
|
|
80
|
+
this.resolvePreviousCommand();
|
|
81
|
+
this.processNextCommand();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
this.commandResolutionNotifier?.reject(error);
|
|
86
|
+
this.commandResolutionNotifier = null;
|
|
87
|
+
this.processNextCommand();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
resolvePreviousCommand = () => {
|
|
91
|
+
if (!this.commandResolutionNotifier)
|
|
92
|
+
return;
|
|
93
|
+
this.commandResolutionNotifier.resolve();
|
|
94
|
+
this.commandResolutionNotifier = null;
|
|
95
|
+
};
|
|
96
|
+
cleanUp = () => {
|
|
97
|
+
this.commandResolutionNotifier?.reject('Disconnected');
|
|
98
|
+
this.commandResolutionNotifier = null;
|
|
99
|
+
this.commandsQueue = [];
|
|
100
|
+
this.clearConnectionCallbacks?.();
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { MediaStreamTrackId } from './types';
|
|
2
|
+
export type TurnServer = {
|
|
3
|
+
transport: string;
|
|
4
|
+
password: string;
|
|
5
|
+
serverAddr: string;
|
|
6
|
+
serverPort: string;
|
|
7
|
+
username: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class ConnectionManager {
|
|
10
|
+
private readonly connection;
|
|
11
|
+
constructor(turnServers: TurnServer[]);
|
|
12
|
+
isConnectionUnstable: () => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Configures TURN servers for WebRTC connections by adding them to the provided RTCConfiguration object.
|
|
15
|
+
*/
|
|
16
|
+
private getIceServers;
|
|
17
|
+
getConnection: () => RTCPeerConnection;
|
|
18
|
+
setTransceiversToReadOnly: () => void;
|
|
19
|
+
addTransceiversIfNeeded: (serverTracks: Map<string, number>) => void;
|
|
20
|
+
private getNeededTransceiversTypes;
|
|
21
|
+
addTransceiver: (track: MediaStreamTrack, transceiverConfig: RTCRtpTransceiverInit) => void;
|
|
22
|
+
setOnTrackReady: (onTrackReady: (event: RTCTrackEvent) => void) => void;
|
|
23
|
+
setRemoteDescription: (data: RTCSessionDescriptionInit) => Promise<void>;
|
|
24
|
+
isTrackInUse: (track: MediaStreamTrack) => boolean;
|
|
25
|
+
setTransceiverDirection: () => void;
|
|
26
|
+
removeTrack: (sender: RTCRtpSender) => void;
|
|
27
|
+
findSender: (mediaStreamTrackId: MediaStreamTrackId) => RTCRtpSender;
|
|
28
|
+
addIceCandidate: (iceCandidate: RTCIceCandidate) => Promise<void>;
|
|
29
|
+
}
|