This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
videojsrtc.js
74 lines (61 loc) · 2.11 KB
/
videojsrtc.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
videojs.plugin('videojsRtc', function(options) {
var
iframe = document.createElement('iframe'),
wrapper = document.createDocumentFragment(),
wrapperDiv = document.createElement('div'),
wrapperRtcDiv = document.createElement('div'),
divJoin = document.createElement('div'),
labelJoin = document.createElement('label'),
inputText = document.createElement('input'),
inputButton = document.createElement('input'),
divId = document.createElement('div'),
labelId = document.createElement('label'),
labelKey = document.createElement('label'),
iframeSrc = '//videojs-rtc.appspot.com/',
prop,
vel = this.el();
labelJoin.textContent = "Enter room key to join a room:";
inputText.type = "text";
inputButton.value = "Join Room";
inputButton.type = "button";
inputButton.addEventListener('click', function(evt) {
var newKey = inputText.value;
if (newKey.length > 0) {
iframe.src = iframeSrc + "?r=" + newKey;
}
});
divJoin.appendChild(labelJoin);
divJoin.appendChild(inputText);
divJoin.appendChild(inputButton);
labelId.textContent = "Current room key:";
divId.appendChild(labelId);
divId.appendChild(labelKey);
window.addEventListener('message', function(evt) {
console.log()
var jsonData, room_key;
jsonData = JSON.parse(evt.data);
if (jsonData.error) {
videojs.log(jsonData.error);
wrapperRtcDiv.parentElement.removeChild(wrapperRtcDiv);
} else if (jsonData.userMedia) {
wrapperRtcDiv.style.height = 'auto';
wrapperRtcDiv.style.width = 'auto';
} else {
var room_key = jsonData['room_key'];
labelKey.textContent = room_key;
}
});
iframe.src = iframeSrc;
iframe.height = 350;
iframe.width = 600;
wrapperRtcDiv.style.height = '1px';
wrapperRtcDiv.style.width = '1px';
wrapperRtcDiv.style.overflow = "hidden";
wrapperRtcDiv.appendChild(divJoin);
wrapperRtcDiv.appendChild(divId);
wrapperRtcDiv.appendChild(iframe);
vel.parentElement.replaceChild(wrapperDiv, vel);
wrapper.appendChild(vel);
wrapper.appendChild(wrapperRtcDiv);
wrapperDiv.appendChild(wrapper);
});