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.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// src/SeoniaClient.ts
|
|
2
|
+
import { Room, RoomEvent, createLocalVideoTrack } from "livekit-client";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
var SeoniaClient = class {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.room = null;
|
|
7
|
+
}
|
|
8
|
+
onParticipantJoined(callback) {
|
|
9
|
+
this.participantJoinedCallback = callback;
|
|
10
|
+
}
|
|
11
|
+
async joinClass(options) {
|
|
12
|
+
const { token, url } = await this.fetchToken(
|
|
13
|
+
options.identity,
|
|
14
|
+
options.roomName,
|
|
15
|
+
options.role
|
|
16
|
+
);
|
|
17
|
+
return this.connect(url, token);
|
|
18
|
+
}
|
|
19
|
+
async connect(serverUrl, token) {
|
|
20
|
+
this.room = new Room();
|
|
21
|
+
this.registerEvents();
|
|
22
|
+
await this.room.connect(serverUrl, token);
|
|
23
|
+
return this.room;
|
|
24
|
+
}
|
|
25
|
+
async startCamera() {
|
|
26
|
+
if (!this.room) {
|
|
27
|
+
throw new Error("Not connected");
|
|
28
|
+
}
|
|
29
|
+
const videoTrack = await createLocalVideoTrack();
|
|
30
|
+
await this.room.localParticipant.publishTrack(videoTrack);
|
|
31
|
+
}
|
|
32
|
+
async disconnect() {
|
|
33
|
+
await this.room?.disconnect();
|
|
34
|
+
this.room = null;
|
|
35
|
+
}
|
|
36
|
+
getRoom() {
|
|
37
|
+
return this.room;
|
|
38
|
+
}
|
|
39
|
+
registerEvents() {
|
|
40
|
+
if (!this.room) return;
|
|
41
|
+
this.room.on(RoomEvent.ParticipantConnected, (participant) => {
|
|
42
|
+
this.participantJoinedCallback?.({
|
|
43
|
+
id: participant.identity,
|
|
44
|
+
name: participant.name
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async fetchToken(identity, roomName, role) {
|
|
49
|
+
const res = await axios.post(
|
|
50
|
+
"https://token-seonia.azurewebsites.net/getToken",
|
|
51
|
+
{
|
|
52
|
+
identity,
|
|
53
|
+
room: roomName,
|
|
54
|
+
role
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
return {
|
|
58
|
+
token: res.data.token,
|
|
59
|
+
url: res.data.url
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export {
|
|
64
|
+
SeoniaClient
|
|
65
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "seonia-js_sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.cjs",
|
|
5
|
+
"module": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
|
+
"build": "tsup src/index.ts --format esm,cjs,iife --global-name Seonia --dts"
|
|
11
|
+
},
|
|
12
|
+
"author": "Kamalnath Gali",
|
|
13
|
+
"license": "Netsupport Pvt Ltd",
|
|
14
|
+
"description": "This is the JavaScript SDK for Seonia, a WEBRTC platform. It provides an easy way to integrate Seonia's features into your web applications.",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"axios": "^1.16.1",
|
|
17
|
+
"livekit-client": "^2.19.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"tsup": "^8.5.1",
|
|
21
|
+
"typescript": "^5.7.3"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Room, RoomEvent, createLocalVideoTrack } from 'livekit-client';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
export interface SeoniaParticipant {
|
|
5
|
+
id: string;
|
|
6
|
+
name?: string | undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface JoinClassOptions {
|
|
10
|
+
identity: string;
|
|
11
|
+
roomName: string;
|
|
12
|
+
role: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class SeoniaClient {
|
|
16
|
+
private room: Room | null = null;
|
|
17
|
+
private participantJoinedCallback?: (participant: SeoniaParticipant) => void;
|
|
18
|
+
|
|
19
|
+
onParticipantJoined(callback: (participant: SeoniaParticipant) => void) {
|
|
20
|
+
this.participantJoinedCallback = callback;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async joinClass(options: JoinClassOptions) {
|
|
24
|
+
const { token, url } = await this.fetchToken(
|
|
25
|
+
options.identity,
|
|
26
|
+
options.roomName,
|
|
27
|
+
options.role
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return this.connect(url, token);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async connect(serverUrl: string, token: string) {
|
|
34
|
+
this.room = new Room();
|
|
35
|
+
this.registerEvents();
|
|
36
|
+
await this.room.connect(serverUrl, token);
|
|
37
|
+
return this.room;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async startCamera():Promise<void> {
|
|
41
|
+
if (!this.room) {
|
|
42
|
+
throw new Error('Not connected');
|
|
43
|
+
}
|
|
44
|
+
const videoTrack = await createLocalVideoTrack();
|
|
45
|
+
|
|
46
|
+
await this.room.localParticipant.publishTrack(videoTrack);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async disconnect() {
|
|
50
|
+
await this.room?.disconnect();
|
|
51
|
+
this.room = null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getRoom() {
|
|
55
|
+
return this.room;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
private registerEvents() {
|
|
60
|
+
if (!this.room) return;
|
|
61
|
+
|
|
62
|
+
this.room.on(RoomEvent.ParticipantConnected, (participant) => {
|
|
63
|
+
this.participantJoinedCallback?.({
|
|
64
|
+
id: participant.identity,
|
|
65
|
+
name: participant.name,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private async fetchToken(
|
|
71
|
+
identity: string,
|
|
72
|
+
roomName: string,
|
|
73
|
+
role: string
|
|
74
|
+
) {
|
|
75
|
+
const res = await axios.post(
|
|
76
|
+
'https://token-seonia.azurewebsites.net/getToken',
|
|
77
|
+
{
|
|
78
|
+
identity,
|
|
79
|
+
room: roomName,
|
|
80
|
+
role,
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
token: res.data.token,
|
|
86
|
+
url: res.data.url,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SeoniaClient';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
// "rootDir": "./src",
|
|
6
|
+
// "outDir": "./dist",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "esnext",
|
|
11
|
+
"target": "es2020",
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"outDir": "dist",
|
|
14
|
+
"types": [],
|
|
15
|
+
// For nodejs:
|
|
16
|
+
// "lib": ["esnext"],
|
|
17
|
+
// "types": ["node"],
|
|
18
|
+
// and npm install -D @types/node
|
|
19
|
+
|
|
20
|
+
// Other Outputs
|
|
21
|
+
"sourceMap": true,
|
|
22
|
+
"declaration": true,
|
|
23
|
+
"declarationMap": true,
|
|
24
|
+
|
|
25
|
+
// Stricter Typechecking Options
|
|
26
|
+
"noUncheckedIndexedAccess": true,
|
|
27
|
+
"exactOptionalPropertyTypes": true,
|
|
28
|
+
|
|
29
|
+
// Style Options
|
|
30
|
+
// "noImplicitReturns": true,
|
|
31
|
+
// "noImplicitOverride": true,
|
|
32
|
+
// "noUnusedLocals": true,
|
|
33
|
+
// "noUnusedParameters": true,
|
|
34
|
+
// "noFallthroughCasesInSwitch": true,
|
|
35
|
+
// "noPropertyAccessFromIndexSignature": true,
|
|
36
|
+
|
|
37
|
+
// Recommended Options
|
|
38
|
+
"strict": true,
|
|
39
|
+
"jsx": "react-jsx",
|
|
40
|
+
"verbatimModuleSyntax": true,
|
|
41
|
+
"isolatedModules": true,
|
|
42
|
+
"noUncheckedSideEffectImports": true,
|
|
43
|
+
"moduleDetection": "force",
|
|
44
|
+
"skipLibCheck": true,
|
|
45
|
+
}
|
|
46
|
+
}
|