-
Notifications
You must be signed in to change notification settings - Fork 0
/
handleStream.js
77 lines (64 loc) · 2.11 KB
/
handleStream.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { client } from "./client";
export function handleAudioStream(element) {
element.addEventListener("click", async () => {
const audioRef = document.querySelector("#audio");
if (audioRef.textContent == "Disable Audio") {
await client.localPeer.disableAudio();
audioRef.textContent = "Enable Audio";
} else {
await client.localPeer.enableAudio();
audioRef.textContent = "Disable Audio";
}
});
}
export function handleVideoStream(element) {
element.addEventListener("click", async () => {
const videoRef = document.querySelector("#videoRef");
if (videoRef.srcObject) {
client.localPeer.disableVideo();
document.querySelector("#video").textContent = "Enable Video";
return;
}
const stream = await client.localPeer.enableVideo();
console.log("stream", stream);
videoRef.srcObject = stream;
videoRef.onloadedmetadata = async () => {
console.warn("videoCard() | Metadata loaded...");
try {
await videoRef.play();
document.querySelector("#video").textContent = "Disable Video";
} catch (error) {
console.error(error);
}
};
videoRef.onerror = () => {
console.error("videoCard() | Error is hapenning...");
};
});
}
export function handleScreenStream(element) {
element.addEventListener("click", async () => {
const screenRef = document.querySelector("#screenRef");
if (screenRef.srcObject) {
client.localPeer.stopScreenShare();
screenRef.srcObject = null;
document.querySelector("#screen").textContent = "Share Screen";
return;
}
const stream = await client.localPeer.startScreenShare();
console.log("stream", stream);
screenRef.srcObject = stream;
screenRef.onloadedmetadata = async () => {
console.warn("videoCard() | Metadata loaded...");
try {
await screenRef.play();
document.querySelector("#screen").textContent = "Stop Sharing";
} catch (error) {
console.error(error);
}
};
screenRef.onerror = () => {
console.error("videoCard() | Error is hapenning...");
};
});
}