-
Notifications
You must be signed in to change notification settings - Fork 3
/
video_call.ts
54 lines (52 loc) · 1.41 KB
/
video_call.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import Janus, { PluginHandle, Controllers } from "../interfaces/janus";
import { JanusPlugin } from "../janus_plugin";
import { JanusSession } from "../janus_session";
export class JanusVideoCallPlugin extends JanusPlugin {
constructor(
instance: Janus,
session: JanusSession,
handle: PluginHandle,
controllers: Controllers
) {
super(instance, session, handle, controllers);
}
/**
* Register user to videocall plugin to make or recieve a call from another registered user
* @param {string} username - username of the user to call
* */
async register(username: string): Promise<void> {
await this.send({
message: {
request: "register",
username: username,
},
});
}
/**
* Register user to videocall plugin to make or recieve a call from another registered user
* @param {string} username - username of the user to call
* @param {RTCSessionDescription} offer- webrtc offer of your choice
* */
async call(
username: string,
offer: RTCSessionDescription = null
): Promise<void> {
if (offer === null) {
offer = await this.createOffer({
media: {
videoSend: true,
videoRecv: true,
audioSend: true,
audioRecv: true,
},
});
}
await this.send({
message: {
request: "call",
username: username,
},
jsep: offer.toJSON(),
});
}
}