-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
137 lines (115 loc) · 4.56 KB
/
index.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!--
************************ use launcher.js *******************************
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<style id="webmakerstyle">
</style>
</head>
<body>
<canvas id='localCanvasSource'></canvas>
<section id='video-container' style="width: 400px; height: 400px"></section>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/fm.liveswitch.js"></script>
<script>
let canvas = document.getElementById('localCanvasSource');
const canvasFrameRate = 3;
if (!canvas) {
canvas = document.createElement('canvas');
canvas.id = 'localCanvasSource';
canvas.style.position = 'absolute';
document.body.appendChild(canvas);
// Load a static image.
var image = new Image();
image.onload = function() {
// Resize the canvas to match the image size.
canvas.width = image.width;
canvas.height = image.height;
canvas.style.left = '-' + image.width + 'px';
canvas.style.top = '-' + image.height + 'px';
// Draw the initial image.
var context = canvas.getContext('2d');
context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
// Refresh the image on a regular interval.
window.setInterval(function() {
context.clearRect(0, 0, canvas.width, canvas.height);
context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
}, 1000.0 / canvasFrameRate);
};
image.src = 'https://v1.liveswitch.fm/images/static.jpg';
}
const applicationId = 'live-switch-mcu-test';
const userId = 'gaurav.sharma';
const deviceId = 'my-device2';
const channelId = 'my-first-channe;';
const client = new fm.liveswitch.Client('http://ec2-13-127-65-239.ap-south-1.compute.amazonaws.com:8080/sync', applicationId, userId, deviceId, null, ['role1', 'role2']);
const sharedSecret = '82bfb27b882c46b2bd2c5605abfb4085274c49c5a9c3458d8086849cddca38ce';
//register a user first
const registerToken = fm.liveswitch.Token.generateClientRegisterToken(
applicationId,
client.getUserId(),
client.getDeviceId(),
client.getId(),
client.getRoles(),
[],
sharedSecret,
);
console.log(registerToken);
client.register(registerToken).then(function (channels) {
console.log('Registered successfully!!');
// handler to join a new channel
const token = fm.liveswitch.Token.generateClientJoinToken(
applicationId,
client.getUserId(),
client.getDeviceId(),
client.getId(),
new fm.liveswitch.ChannelClaim(channelId),
sharedSecret,
);
// console.log(token);
client.join(channelId, token).then((channel) => {
console.log('Successfully joined a channel');
// handle the media implementation here
const audio = true;
// const video = true;
// const video = {
// width: 320,
// height: 240,
// frameRate: 30
// };
// handle the canvas
var video = true;
// instance to capture the local media
const localMedia = new fm.liveswitch.LocalMedia(audio, video);
// create instance to capture the remote media
const remoteMedia = new fm.liveswitch.RemoteMedia();
const audioStream = new fm.liveswitch.AudioStream(localMedia, remoteMedia);
const videoStream = new fm.liveswitch.VideoStream(localMedia, remoteMedia);
const mcuConnection = channel.createMcuConnection(audioStream, videoStream);
const layoutManager = new fm.liveswitch.DomLayoutManager(document.getElementById('video-container'));
localMedia.start().then((lm) => {
console.log('started recording');
// render the captured video into the container
layoutManager.setLocalView(localMedia.getView());
layoutManager.addRemoteView(remoteMedia.getId(), remoteMedia.getView());
mcuConnection.setIceServers([
new fm.liveswitch.IceServer('stun:turn.frozenmountain.com:3478'),
new fm.liveswitch.IceServer('turn:turn.frozenmountain.com:80', 'test', 'pa55w0rd!'),
new fm.liveswitch.IceServer('turns:turn.frozenmountain.com:443', 'test', 'pa55w0rd!')
]);
try {
mcuConnection.open()
.then(result => console.log('Mixed connection established'))
.fail(err => console.log('MCU Open connection Error', err.message));
} catch (err) {
console.log(err.message);
}
// layoutManager.unsetLocalView();
}).fail(err => console.log('Some syntax error: ',err.message));
// localMedia.start().then(lm => console.log(lm)).catch(err => console.log(err.message));
}).fail(err => console.log('Failed while joining a channel', err));
}).fail(err => console.log(err));
//# sourceURL=userscript.js
</script>
</body>
</html> -->