@auxilium/datalynk-client 1.1.4 → 1.1.6
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 +25 -0
- package/dist/api.d.ts +9 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/index.js +145 -6
- package/dist/index.mjs +145 -6
- package/dist/socket.d.ts +31 -0
- package/dist/socket.d.ts.map +1 -1
- package/dist/webrtc.d.ts +47 -0
- package/dist/webrtc.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -401,3 +401,28 @@ api.files.upload(files).then(uploaded => {
|
|
|
401
401
|
```
|
|
402
402
|
|
|
403
403
|
</details>
|
|
404
|
+
|
|
405
|
+
<details>
|
|
406
|
+
<summary>
|
|
407
|
+
<h3 id="webrtc" style="display: inline">WebRTC</h3>
|
|
408
|
+
</summary>
|
|
409
|
+
|
|
410
|
+
Connect to a WebRTC chatroom to send audio/video to peers
|
|
411
|
+
|
|
412
|
+
```js
|
|
413
|
+
// Video elements to display stream on
|
|
414
|
+
const local = document.querySelector('#video1');
|
|
415
|
+
const remote = document.querySelector('#video1');
|
|
416
|
+
|
|
417
|
+
const roomID = 'TEST_ROOM'
|
|
418
|
+
const session = await api.webrtc.connect('test', (peer) => { // This callback fires everytime a new peer connects
|
|
419
|
+
// Set remote audio/video stream to first track once availible
|
|
420
|
+
const streams = peer.stream.getRemoteStreams();
|
|
421
|
+
if(streams[0]) remoteVideo.srcObject = streams[0];
|
|
422
|
+
else peer.stream.ontrack = ({streams}) => remoteVideo.srcObject = streams[0];
|
|
423
|
+
}, true, false); // audio = true, video = false
|
|
424
|
+
local.srcObject = session.stream; // Set local audio/video stream
|
|
425
|
+
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
</details>
|
package/dist/api.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { Pdf } from './pdf';
|
|
|
7
7
|
import { ApiCall, Slice } from './slice';
|
|
8
8
|
import { Socket } from './socket';
|
|
9
9
|
import { Superuser } from './superuser';
|
|
10
|
+
import { WebRtc } from './webrtc';
|
|
10
11
|
export type JwtPayload = {
|
|
11
12
|
aud: string;
|
|
12
13
|
email: string;
|
|
@@ -41,6 +42,12 @@ export type ApiOptions = {
|
|
|
41
42
|
serviceWorker?: string;
|
|
42
43
|
/** Disable sockets with false or override socket URL */
|
|
43
44
|
socket?: false | string;
|
|
45
|
+
/** WebRTC TURN server URL */
|
|
46
|
+
webrtc?: {
|
|
47
|
+
url: string;
|
|
48
|
+
username?: string;
|
|
49
|
+
password?: string;
|
|
50
|
+
};
|
|
44
51
|
};
|
|
45
52
|
/**
|
|
46
53
|
* Possible options for API calls
|
|
@@ -90,6 +97,8 @@ export declare class Api {
|
|
|
90
97
|
readonly socket: Socket;
|
|
91
98
|
/** Superuser */
|
|
92
99
|
readonly superuser: Superuser;
|
|
100
|
+
/** WebRTC */
|
|
101
|
+
readonly webrtc: WebRtc;
|
|
93
102
|
/** Offline database */
|
|
94
103
|
database?: Database;
|
|
95
104
|
/** Options */
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoD,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAC,eAAe,EAAuB,MAAM,MAAM,CAAC;AAC3D,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,SAAS,CAAC;AACvC,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC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CAAC,IAAI,CAAC;IAsBjB;;;;OAIG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAS3B;;;;;;OAMG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW;IAIrE;;;;OAIG;IACH,MAAM,CAAC,MAAM,UAAO;gBAEe,MAAM;aAAO,MAAM;;IAOtD;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAavD;;;;;;OAMG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,KAAK,GAAG,OAAO;CAI3D"}
|
package/dist/index.js
CHANGED
|
@@ -274,6 +274,26 @@ function contrast(background) {
|
|
|
274
274
|
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
275
275
|
return luminance > 0.5 ? "black" : "white";
|
|
276
276
|
}
|
|
277
|
+
const LETTER_LIST = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
278
|
+
const NUMBER_LIST = "0123456789";
|
|
279
|
+
const SYMBOL_LIST = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/";
|
|
280
|
+
function randomStringBuilder(length, letters = false, numbers = false, symbols = false) {
|
|
281
|
+
if (!letters && !numbers && !symbols) throw new Error("Must enable at least one: letters, numbers, symbols");
|
|
282
|
+
return Array(length).fill(null).map(() => {
|
|
283
|
+
let c;
|
|
284
|
+
do {
|
|
285
|
+
const type = ~~(Math.random() * 3);
|
|
286
|
+
if (letters && type == 0) {
|
|
287
|
+
c = LETTER_LIST[~~(Math.random() * LETTER_LIST.length)];
|
|
288
|
+
} else if (numbers && type == 1) {
|
|
289
|
+
c = NUMBER_LIST[~~(Math.random() * NUMBER_LIST.length)];
|
|
290
|
+
} else if (symbols && type == 2) {
|
|
291
|
+
c = SYMBOL_LIST[~~(Math.random() * SYMBOL_LIST.length)];
|
|
292
|
+
}
|
|
293
|
+
} while (!c);
|
|
294
|
+
return c;
|
|
295
|
+
}).join("");
|
|
296
|
+
}
|
|
277
297
|
class PromiseProgress extends Promise {
|
|
278
298
|
constructor(executor) {
|
|
279
299
|
super((resolve, reject) => executor(
|
|
@@ -2261,9 +2281,10 @@ class Auth {
|
|
|
2261
2281
|
*
|
|
2262
2282
|
* @return {Promise<{closed: string, new: string}>}
|
|
2263
2283
|
*/
|
|
2264
|
-
logout() {
|
|
2284
|
+
logout(reload = true) {
|
|
2265
2285
|
localStorage.removeItem("datalynk-user");
|
|
2266
2286
|
return this.api.request({ "$/auth/logout": {} }).then((resp) => {
|
|
2287
|
+
if (reload) location.reload();
|
|
2267
2288
|
this.api.token = null;
|
|
2268
2289
|
return resp;
|
|
2269
2290
|
});
|
|
@@ -3110,10 +3131,15 @@ class Socket {
|
|
|
3110
3131
|
* Add listener for all socket events
|
|
3111
3132
|
*
|
|
3112
3133
|
* @param {SocketListener} fn Callback function
|
|
3134
|
+
*
|
|
3135
|
+
*
|
|
3136
|
+
*
|
|
3137
|
+
*
|
|
3113
3138
|
* @return {Unsubscribe} Function to unsubscribe callback
|
|
3114
3139
|
*/
|
|
3115
3140
|
addListener(fn, reconnect) {
|
|
3116
3141
|
this.listeners.push([fn, reconnect]);
|
|
3142
|
+
if (this.open) reconnect();
|
|
3117
3143
|
return () => this.listeners = this.listeners.filter((l) => l[0] != fn);
|
|
3118
3144
|
}
|
|
3119
3145
|
/**
|
|
@@ -3141,7 +3167,7 @@ class Socket {
|
|
|
3141
3167
|
this.connect();
|
|
3142
3168
|
}, timeout * 1e3);
|
|
3143
3169
|
if (navigator.onLine) {
|
|
3144
|
-
this.socket = new WebSocket(this.options.url + (this.api.token ? `?token=${this.api.token}` : ""));
|
|
3170
|
+
this.socket = new WebSocket(this.options.url + (this.api.token ? `?token=${this.api.token}&origin=${location.href}` : ""));
|
|
3145
3171
|
this.socket.onopen = () => clearTimeout(this.retry);
|
|
3146
3172
|
this.socket.onclose = () => {
|
|
3147
3173
|
if (this.open) this.connect(timeout);
|
|
@@ -3180,11 +3206,9 @@ class Socket {
|
|
|
3180
3206
|
* @return {Unsubscribe} Run returned function to unsubscribe callback
|
|
3181
3207
|
*/
|
|
3182
3208
|
sliceEvents(slice, callback) {
|
|
3183
|
-
const listen = () => this.send({ onSliceEvents: slice });
|
|
3184
|
-
if (this.open) listen();
|
|
3185
3209
|
const unsubscribe = this.addListener((event) => {
|
|
3186
3210
|
if (event.type == "sliceEvents" && event.data.slice == slice) callback(event);
|
|
3187
|
-
}, () =>
|
|
3211
|
+
}, () => this.send({ onSliceEvents: slice }));
|
|
3188
3212
|
return () => {
|
|
3189
3213
|
this.send({ offSliceEvents: slice });
|
|
3190
3214
|
unsubscribe();
|
|
@@ -3221,7 +3245,114 @@ class Superuser {
|
|
|
3221
3245
|
} });
|
|
3222
3246
|
}
|
|
3223
3247
|
}
|
|
3224
|
-
const version = "1.1.
|
|
3248
|
+
const version = "1.1.6";
|
|
3249
|
+
class WebRtc {
|
|
3250
|
+
constructor(api) {
|
|
3251
|
+
__publicField(this, "ice");
|
|
3252
|
+
var _a, _b, _c;
|
|
3253
|
+
this.api = api;
|
|
3254
|
+
this.ice = clean({
|
|
3255
|
+
urls: [(_a = this.api.options.webrtc) == null ? void 0 : _a.url],
|
|
3256
|
+
username: (_b = this.api.options.webrtc) == null ? void 0 : _b.username,
|
|
3257
|
+
credential: (_c = this.api.options.webrtc) == null ? void 0 : _c.password
|
|
3258
|
+
});
|
|
3259
|
+
}
|
|
3260
|
+
async answer(offer, stream) {
|
|
3261
|
+
const rtc = new RTCPeerConnection({ iceServers: [this.ice] });
|
|
3262
|
+
stream.getTracks().forEach((track) => rtc.addTrack(track, stream));
|
|
3263
|
+
await rtc.setRemoteDescription(new RTCSessionDescription(offer));
|
|
3264
|
+
const answer = await rtc.createAnswer();
|
|
3265
|
+
await rtc.setLocalDescription(answer);
|
|
3266
|
+
await new Promise((res) => {
|
|
3267
|
+
if (rtc.iceGatheringState === "complete") return res();
|
|
3268
|
+
rtc.onicegatheringstatechange = () => {
|
|
3269
|
+
if (rtc.iceGatheringState === "complete") res();
|
|
3270
|
+
};
|
|
3271
|
+
});
|
|
3272
|
+
return rtc;
|
|
3273
|
+
}
|
|
3274
|
+
async offer(stream) {
|
|
3275
|
+
const rtc = new RTCPeerConnection({ iceServers: [this.ice] });
|
|
3276
|
+
stream.getTracks().forEach((track) => rtc.addTrack(track, stream));
|
|
3277
|
+
await rtc.setLocalDescription(await rtc.createOffer());
|
|
3278
|
+
await new Promise((res) => {
|
|
3279
|
+
if (rtc.iceGatheringState === "complete") return res();
|
|
3280
|
+
rtc.onicegatheringstatechange = () => {
|
|
3281
|
+
if (rtc.iceGatheringState === "complete") res();
|
|
3282
|
+
};
|
|
3283
|
+
});
|
|
3284
|
+
return rtc;
|
|
3285
|
+
}
|
|
3286
|
+
/**
|
|
3287
|
+
* Create a new WebRTC connection to a room
|
|
3288
|
+
* @param {string} id Room ID
|
|
3289
|
+
* @param {(peer) => any} onConnect Callback when peers connect
|
|
3290
|
+
* @param {boolean} audio Stream local audio to room/peers
|
|
3291
|
+
* @param {boolean} video Stream local video to room/peers
|
|
3292
|
+
* @returns {Promise<WebRTCSession>} Connection session
|
|
3293
|
+
*/
|
|
3294
|
+
async connect(id = randomStringBuilder(16, true, true), onConnect, audio = true, video = true) {
|
|
3295
|
+
const session = {
|
|
3296
|
+
open: true,
|
|
3297
|
+
id,
|
|
3298
|
+
uid: randomStringBuilder(8, true, true),
|
|
3299
|
+
peers: {},
|
|
3300
|
+
stream: await navigator.mediaDevices.getUserMedia({ audio, video }),
|
|
3301
|
+
disconnect: null
|
|
3302
|
+
};
|
|
3303
|
+
const unsubscribe = this.api.socket.addListener(async (event) => {
|
|
3304
|
+
var _a, _b, _c, _d;
|
|
3305
|
+
const key = Object.keys(event)[0];
|
|
3306
|
+
if (key == `webrtc/${id}`) {
|
|
3307
|
+
if (event[key].connected) {
|
|
3308
|
+
const payload = event[key].connected;
|
|
3309
|
+
session.peers[payload.uid] = {
|
|
3310
|
+
uid: payload.uid,
|
|
3311
|
+
username: payload.username,
|
|
3312
|
+
stream: await this.offer(session.stream)
|
|
3313
|
+
};
|
|
3314
|
+
this.api.socket.send({ [`webrtc/${id}`]: { offer: {
|
|
3315
|
+
to: payload.uid,
|
|
3316
|
+
uid: session.uid,
|
|
3317
|
+
username: (_a = this.api.auth.user) == null ? void 0 : _a.login,
|
|
3318
|
+
offer: session.peers[payload.uid].stream.localDescription
|
|
3319
|
+
} } });
|
|
3320
|
+
} else if (event[key].disconnected) {
|
|
3321
|
+
session.peers[event[key].disconnected.uid].stream.close();
|
|
3322
|
+
delete session.peers[event[key].disconnected.uid];
|
|
3323
|
+
} else if (event[key].offer && event[key].offer.to == session.uid) {
|
|
3324
|
+
const payload = event[key].offer;
|
|
3325
|
+
session.peers[payload.uid] = {
|
|
3326
|
+
uid: payload.uid,
|
|
3327
|
+
username: payload.username,
|
|
3328
|
+
stream: await this.answer(payload.offer, session.stream)
|
|
3329
|
+
};
|
|
3330
|
+
this.api.socket.send({ [`webrtc/${id}`]: { answer: {
|
|
3331
|
+
to: payload.uid,
|
|
3332
|
+
uid: session.uid,
|
|
3333
|
+
username: (_b = this.api.auth.user) == null ? void 0 : _b.login,
|
|
3334
|
+
answer: session.peers[payload.uid].stream.localDescription
|
|
3335
|
+
} } });
|
|
3336
|
+
if (onConnect) onConnect(session.peers[payload.uid]);
|
|
3337
|
+
} else if (event[key].answer && event[key].answer.to == session.uid) {
|
|
3338
|
+
(_d = (_c = session.peers[event[key].answer.uid]) == null ? void 0 : _c.stream) == null ? void 0 : _d.setRemoteDescription(new RTCSessionDescription(event[key].answer.answer));
|
|
3339
|
+
if (onConnect) onConnect(session.peers[event[key].answer.uid]);
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
}, () => {
|
|
3343
|
+
var _a;
|
|
3344
|
+
return this.api.socket.send({ [`webrtc/${id}`]: { connected: { uid: session.uid, username: (_a = this.api.auth.user) == null ? void 0 : _a.login } } });
|
|
3345
|
+
});
|
|
3346
|
+
session.disconnect = () => {
|
|
3347
|
+
var _a;
|
|
3348
|
+
session.open = false;
|
|
3349
|
+
session.peers = {};
|
|
3350
|
+
this.api.socket.send({ [`webrtc/${id}`]: { disconnected: { uid: session.uid, username: (_a = this.api.auth.user) == null ? void 0 : _a.login } } });
|
|
3351
|
+
unsubscribe();
|
|
3352
|
+
};
|
|
3353
|
+
return session;
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3225
3356
|
const _Api = class _Api {
|
|
3226
3357
|
/**
|
|
3227
3358
|
* Connect to Datalynk & send requests
|
|
@@ -3254,6 +3385,8 @@ const _Api = class _Api {
|
|
|
3254
3385
|
__publicField(this, "socket");
|
|
3255
3386
|
/** Superuser */
|
|
3256
3387
|
__publicField(this, "superuser");
|
|
3388
|
+
/** WebRTC */
|
|
3389
|
+
__publicField(this, "webrtc");
|
|
3257
3390
|
/** Offline database */
|
|
3258
3391
|
__publicField(this, "database");
|
|
3259
3392
|
/** Options */
|
|
@@ -3276,6 +3409,11 @@ const _Api = class _Api {
|
|
|
3276
3409
|
origin: typeof location !== "undefined" ? location.host : "Unknown",
|
|
3277
3410
|
saveSession: true,
|
|
3278
3411
|
serviceWorker: "/service.worker.mjs",
|
|
3412
|
+
webrtc: {
|
|
3413
|
+
url: "turn:scarborough.auxilium.world:3478",
|
|
3414
|
+
username: "auxilium-webrtc",
|
|
3415
|
+
password: "UU3qkD95Tg54eF"
|
|
3416
|
+
},
|
|
3279
3417
|
...options
|
|
3280
3418
|
};
|
|
3281
3419
|
if (this.options.saveSession) {
|
|
@@ -3291,6 +3429,7 @@ const _Api = class _Api {
|
|
|
3291
3429
|
this.files = new Files(this);
|
|
3292
3430
|
this.pdf = new Pdf(this);
|
|
3293
3431
|
this.superuser = new Superuser(this);
|
|
3432
|
+
this.webrtc = new WebRtc(this);
|
|
3294
3433
|
if ((_a = this.options.offline) == null ? void 0 : _a.length) {
|
|
3295
3434
|
if (typeof indexedDB == "undefined") throw new Error("Cannot enable offline support, indexedDB is not available in this environment");
|
|
3296
3435
|
this.database = new Database("datalynk", this.options.offline);
|
package/dist/index.mjs
CHANGED
|
@@ -272,6 +272,26 @@ function contrast(background) {
|
|
|
272
272
|
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
273
273
|
return luminance > 0.5 ? "black" : "white";
|
|
274
274
|
}
|
|
275
|
+
const LETTER_LIST = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
276
|
+
const NUMBER_LIST = "0123456789";
|
|
277
|
+
const SYMBOL_LIST = "~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/";
|
|
278
|
+
function randomStringBuilder(length, letters = false, numbers = false, symbols = false) {
|
|
279
|
+
if (!letters && !numbers && !symbols) throw new Error("Must enable at least one: letters, numbers, symbols");
|
|
280
|
+
return Array(length).fill(null).map(() => {
|
|
281
|
+
let c;
|
|
282
|
+
do {
|
|
283
|
+
const type = ~~(Math.random() * 3);
|
|
284
|
+
if (letters && type == 0) {
|
|
285
|
+
c = LETTER_LIST[~~(Math.random() * LETTER_LIST.length)];
|
|
286
|
+
} else if (numbers && type == 1) {
|
|
287
|
+
c = NUMBER_LIST[~~(Math.random() * NUMBER_LIST.length)];
|
|
288
|
+
} else if (symbols && type == 2) {
|
|
289
|
+
c = SYMBOL_LIST[~~(Math.random() * SYMBOL_LIST.length)];
|
|
290
|
+
}
|
|
291
|
+
} while (!c);
|
|
292
|
+
return c;
|
|
293
|
+
}).join("");
|
|
294
|
+
}
|
|
275
295
|
class PromiseProgress extends Promise {
|
|
276
296
|
constructor(executor) {
|
|
277
297
|
super((resolve, reject) => executor(
|
|
@@ -2259,9 +2279,10 @@ class Auth {
|
|
|
2259
2279
|
*
|
|
2260
2280
|
* @return {Promise<{closed: string, new: string}>}
|
|
2261
2281
|
*/
|
|
2262
|
-
logout() {
|
|
2282
|
+
logout(reload = true) {
|
|
2263
2283
|
localStorage.removeItem("datalynk-user");
|
|
2264
2284
|
return this.api.request({ "$/auth/logout": {} }).then((resp) => {
|
|
2285
|
+
if (reload) location.reload();
|
|
2265
2286
|
this.api.token = null;
|
|
2266
2287
|
return resp;
|
|
2267
2288
|
});
|
|
@@ -3108,10 +3129,15 @@ class Socket {
|
|
|
3108
3129
|
* Add listener for all socket events
|
|
3109
3130
|
*
|
|
3110
3131
|
* @param {SocketListener} fn Callback function
|
|
3132
|
+
*
|
|
3133
|
+
*
|
|
3134
|
+
*
|
|
3135
|
+
*
|
|
3111
3136
|
* @return {Unsubscribe} Function to unsubscribe callback
|
|
3112
3137
|
*/
|
|
3113
3138
|
addListener(fn, reconnect) {
|
|
3114
3139
|
this.listeners.push([fn, reconnect]);
|
|
3140
|
+
if (this.open) reconnect();
|
|
3115
3141
|
return () => this.listeners = this.listeners.filter((l) => l[0] != fn);
|
|
3116
3142
|
}
|
|
3117
3143
|
/**
|
|
@@ -3139,7 +3165,7 @@ class Socket {
|
|
|
3139
3165
|
this.connect();
|
|
3140
3166
|
}, timeout * 1e3);
|
|
3141
3167
|
if (navigator.onLine) {
|
|
3142
|
-
this.socket = new WebSocket(this.options.url + (this.api.token ? `?token=${this.api.token}` : ""));
|
|
3168
|
+
this.socket = new WebSocket(this.options.url + (this.api.token ? `?token=${this.api.token}&origin=${location.href}` : ""));
|
|
3143
3169
|
this.socket.onopen = () => clearTimeout(this.retry);
|
|
3144
3170
|
this.socket.onclose = () => {
|
|
3145
3171
|
if (this.open) this.connect(timeout);
|
|
@@ -3178,11 +3204,9 @@ class Socket {
|
|
|
3178
3204
|
* @return {Unsubscribe} Run returned function to unsubscribe callback
|
|
3179
3205
|
*/
|
|
3180
3206
|
sliceEvents(slice, callback) {
|
|
3181
|
-
const listen = () => this.send({ onSliceEvents: slice });
|
|
3182
|
-
if (this.open) listen();
|
|
3183
3207
|
const unsubscribe = this.addListener((event) => {
|
|
3184
3208
|
if (event.type == "sliceEvents" && event.data.slice == slice) callback(event);
|
|
3185
|
-
}, () =>
|
|
3209
|
+
}, () => this.send({ onSliceEvents: slice }));
|
|
3186
3210
|
return () => {
|
|
3187
3211
|
this.send({ offSliceEvents: slice });
|
|
3188
3212
|
unsubscribe();
|
|
@@ -3219,7 +3243,114 @@ class Superuser {
|
|
|
3219
3243
|
} });
|
|
3220
3244
|
}
|
|
3221
3245
|
}
|
|
3222
|
-
const version = "1.1.
|
|
3246
|
+
const version = "1.1.6";
|
|
3247
|
+
class WebRtc {
|
|
3248
|
+
constructor(api) {
|
|
3249
|
+
__publicField(this, "ice");
|
|
3250
|
+
var _a, _b, _c;
|
|
3251
|
+
this.api = api;
|
|
3252
|
+
this.ice = clean({
|
|
3253
|
+
urls: [(_a = this.api.options.webrtc) == null ? void 0 : _a.url],
|
|
3254
|
+
username: (_b = this.api.options.webrtc) == null ? void 0 : _b.username,
|
|
3255
|
+
credential: (_c = this.api.options.webrtc) == null ? void 0 : _c.password
|
|
3256
|
+
});
|
|
3257
|
+
}
|
|
3258
|
+
async answer(offer, stream) {
|
|
3259
|
+
const rtc = new RTCPeerConnection({ iceServers: [this.ice] });
|
|
3260
|
+
stream.getTracks().forEach((track) => rtc.addTrack(track, stream));
|
|
3261
|
+
await rtc.setRemoteDescription(new RTCSessionDescription(offer));
|
|
3262
|
+
const answer = await rtc.createAnswer();
|
|
3263
|
+
await rtc.setLocalDescription(answer);
|
|
3264
|
+
await new Promise((res) => {
|
|
3265
|
+
if (rtc.iceGatheringState === "complete") return res();
|
|
3266
|
+
rtc.onicegatheringstatechange = () => {
|
|
3267
|
+
if (rtc.iceGatheringState === "complete") res();
|
|
3268
|
+
};
|
|
3269
|
+
});
|
|
3270
|
+
return rtc;
|
|
3271
|
+
}
|
|
3272
|
+
async offer(stream) {
|
|
3273
|
+
const rtc = new RTCPeerConnection({ iceServers: [this.ice] });
|
|
3274
|
+
stream.getTracks().forEach((track) => rtc.addTrack(track, stream));
|
|
3275
|
+
await rtc.setLocalDescription(await rtc.createOffer());
|
|
3276
|
+
await new Promise((res) => {
|
|
3277
|
+
if (rtc.iceGatheringState === "complete") return res();
|
|
3278
|
+
rtc.onicegatheringstatechange = () => {
|
|
3279
|
+
if (rtc.iceGatheringState === "complete") res();
|
|
3280
|
+
};
|
|
3281
|
+
});
|
|
3282
|
+
return rtc;
|
|
3283
|
+
}
|
|
3284
|
+
/**
|
|
3285
|
+
* Create a new WebRTC connection to a room
|
|
3286
|
+
* @param {string} id Room ID
|
|
3287
|
+
* @param {(peer) => any} onConnect Callback when peers connect
|
|
3288
|
+
* @param {boolean} audio Stream local audio to room/peers
|
|
3289
|
+
* @param {boolean} video Stream local video to room/peers
|
|
3290
|
+
* @returns {Promise<WebRTCSession>} Connection session
|
|
3291
|
+
*/
|
|
3292
|
+
async connect(id = randomStringBuilder(16, true, true), onConnect, audio = true, video = true) {
|
|
3293
|
+
const session = {
|
|
3294
|
+
open: true,
|
|
3295
|
+
id,
|
|
3296
|
+
uid: randomStringBuilder(8, true, true),
|
|
3297
|
+
peers: {},
|
|
3298
|
+
stream: await navigator.mediaDevices.getUserMedia({ audio, video }),
|
|
3299
|
+
disconnect: null
|
|
3300
|
+
};
|
|
3301
|
+
const unsubscribe = this.api.socket.addListener(async (event) => {
|
|
3302
|
+
var _a, _b, _c, _d;
|
|
3303
|
+
const key = Object.keys(event)[0];
|
|
3304
|
+
if (key == `webrtc/${id}`) {
|
|
3305
|
+
if (event[key].connected) {
|
|
3306
|
+
const payload = event[key].connected;
|
|
3307
|
+
session.peers[payload.uid] = {
|
|
3308
|
+
uid: payload.uid,
|
|
3309
|
+
username: payload.username,
|
|
3310
|
+
stream: await this.offer(session.stream)
|
|
3311
|
+
};
|
|
3312
|
+
this.api.socket.send({ [`webrtc/${id}`]: { offer: {
|
|
3313
|
+
to: payload.uid,
|
|
3314
|
+
uid: session.uid,
|
|
3315
|
+
username: (_a = this.api.auth.user) == null ? void 0 : _a.login,
|
|
3316
|
+
offer: session.peers[payload.uid].stream.localDescription
|
|
3317
|
+
} } });
|
|
3318
|
+
} else if (event[key].disconnected) {
|
|
3319
|
+
session.peers[event[key].disconnected.uid].stream.close();
|
|
3320
|
+
delete session.peers[event[key].disconnected.uid];
|
|
3321
|
+
} else if (event[key].offer && event[key].offer.to == session.uid) {
|
|
3322
|
+
const payload = event[key].offer;
|
|
3323
|
+
session.peers[payload.uid] = {
|
|
3324
|
+
uid: payload.uid,
|
|
3325
|
+
username: payload.username,
|
|
3326
|
+
stream: await this.answer(payload.offer, session.stream)
|
|
3327
|
+
};
|
|
3328
|
+
this.api.socket.send({ [`webrtc/${id}`]: { answer: {
|
|
3329
|
+
to: payload.uid,
|
|
3330
|
+
uid: session.uid,
|
|
3331
|
+
username: (_b = this.api.auth.user) == null ? void 0 : _b.login,
|
|
3332
|
+
answer: session.peers[payload.uid].stream.localDescription
|
|
3333
|
+
} } });
|
|
3334
|
+
if (onConnect) onConnect(session.peers[payload.uid]);
|
|
3335
|
+
} else if (event[key].answer && event[key].answer.to == session.uid) {
|
|
3336
|
+
(_d = (_c = session.peers[event[key].answer.uid]) == null ? void 0 : _c.stream) == null ? void 0 : _d.setRemoteDescription(new RTCSessionDescription(event[key].answer.answer));
|
|
3337
|
+
if (onConnect) onConnect(session.peers[event[key].answer.uid]);
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
}, () => {
|
|
3341
|
+
var _a;
|
|
3342
|
+
return this.api.socket.send({ [`webrtc/${id}`]: { connected: { uid: session.uid, username: (_a = this.api.auth.user) == null ? void 0 : _a.login } } });
|
|
3343
|
+
});
|
|
3344
|
+
session.disconnect = () => {
|
|
3345
|
+
var _a;
|
|
3346
|
+
session.open = false;
|
|
3347
|
+
session.peers = {};
|
|
3348
|
+
this.api.socket.send({ [`webrtc/${id}`]: { disconnected: { uid: session.uid, username: (_a = this.api.auth.user) == null ? void 0 : _a.login } } });
|
|
3349
|
+
unsubscribe();
|
|
3350
|
+
};
|
|
3351
|
+
return session;
|
|
3352
|
+
}
|
|
3353
|
+
}
|
|
3223
3354
|
const _Api = class _Api {
|
|
3224
3355
|
/**
|
|
3225
3356
|
* Connect to Datalynk & send requests
|
|
@@ -3252,6 +3383,8 @@ const _Api = class _Api {
|
|
|
3252
3383
|
__publicField(this, "socket");
|
|
3253
3384
|
/** Superuser */
|
|
3254
3385
|
__publicField(this, "superuser");
|
|
3386
|
+
/** WebRTC */
|
|
3387
|
+
__publicField(this, "webrtc");
|
|
3255
3388
|
/** Offline database */
|
|
3256
3389
|
__publicField(this, "database");
|
|
3257
3390
|
/** Options */
|
|
@@ -3274,6 +3407,11 @@ const _Api = class _Api {
|
|
|
3274
3407
|
origin: typeof location !== "undefined" ? location.host : "Unknown",
|
|
3275
3408
|
saveSession: true,
|
|
3276
3409
|
serviceWorker: "/service.worker.mjs",
|
|
3410
|
+
webrtc: {
|
|
3411
|
+
url: "turn:scarborough.auxilium.world:3478",
|
|
3412
|
+
username: "auxilium-webrtc",
|
|
3413
|
+
password: "UU3qkD95Tg54eF"
|
|
3414
|
+
},
|
|
3277
3415
|
...options
|
|
3278
3416
|
};
|
|
3279
3417
|
if (this.options.saveSession) {
|
|
@@ -3289,6 +3427,7 @@ const _Api = class _Api {
|
|
|
3289
3427
|
this.files = new Files(this);
|
|
3290
3428
|
this.pdf = new Pdf(this);
|
|
3291
3429
|
this.superuser = new Superuser(this);
|
|
3430
|
+
this.webrtc = new WebRtc(this);
|
|
3292
3431
|
if ((_a = this.options.offline) == null ? void 0 : _a.length) {
|
|
3293
3432
|
if (typeof indexedDB == "undefined") throw new Error("Cannot enable offline support, indexedDB is not available in this environment");
|
|
3294
3433
|
this.database = new Database("datalynk", this.options.offline);
|
package/dist/socket.d.ts
CHANGED
|
@@ -12,6 +12,33 @@ export type SocketEventSlice = SocketEvent<{
|
|
|
12
12
|
lost: number[];
|
|
13
13
|
changed: number[];
|
|
14
14
|
}>;
|
|
15
|
+
export type WebRTCEvent = {
|
|
16
|
+
type: string;
|
|
17
|
+
} & ({
|
|
18
|
+
connected: {
|
|
19
|
+
uid: string;
|
|
20
|
+
username: string;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
disconnected: {
|
|
24
|
+
uid: string;
|
|
25
|
+
username: string;
|
|
26
|
+
};
|
|
27
|
+
} | {
|
|
28
|
+
offer: {
|
|
29
|
+
to: string;
|
|
30
|
+
uid: string;
|
|
31
|
+
username: string;
|
|
32
|
+
offer: RTCSessionDescriptionInit;
|
|
33
|
+
};
|
|
34
|
+
} | {
|
|
35
|
+
answer: {
|
|
36
|
+
to: string;
|
|
37
|
+
uid: string;
|
|
38
|
+
username: string;
|
|
39
|
+
offer: RTCSessionDescriptionInit;
|
|
40
|
+
};
|
|
41
|
+
});
|
|
15
42
|
/** Connection options */
|
|
16
43
|
export type SocketOptions = {
|
|
17
44
|
/** Set connection URL or disable with false */
|
|
@@ -34,6 +61,10 @@ export declare class Socket {
|
|
|
34
61
|
* Add listener for all socket events
|
|
35
62
|
*
|
|
36
63
|
* @param {SocketListener} fn Callback function
|
|
64
|
+
*
|
|
65
|
+
*
|
|
66
|
+
*
|
|
67
|
+
*
|
|
37
68
|
* @return {Unsubscribe} Function to unsubscribe callback
|
|
38
69
|
*/
|
|
39
70
|
addListener(fn: SocketListener, reconnect: () => void): Unsubscribe;
|
package/dist/socket.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../src/socket.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,CAAC,CAAA;CACP,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,M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
+
import { Api } from './api';
|
|
3
|
+
/** WebRTC session */
|
|
4
|
+
export type WebRTCSession = {
|
|
5
|
+
/** Is the connection active? */
|
|
6
|
+
open: boolean;
|
|
7
|
+
/** Room ID */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Connection UID */
|
|
10
|
+
uid: string;
|
|
11
|
+
/** Local media stream */
|
|
12
|
+
stream: MediaStream;
|
|
13
|
+
/** Connected peers */
|
|
14
|
+
peers: {
|
|
15
|
+
[key: string]: {
|
|
16
|
+
/** Peer connection UID */
|
|
17
|
+
uid: string;
|
|
18
|
+
/** Peer username */
|
|
19
|
+
username: string;
|
|
20
|
+
/** Remote connection to stream */
|
|
21
|
+
stream: RTCPeerConnection;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
/** Disconnection session */
|
|
25
|
+
disconnect: Unsubscribe;
|
|
26
|
+
};
|
|
27
|
+
export declare class WebRtc {
|
|
28
|
+
private api;
|
|
29
|
+
readonly ice: {
|
|
30
|
+
urls: string[];
|
|
31
|
+
username?: string;
|
|
32
|
+
credential?: string;
|
|
33
|
+
};
|
|
34
|
+
constructor(api: Api);
|
|
35
|
+
private answer;
|
|
36
|
+
private offer;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new WebRTC connection to a room
|
|
39
|
+
* @param {string} id Room ID
|
|
40
|
+
* @param {(peer) => any} onConnect Callback when peers connect
|
|
41
|
+
* @param {boolean} audio Stream local audio to room/peers
|
|
42
|
+
* @param {boolean} video Stream local video to room/peers
|
|
43
|
+
* @returns {Promise<WebRTCSession>} Connection session
|
|
44
|
+
*/
|
|
45
|
+
connect(id?: string, onConnect?: (peer: any) => any, audio?: boolean, video?: boolean): Promise<WebRTCSession>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=webrtc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webrtc.d.ts","sourceRoot":"","sources":["../src/webrtc.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,WAAW,EAAC,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAE1B,qBAAqB;AACrB,MAAM,MAAM,aAAa,GAAG;IAC3B,gCAAgC;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,cAAc;IACd,EAAE,EAAE,MAAM,CAAC;IACX,qBAAqB;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,MAAM,EAAE,WAAW,CAAC;IACpB,sBAAsB;IACtB,KAAK,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG;YACtB,0BAA0B;YAC1B,GAAG,EAAE,MAAM,CAAC;YACZ,oBAAoB;YACpB,QAAQ,EAAE,MAAM,CAAC;YACjB,kCAAkC;YAClC,MAAM,EAAE,iBAAiB,CAAA;SACzB,CAAA;KAAC,CAAA;IACF,4BAA4B;IAC5B,UAAU,EAAE,WAAW,CAAA;CACvB,CAAA;AAED,qBAAa,MAAM;IAGN,OAAO,CAAC,GAAG;IAFvB,SAAgB,GAAG,EAAG;QAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;gBAE3D,GAAG,EAAE,GAAG;YAQd,MAAM;YAaN,KAAK;IAWnB;;;;;;;OAOG;IACG,OAAO,CAAC,EAAE,GAAE,MAA4C,EAAE,SAAS,CAAC,EAAE,CAAC,IAAI,KAAA,KAAK,GAAG,EAAE,KAAK,UAAO,EAAE,KAAK,UAAO,GAAG,OAAO,CAAC,aAAa,CAAC;CAyD9I"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@auxilium/datalynk-client",
|
|
3
3
|
"description": "Datalynk client library",
|
|
4
4
|
"repository": "https://gitlab.auxiliumgroup.com/auxilium/datalynk/datalynk-client",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.6",
|
|
6
6
|
"author": "Zak Timson <zaktimson@gmail.com>",
|
|
7
7
|
"private": false,
|
|
8
8
|
"main": "./dist/index.cjs",
|