-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
279 lines (247 loc) · 8.73 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE HTML>
<html>
<head>
<meta charset=utf-8>
<!-- add libs -->
<script language="JavaScript" type="text/javascript" src="//comet-server.com/js/lib/jquery.min.js" ></script>
<script src="//comet-server.com/CometServerApi.js" type="text/javascript"></script>
<script src="//comet-server.com/cometVideoApi.js" type="text/javascript"></script>
</head>
<body>
<style>
video{
background:#000;
float:left;
width: 45%;
border:1px solid #f00;
margin:5px;
}
hr{
clear:both;
}
.hide{
display:none;
}
.root .showincall{
display:none;
}
.root .hideincall{
display:block;
}
.root.incall .showincall{
display:block;
}
.root.incall .hideincall{
display:none;
}
.callbtns button{
float:left;
margin:5px;
margin-top:0px;
margin-bottom:10px;
}
#log{
color:#000
}
.status{
color:#272;
font-weight:bold;
}
.note{
background:#eee;
padding:1px 10px;
margin:5px;
border-radius:5px;
text-align:justify;
}
</style>
<h3>Video chat</h3>
<div class="note">
<p><a href="https://github.com/CppComet/video-chat-example">Git repository with all code of this example.</a></p>
<p>To check the operation of the video chat, go to this page from two or more browsers.</p>
<p>Do not forget that for a video chat you need a webcam or at least a microphone.</p>
<p>If you have opened a video chat from two browsers, but from one computer it can happen that only one browser will access the video stream from the camera, and the second browser will either give an error (If it's FireFox) or broadcast a black box (If it's a chrome)</p>
<p>If the conference is more than 2 people, then the speaker will be shown, and not all at once. But it is also possible for all conference participants to immediately display tiles on a common image.</p>
<p style="font-weight:bold;">This functionality in the beta testing phase, about errors, report at <a href="https://github.com/CppComet/comet-server/issues">this page</a> or to the email [email protected]</p>
</div>
<div class="root">
<div>
<video id="video_remote" autoplay="autoplay" ></video>
<video id="video_local" autoplay="autoplay" muted="true" ></video>
<audio id="audio_remote" autoplay="autoplay" style="display: none;"></audio>
</div>
<hr>
<div class="callbtns">
<button class="hideincall StartCallBtn" onclick="StartCall()" >Join to the conference</button>
<button class="showincall EndCall" onclick="EndCall()">Hangup</button>
<button class="showincall MuteAudio" onclick="MuteAudio()">Mute/UnMute audio</button>
<button class="showincall MuteVideo" onclick="MuteVideo()">Mute/UnMute video</button>
</div>
<hr>
<div class="status">
We are waiting for authorization on the comet server
</div>
<hr>
<div id="log"></div>
</div>
<script type="text/javascript">
function log()
{
console.log(arguments);
$("#log").append(JSON.stringify(arguments)+"<hr>");
}
function StartCall()
{
$(".StartCallBtn").hide();
$(".status").html("We are waiting for permission to call");
roomId = "101";
log("call", roomId)
// Connecting to video chat
$.ajax({
url: "https://comet-server.com/doc/CometQL/videochat/call.php?user_id="+cometApi.getUserId()+"&room="+roomId,
type: "POST",
});
}
function EndCall()
{
// End the call
cometVideoApi.hangup();
}
function MuteAudio()
{
cometVideoApi.muteAudio(!cometVideoApi.isMute().audio)
}
function MuteVideo()
{
cometVideoApi.muteVideo(!cometVideoApi.isMute().video)
}
// Authorization on comets server
function auth()
{
var user_id = localStorage['user_id']
if(!user_id)
{
user_id = Math.floor(Math.random()*1000000)
localStorage['user_id'] = user_id
}
log("Request authorization for user_id="+user_id)
var user_key = "PassForUser"+user_id
// Connecting to video chat
return $.when($.ajax({
url: "https://comet-server.com/doc/CometQL/videochat/auth.php?user_id="+user_id+"&user_key="+user_key,
type: "GET",
dataType:'json',
})).always(function(res){
$(".status").html("We are waiting for connection to the comet server");
cometApi.start({
node: "app.comet-server.ru",
dev_id: 15,
user_id:user_id,
user_key:user_key,
})
}).promise();
}
cometApi.onAuthSuccess(function()
{
// We will initialize the call after successful authorization on the comet server.
$(".StartCallBtn").removeClass("hide");
log("Authorization on the comet server is complete")
$(".status").html("Authorization on the comet server is complete");
})
auth();
// We initiate the activation of cometVideoApi
cometVideoApi.start({
// Callback called before starting the connection for the call
// It is assumed that it will set the settings for the next call
// Such as the parameters audio_remote, video_local, video_remote and maybe even some more.
// And then the cometVideoApi.acceptCall (event) function will be called
// And if it's not called, then we did not pick up the phone.
onCall:function(callEvent)
{
$(".status").html("Incoming call, press answer.");
if(!confirm("Answer a call?"))
{
// We decided not to answer the call
$(".status").html("We decided not to answer the call");
$(".StartCallBtn").show();
return
}
// Receive call
cometVideoApi.acceptCall({
// Type of call 'audio' | 'video'
type:'video',
// Specify the target element for the video stream from the interlocutor
video_remote: $("#video_remote")[0],
// Specify the target element for the audio stream from the interlocutor
audio_remote: $("#audio_remote")[0],
// Specify the target element for the video stream from me (my own image from the camera)
video_local: $("#video_local")[0],
})
$(".status").html("We look forward to hearing from other conference participants");
},
/**
* Callback end of call
* @param {object} event
* {
* Action: "", // Event name
* Status: "", // Call completion reason
* CallInfo: {}, // Information about the call
* Time: 1000 // Time duration of the call
* Type: "audio" // Type of call
* }
*/
onCallEnd:function(event)
{
$(".root").removeClass("incall")
$(".StartCallBtn").show();
$(".status").html("Call ended");
log("onCallEnd", event)
},
/**
* Callback picking up the interlocutor
* @param {object} event
* {
* Action: "accept", // Event name
* CallInfo: {}, // Information about the call
* Type: "audio" // The type of call that is selected by the interlocutor
* }
*
* The callback is called only once for the first responding interlocutor
*
*/
onCallAccept: function(event)
{
$(".status").html("Received a response from another participant in the conference.");
log("onAccept", event)
},
/**
* Callback when I and my interlocutor are connected to the server
* @param {object} event
* {
* Action: "start", // Event name
* CallInfo: {}, // Information about the call
* Type: "audio" // Type of call
*}
*/
onCallStart: function(event)
{
$(".status").html("Connection to the media server is complete. The conversation began.");
$(".root").addClass("incall")
log("onCallStart", event)
},
onOut: function(event)
{
// Participant's exit from the conference
$(".status").html("One of the interlocutors left the conference");
log("onOut", event)
},
onIn: function(event)
{
// Log in to the conference
$(".status").html("Another person joined the conference.");
log("onIn", event)
},
})
</script>
</body>
</html>