-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.js
More file actions
159 lines (128 loc) · 4.84 KB
/
Copy pathclient.js
File metadata and controls
159 lines (128 loc) · 4.84 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* New node file
*/
var selfEasyrtcid = "";
function disable(domId) {
document.getElementById(domId).disabled = "disabled";
}
function enable(domId) {
document.getElementById(domId).disabled = "";
}
function connect() {
easyrtc.setSocketUrl(":8080");
easyrtc.enableDebug(false);
console.log("Initializing.");
easyrtc.enableAudio(true);
easyrtc.enableAudioReceive(true);
easyrtc.setRoomOccupantListener(convertListToButtons);
easyrtc.initMediaSource(
function(){ // success callback
var selfVideo = document.getElementById("selfVideo");
easyrtc.setVideoObjectSrc(selfVideo, easyrtc.getLocalStream());
easyrtc.connect("easyrtc.audioVideoSimple", loginSuccess, loginFailure);//videoOnly
},
function(errorCode, errmesg){
easyrtc.showError("MEDIA-ERROR", errmesg);
} // failure callback
);
}
function terminatePage() {
easyrtc.disconnect();
}
function hangup() {
easyrtc.hangupAll();
disable("hangupButton");
}
function clearConnectList() {
var otherClientDiv = document.getElementById("otherClients");
while (otherClientDiv.hasChildNodes()) {
otherClientDiv.removeChild(otherClientDiv.lastChild);
}
}
function convertListToButtons (roomName, occupants, isPrimary) {
clearConnectList();
var otherClientDiv = document.getElementById("otherClients");
for(var easyrtcid in occupants) {
var button = document.createElement("button");
button.onclick = function(easyrtcid) {
return function() {
performCall(easyrtcid);
};
}(easyrtcid);
var label = document.createTextNode( easyrtc.idToName(easyrtcid));
button.appendChild(label);
otherClientDiv.appendChild(button);
}
if( !otherClientDiv.hasChildNodes() ) {
otherClientDiv.innerHTML = "<em>Nobody else is on...</em>";
}
}
function performCall(otherEasyrtcid) {
easyrtc.hangupAll();
var acceptedCB = function(accepted, easyrtcid) {
if( !accepted ) {
easyrtc.showError("CALL-REJECTED", "Sorry, your call to " + easyrtc.idToName(easyrtcid) + " was rejected");
enable("otherClients");
}
};
var successCB = function() {
enable("hangupButton");
};
var failureCB = function() {
enable("otherClients");
};
easyrtc.call(otherEasyrtcid, successCB, failureCB, acceptedCB);
}
function loginSuccess(easyrtcid) {
disable("connectButton");
// enable("disconnectButton");
enable("otherClients");
selfEasyrtcid = easyrtcid;
//var us_id = mongoose.model('userShema', shema, local.email);
//console('us_id'+us_id);
document.getElementById("iam").innerHTML = "I am " + easyrtcid; //
}
function loginFailure(errorCode, message) {
easyrtc.showError(errorCode, message);
}
function disconnect() {
document.getElementById("iam").innerHTML = "logged out";
easyrtc.disconnect();
console.log("disconnecting from server");
enable("connectButton");
// disable("disconnectButton");
clearConnectList();
easyrtc.setVideoObjectSrc(document.getElementById("selfVideo"), "");
}
easyrtc.setStreamAcceptor( function(easyrtcid, stream) {
var video = document.getElementById("callerVideo");
easyrtc.setVideoObjectSrc(video,stream);
console.log("saw video from " + easyrtcid);
enable("hangupButton");
});
easyrtc.setOnStreamClosed( function (easyrtcid) {
easyrtc.setVideoObjectSrc(document.getElementById("callerVideo"), "");
disable("hangupButton");
});
easyrtc.setAcceptChecker(function(easyrtcid, callback) {
document.getElementById("acceptCallBox").style.display = "block";
if( easyrtc.getConnectionCount() > 0 ) {
document.getElementById("acceptCallLabel").innerHTML = "Drop current call and accept new from " + easyrtc.idToName(easyrtcid) + " ?";
}
else {
document.getElementById("acceptCallLabel").innerHTML = "Accept incoming call from " + easyrtc.idToName(easyrtcid) + " ?";
}
var acceptTheCall = function(wasAccepted) {
document.getElementById("acceptCallBox").style.display = "none";
if( wasAccepted && easyrtc.getConnectionCount() > 0 ) {
easyrtc.hangupAll();
}
callback(wasAccepted);
};
document.getElementById("callAcceptButton").onclick = function() {
acceptTheCall(true);
};
document.getElementById("callRejectButton").onclick =function() {
acceptTheCall(false);
};
} );