seonia-js_sdk 1.0.0
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/dist/index.cjs +102 -0
- package/dist/index.global.js +44892 -0
- package/dist/index.js +65 -0
- package/package.json +23 -0
- package/seonia-js_sdk-1.0.0.tgz +0 -0
- package/src/SeoniaClient.ts +89 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +46 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
SeoniaClient: () => SeoniaClient
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/SeoniaClient.ts
|
|
38
|
+
var import_livekit_client = require("livekit-client");
|
|
39
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
40
|
+
var SeoniaClient = class {
|
|
41
|
+
constructor() {
|
|
42
|
+
this.room = null;
|
|
43
|
+
}
|
|
44
|
+
onParticipantJoined(callback) {
|
|
45
|
+
this.participantJoinedCallback = callback;
|
|
46
|
+
}
|
|
47
|
+
async joinClass(options) {
|
|
48
|
+
const { token, url } = await this.fetchToken(
|
|
49
|
+
options.identity,
|
|
50
|
+
options.roomName,
|
|
51
|
+
options.role
|
|
52
|
+
);
|
|
53
|
+
return this.connect(url, token);
|
|
54
|
+
}
|
|
55
|
+
async connect(serverUrl, token) {
|
|
56
|
+
this.room = new import_livekit_client.Room();
|
|
57
|
+
this.registerEvents();
|
|
58
|
+
await this.room.connect(serverUrl, token);
|
|
59
|
+
return this.room;
|
|
60
|
+
}
|
|
61
|
+
async startCamera() {
|
|
62
|
+
if (!this.room) {
|
|
63
|
+
throw new Error("Not connected");
|
|
64
|
+
}
|
|
65
|
+
const videoTrack = await (0, import_livekit_client.createLocalVideoTrack)();
|
|
66
|
+
await this.room.localParticipant.publishTrack(videoTrack);
|
|
67
|
+
}
|
|
68
|
+
async disconnect() {
|
|
69
|
+
await this.room?.disconnect();
|
|
70
|
+
this.room = null;
|
|
71
|
+
}
|
|
72
|
+
getRoom() {
|
|
73
|
+
return this.room;
|
|
74
|
+
}
|
|
75
|
+
registerEvents() {
|
|
76
|
+
if (!this.room) return;
|
|
77
|
+
this.room.on(import_livekit_client.RoomEvent.ParticipantConnected, (participant) => {
|
|
78
|
+
this.participantJoinedCallback?.({
|
|
79
|
+
id: participant.identity,
|
|
80
|
+
name: participant.name
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async fetchToken(identity, roomName, role) {
|
|
85
|
+
const res = await import_axios.default.post(
|
|
86
|
+
"https://token-seonia.azurewebsites.net/getToken",
|
|
87
|
+
{
|
|
88
|
+
identity,
|
|
89
|
+
room: roomName,
|
|
90
|
+
role
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
return {
|
|
94
|
+
token: res.data.token,
|
|
95
|
+
url: res.data.url
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
SeoniaClient
|
|
102
|
+
});
|