-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathclient.js
144 lines (110 loc) · 3.8 KB
/
client.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
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
138
139
140
141
142
143
var aliceButton = document.getElementById("aliceButton");
var bobButton = document.getElementById("bobButton");
var chooseUserForm = document.getElementById("chooseUserForm");
var helloJumbo = document.getElementById("helloJumbo");
var helloJumboUser = document.getElementById("helloJumboUser");
var helloJumboButton = document.getElementById("helloJumboButton");
var screenVideoLocal = document.getElementById("screenVideoLocal");
var screenVideoRemote = document.getElementById("screenVideoRemote");
var extDownloadHref = document.getElementById("extDownloadHref");
var localVideoPanel = document.getElementById("localScreenPanel");
var remoteVideoPanel = document.getElementById("remoteScreenPanel");
var currentUser;
var currentConnection;
aliceButton.onclick = showAlicePage;
bobButton.onclick = showBobPage;
$(document).ready(function() {
extDownloadHref.href = location.protocol + "//" + location.host + location.pathname + "screen-sharing-extension.crx";
});
function showAlicePage() {
showPageOf("alice");
}
function showBobPage() {
showPageOf("bob");
}
function showPageOf(user) {
currentUser = user;
connectToRestcomm();
}
function connectToRestcomm() {
var parameters = {
'debug': true,
'username': currentUser,
'password': '1234',
'registrar': 'wss://localhost:5063',
'domain': 'localhost'
};
RestCommClient.Device.setup(parameters);
RestCommClient.Device.ready(function(device) {
console.log(currentUser + " : Ready");
prepareInitJumbo();
});
RestCommClient.Device.error(function(error) {
console.error(currentUser + " : " + error.message);
});
RestCommClient.Device.connect(function(connection) {
console.log(currentUser + " : Successfully established call");
fillSharedJumbo();
});
RestCommClient.Device.disconnect(function(connection) {
console.log(currentUser + " : Connection ended");
prepareInitJumbo();
});
RestCommClient.Device.incoming(function(connection) {
var parameters = {
//'video-source': 'no-video',
'video-source': 'screen',
'local-media': screenVideoLocal,
'remote-media': screenVideoRemote,
};
currentConnection = connection;
currentConnection.accept(parameters);
currentConnection.disconnect(function(connection) {
console.log(currentUser + " : Connection ended");
prepareInitJumbo();
});
});
}
function prepareInitJumbo() {
chooseUserForm.style.display = 'none';
helloJumbo.style.display = 'block';
fillJumboForSharing();
}
function fillJumboForSharing() {
helloJumboUser.innerHTML = helloJumboUserHTML(false);
helloJumboButton.innerHTML = "Share screen";
helloJumboButton.onclick = startSharing;
localVideoPanel.style.display='block'
remoteVideoPanel.style.display='block'
screenVideoLocal.src = undefined;
screenVideoRemote.src = undefined;
}
function fillSharedJumbo() {
helloJumboUser.innerHTML = helloJumboUserHTML(true);
helloJumboButton.innerHTML = "Stop sharing";
helloJumboButton.onclick = hangup;
}
function startSharing() {
var calleeContact = (currentUser == "alice" ? "bob" : "alice");
var parameters = {
'username': calleeContact,
//'video-source': 'no-video',
'video-source': 'screen',
'local-media': screenVideoLocal,
'remote-media': screenVideoRemote,
};
currentConnection = RestCommClient.Device.connect(parameters);
currentConnection.disconnect(function(connection) {
prepareInitJumbo();
});
// Pass a callback to get notified if a Connetion error occurs
currentConnection.error(function(error) {
console.error(currentUser + ": Connection error: " + error);
});
}
function hangup() {
RestCommClient.Device.disconnectAll();
}
function helloJumboUserHTML(isConnected) {
return "Hello, " + (currentUser == "alice" ? "Alice" : "Bob") + "! <span class='label " + (isConnected ? "label-success'>Connected" : "label-default'>Disconnected") + "<\/span>";
}