-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmulti_firebase.html
836 lines (729 loc) · 23.3 KB
/
multi_firebase.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>multi firebase</title>
<!--
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
-->
<!--
<script src="http://localhost:3002/socket.io/socket.io.js"></script>
-->
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-database.js"></script>
<script>
function _assert(desc, v) {
if (v) {
return;
}
else {
let caller = _assert.caller || 'Top level';
console.error('ASSERT in %s, %s is :', caller, desc, v);
}
}
</script>
</head>
<body>
firebase signaling for multi-party (trickle ICE)<br />
<button type="button" onclick="startVideo();">Start Video</button>
<button type="button" onclick="stopVideo();">Stop Video</button>
<button type="button" onclick="connect();">Connect</button>
<button type="button" onclick="hangUp();">Hang Up</button>
<a id="room_link" href="" target="_blank">Open another window (link to this room)</a>
<a id="mail_link" href="" target="_blank">Mail link of this room</a>
<div>
<video id="local_video" autoplay style="width: 160px; height: 120px; border: 1px solid black;"></video>
</div>
<div id="container">
</div>
<!--
<p>SDP to send:<br />
<textarea id="text_for_send_sdp" rows="5" cols="60" readonly="readonly">SDP to send</textarea>
</p>
<p>SDP received:
<button type="button" onclick="onSdpText();">Receive remote SDP</button>
<br />
<textarea id="text_for_receive_sdp" rows="5" cols="60"></textarea>
</p>
-->
</body>
<script type="text/javascript">
let localVideo = document.getElementById('local_video');
//let remoteVideo = document.getElementById('remote_video');
let localStream = null;
//let peerConnection = null;
//let textForSendSdp = document.getElementById('text_for_send_sdp');
//let textToReceiveSdp = document.getElementById('text_for_receive_sdp');
// ---- for multi party -----
let peerConnections = [];
let remoteStreams = [];
let remoteVideos = [];
const MAX_CONNECTION_COUNT = 3;
// --- multi video ---
let container = document.getElementById('container');
_assert('container', container);
// --- prefix -----
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
RTCSessionDescription = window.RTCSessionDescription || window.webkitRTCSessionDescription || window.mozRTCSessionDescription;
/*---
// ----- use socket.io ---
let port = 3002;
let socket = io.connect('http://localhost:' + port + '/');
let room = getRoomName();
socket.on('connect', function(evt) {
console.log('socket.io connected. enter room=' + room );
socket.emit('enter', room);
});
socket.on('message', function(message) {
console.log('message:', message);
let fromId = message.from;
if (message.type === 'offer') {
// -- got offer ---
console.log('Received offer ...');
//let offer = message.sessionDescription;
let offer = new RTCSessionDescription(message);
setOffer(fromId, offer);
}
else if (message.type === 'answer') {
// --- got answer ---
console.log('Received answer ...');
//let answer = message.sessionDescription;
let answer = new RTCSessionDescription(message);
setAnswer(fromId, answer);
}
else if (message.type === 'candidate') {
// --- got ICE candidate ---
console.log('Received ICE candidate ...');
let candidate = new RTCIceCandidate(message.ice);
console.log(candidate);
addIceCandidate(fromId, candidate);
}
else if (message.type === 'call me') {
if (! isReadyToConnect()) {
console.log('Not ready to connect, so ignore');
return;
}
else if (! canConnectMore()) {
console.warn('TOO MANY connections, so ignore');
}
if (isConnectedWith(fromId)) {
// already connnected, so skip
console.log('already connected, so ignore');
}
else {
// connect new party
makeOffer(fromId);
}
}
else if (message.type === 'bye') {
if (isConnectedWith(fromId)) {
stopConnection(fromId);
}
}
});
socket.on('user disconnected', function(evt) {
console.log('====user disconnected==== evt:', evt);
let id = evt.id;
if (isConnectedWith(id)) {
stopConnection(id);
}
});
---*/
// ----- use firebase.io ----
const dataDebugFlag = false;
let room = getRoomName();
// Initialize Firebase
let config = {
apiKey: "xxxxxxxxxxxxxxxxxxxxxxxx", // <-- please set your API key
databaseURL: "https://webrtcexpjp.firebaseio.com", // <-- please set your database URL
};
let databaseRoot = 'basic2016/multi/'; // <--- plaase set your database root for signaling
firebase.initializeApp(config);
let database = firebase.database();
let roomBroadcastRef;
let clientRef;
let clientId;
joinRoom(room);
setRoomLink(room);
function joinRoom(room) {
console.log('join room name = ' + room);
let key = database.ref(databaseRoot + room + '/_join_').push({ joined : 'unknown'}).key
clientId = 'member_' + key;
console.log('joined to room=' + room + ' as clientId=' + clientId);
database.ref(databaseRoot + room + '/_join_/' + key).update({ joined : clientId});
// remove join object
if (! dataDebugFlag) {
let jooinRef = database.ref(databaseRoot + room + '/_join_/' + key);
jooinRef.remove();
}
roomBroadcastRef = database.ref(databaseRoot + room + '/_broadcast_');
roomBroadcastRef.on('child_added', function(data) {
console.log('roomBroadcastRef.on(data) data.key=' + data.key + ', data.val():', data.val());
let message = data.val();
let fromId = message.from;
if (fromId === clientId) {
// ignore self message
return;
}
if (message.type === 'call me') {
if (! isReadyToConnect()) {
console.log('Not ready to connect, so ignore');
return;
}
else if (! canConnectMore()) {
console.warn('TOO MANY connections, so ignore');
}
if (isConnectedWith(fromId)) {
// already connnected, so skip
console.log('already connected, so ignore');
}
else {
// connect new party
makeOffer(fromId);
}
}
else if (message.type === 'bye') {
if (isConnectedWith(fromId)) {
stopConnection(fromId);
}
}
});
clientRef = database.ref(databaseRoot + room + '/_direct_/' + clientId);
clientRef.on('child_added', function(data) {
console.log('clientRef.on(data) data.key=' + data.key + ', data.val():', data.val());
let message = data.val();
let fromId = message.from;
if (message.type === 'offer') {
// -- got offer ---
console.log('Received offer ... fromId=' + fromId);
//let offer = message.sessionDescription;
let offer = new RTCSessionDescription(message);
setOffer(fromId, offer);
}
else if (message.type === 'answer') {
// --- got answer ---
console.log('Received answer ... fromId=' + fromId);
//let answer = message.sessionDescription;
let answer = new RTCSessionDescription(message);
setAnswer(fromId, answer);
}
else if (message.type === 'candidate') {
// --- got ICE candidate ---
console.log('Received ICE candidate ... fromId=' + fromId);
//let candidate = new RTCIceCandidate(message.ice);
let candidate = new RTCIceCandidate(JSON.parse(message.ice)); // <---- JSON
console.log(candidate);
addIceCandidate(fromId, candidate);
}
if (! dataDebugFlag) {
// remove direct message
let messageRef = database.ref(databaseRoot + room + '/_direct_/' + clientId + '/' + data.key);
messageRef.remove();
}
});
}
function setRoomLink(room) {
let url = document.location.href;
let anchorLink = document.getElementById('room_link');
anchorLink.href = url;
let anchorMail = document.getElementById('mail_link');
let mailtoUrl = 'mailto:?subject=invitation-of-multi-party-videochat&body=' + url;
anchorMail.href = mailtoUrl;
}
// ----- use firebase.io ---- //
// --- broadcast message to all members in room
function emitRoom(msg) {
//socket.emit('message', msg);
msg.from = clientId;
roomBroadcastRef.push(msg);
}
function emitTo(id, msg) {
//msg.sendto = id;
//socket.emit('message', msg);
console.log('===== sending from=' + clientId + ' , to=' + id);
msg.from = clientId;
database.ref(databaseRoot + room + '/_direct_/' + id).push(msg);
}
function clearMessage() {
clientRef.set({});
}
// -- room名を取得 --
function getRoomName() { // たとえば、 URLに ?roomname とする
let url = document.location.href;
let args = url.split('?');
if (args.length > 1) {
let room = args[1];
if (room != '') {
return room;
}
}
// generate rondom room, and replace URL
let room = 'room_' + getUniqueStr();
window.history.pushState(null, null, 'multi_firebase.html?' + room);
return room;
}
// http://qiita.com/coa00@github/items/679b0b5c7c468698d53f
// 疑似ユニークIDを生成
function getUniqueStr(myStrong){
var strong = 1000;
if (myStrong) strong = myStrong;
return new Date().getTime().toString(16) + Math.floor(strong*Math.random()).toString(16);
}
// ---- for multi party -----
function isReadyToConnect() {
if (localStream) {
return true;
}
else {
return false;
}
}
// --- RTCPeerConnections ---
function getConnectionCount() {
return peerConnections.length;
}
function canConnectMore() {
return (getConnectionCount() < MAX_CONNECTION_COUNT);
}
function isConnectedWith(id) {
if (peerConnections[id]) {
return true;
}
else {
return false;
}
}
function addConnection(id, peer) {
_assert('addConnection() peer', peer);
_assert('addConnection() peer must NOT EXIST', (! peerConnections[id]));
peerConnections[id] = peer;
}
function getConnection(id) {
let peer = peerConnections[id];
_assert('getConnection() peer must exist', peer);
return peer;
}
function deleteConnection(id) {
_assert('deleteConnection() peer must exist', peerConnections[id]);
delete peerConnections[id];
}
function stopConnection(id) {
detachVideo(id);
if (isConnectedWith(id)) {
let peer = getConnection(id);
peer.close();
deleteConnection(id);
}
}
function stopAllConnection() {
for (let id in peerConnections) {
stopConnection(id);
}
}
/* --- not used ----
// --- remote streams ---
const ID_SPLITER = ':';
function addRemoteStream(id, stream) {
_assert('addRemoteStream() id=' + id + 'stream:', stream);
let concatId = id + ID_SPLITER + stream.id;
console.log('add remote steram, concatId=' + concatId);
_assert('addRemoteStream() stream must NOT EXIST', (! remoteStreams[concatId]));
remoteStreams[concatId] = stream;
}
function getRemoteStream(id) {
let stream = remoteStreams[id];
_assert('getRemoteStream() stream must exist', stream);
return stream;
}
function deleteRemoteStream(id) {
for (let key in remoteStreams) {
console.log('concatId=' + concatId);
let ids = key.split(ID_SPLITER);
let peerId = ids[0];
let streamId = ids[1];
if (peerId === id) {
delete remoteStreams[id];
}
}
}
function isRemoteStreamExist(id, stream) {
let concatId = id + ID_SPLITER + stream.id;
for (let key in remoteStreams) {
console.log('isRemoteStreamExist key=' + key);
if (key === concatId) {
return true;
}
}
return false;
}
--- not used ----*/
// --- video elements ---
function attachVideo(id, stream) {
let video = addRemoteVideoElement(id);
playVideo(video, stream);
video.volume = 1.0;
}
function detachVideo(id) {
let video = getRemoteVideoElement(id);
pauseVideo(video);
deleteRemoteVideoElement(id);
}
function isRemoteVideoAttached(id) {
if (remoteVideos[id]) {
return true;
}
else {
return false;
}
}
function addRemoteVideoElement(id) {
_assert('addRemoteVideoElement() video must NOT EXIST', (! remoteVideos[id]));
let video = createVideoElement('remote_video_' + id);
remoteVideos[id] = video;
return video;
}
function getRemoteVideoElement(id) {
let video = remoteVideos[id];
_assert('getRemoteVideoElement() video must exist', video);
return video;
}
function deleteRemoteVideoElement(id) {
_assert('deleteRemoteVideoElement() stream must exist', remoteVideos[id]);
removeVideoElement('remote_video_' + id);
delete remoteVideos[id];
}
function createVideoElement(elementId) {
let video = document.createElement('video');
video.width = '240';
video.height = '180';
video.id = elementId;
video.style.border = 'solid black 1px';
video.style.margin = '2px';
container.appendChild(video);
return video;
}
function removeVideoElement(elementId) {
let video = document.getElementById(elementId);
_assert('removeVideoElement() video must exist', video);
container.removeChild(video);
return video;
}
// ---------------------- media handling -----------------------
// start local video
function startVideo() {
getDeviceStream({video: true, audio: true}) // audio: false <-- ontrack once, audio:true --> ontrack twice!!
//navigator.mediaDevices.getUserMedia({video: true, audio: true})
.then(function (stream) { // success
localStream = stream;
playVideo(localVideo, stream);
}).catch(function (error) { // error
console.error('getUserMedia error:', error);
return;
});
}
// stop local video
function stopVideo() {
pauseVideo(localVideo);
stopLocalStream(localStream);
localStream = null;
}
function stopLocalStream(stream) {
let tracks = stream.getTracks();
if (! tracks) {
console.warn('NO tracks');
return;
}
for (let track of tracks) {
track.stop();
}
}
function getDeviceStream(option) {
if ('getUserMedia' in navigator.mediaDevices) {
console.log('navigator.mediaDevices.getUserMadia');
return navigator.mediaDevices.getUserMedia(option);
}
else {
console.log('wrap navigator.getUserMadia with Promise');
return new Promise(function(resolve, reject){
navigator.getUserMedia(option,
resolve,
reject
);
});
}
}
function playVideo(element, stream) {
if ('srcObject' in element) {
element.srcObject = stream;
}
else {
element.src = window.URL.createObjectURL(stream);
}
element.play();
element.volume = 0;
}
function pauseVideo(element) {
element.pause();
if ('srcObject' in element) {
element.srcObject = null;
}
else {
if (element.src && (element.src !== '') ) {
window.URL.revokeObjectURL(element.src);
}
element.src = '';
}
}
/*--
// ----- hand signaling ----
function onSdpText() {
let text = textToReceiveSdp.value;
if (peerConnection) {
console.log('Received answer text...');
let answer = new RTCSessionDescription({
type : 'answer',
sdp : text,
});
setAnswer(answer);
}
else {
console.log('Received offer text...');
let offer = new RTCSessionDescription({
type : 'offer',
sdp : text,
});
setOffer(offer);
}
textToReceiveSdp.value ='';
}
--*/
function sendSdp(id, sessionDescription) {
console.log('---sending sdp ---');
/*---
textForSendSdp.value = sessionDescription.sdp;
textForSendSdp.focus();
textForSendSdp.select();
----*/
let message = { type: sessionDescription.type, sdp: sessionDescription.sdp };
console.log('sending SDP=' + message);
//ws.send(message);
//socket.emit('message', message);
emitTo(id, message);
}
function sendIceCandidate(id, candidate) {
console.log('---sending ICE candidate ---');
let obj = { type: 'candidate', ice: JSON.stringify(candidate) }; // <--- JSON
//let message = JSON.stringify(obj);
//console.log('sending candidate=' + message);
//ws.send(message);
//socket.emit('message', obj);
emitTo(id, obj);
}
// ---------------------- connection handling -----------------------
function prepareNewConnection(id) {
let pc_config = {"iceServers":[{"urls": "stun:stun.l.google.com:19302"}]}; // for STUN server
let peer = new RTCPeerConnection(pc_config);
// --- on get remote stream ---
if ('ontrack' in peer) {
peer.ontrack = function(event) {
let stream = event.streams[0];
console.log('-- peer.ontrack() stream.id=' + stream.id);
if (isRemoteVideoAttached(id)) {
console.log('stream already attached, so ignore');
}
else {
//playVideo(remoteVideo, stream);
attachVideo(id, stream);
}
};
}
else {
peer.onaddstream = function(event) {
let stream = event.stream;
console.log('-- peer.onaddstream() stream.id=' + stream.id);
//playVideo(remoteVideo, stream);
attachVideo(id, stream);
};
}
// --- on get local ICE candidate
peer.onicecandidate = function (evt) {
if (evt.candidate) {
console.log(evt.candidate);
// Trickle ICE の場合は、ICE candidateを相手に送る
sendIceCandidate(id, evt.candidate);
// Vanilla ICE の場合には、何もしない
} else {
console.log('empty ice event');
// Trickle ICE の場合は、何もしない
// Vanilla ICE の場合には、ICE candidateを含んだSDPを相手に送る
//sendSdp(id, peer.localDescription);
}
};
// --- when need to exchange SDP ---
peer.onnegotiationneeded = function(evt) {
console.log('-- onnegotiationneeded() ---');
};
// --- other events ----
peer.onicecandidateerror = function (evt) {
console.error('ICE candidate ERROR:', evt);
};
peer.onsignalingstatechange = function() {
console.log('== signaling status=' + peer.signalingState);
};
peer.oniceconnectionstatechange = function() {
console.log('== ice connection status=' + peer.iceConnectionState);
if (peer.iceConnectionState === 'disconnected') {
console.log('-- disconnected --');
//hangUp();
stopConnection(id);
}
};
peer.onicegatheringstatechange = function() {
console.log('==***== ice gathering state=' + peer.iceGatheringState);
};
peer.onconnectionstatechange = function() {
console.log('==***== connection state=' + peer.connectionState);
};
peer.onremovestream = function(event) {
console.log('-- peer.onremovestream()');
//pauseVideo(remoteVideo);
deleteRemoteStream(id);
detachVideo(id);
};
// -- add local stream --
if (localStream) {
console.log('Adding local stream...');
peer.addStream(localStream);
}
else {
console.warn('no local stream, but continue.');
}
return peer;
}
function makeOffer(id) {
_assert('makeOffer must not connected yet', (! isConnectedWith(id)) );
peerConnection = prepareNewConnection(id);
addConnection(id, peerConnection);
peerConnection.createOffer()
.then(function (sessionDescription) {
console.log('createOffer() succsess in promise');
return peerConnection.setLocalDescription(sessionDescription);
}).then(function() {
console.log('setLocalDescription() succsess in promise');
// -- Trickle ICE の場合は、初期SDPを相手に送る --
sendSdp(id, peerConnection.localDescription);
// -- Vanilla ICE の場合には、まだSDPは送らない --
}).catch(function(err) {
console.error(err);
});
}
function setOffer(id, sessionDescription) {
/*
if (peerConnection) {
console.error('peerConnection alreay exist!');
}
*/
_assert('setOffer must not connected yet', (! isConnectedWith(id)) );
let peerConnection = prepareNewConnection(id);
addConnection(id, peerConnection);
peerConnection.setRemoteDescription(sessionDescription)
.then(function() {
console.log('setRemoteDescription(offer) succsess in promise');
makeAnswer(id);
}).catch(function(err) {
console.error('setRemoteDescription(offer) ERROR: ', err);
});
}
function makeAnswer(id) {
console.log('sending Answer. Creating remote session description...' );
let peerConnection = getConnection(id);
if (! peerConnection) {
console.error('peerConnection NOT exist!');
return;
}
peerConnection.createAnswer()
.then(function (sessionDescription) {
console.log('createAnswer() succsess in promise');
return peerConnection.setLocalDescription(sessionDescription);
}).then(function() {
console.log('setLocalDescription() succsess in promise');
// -- Trickle ICE の場合は、初期SDPを相手に送る --
sendSdp(id, peerConnection.localDescription);
// -- Vanilla ICE の場合には、まだSDPは送らない --
}).catch(function(err) {
console.error(err);
});
}
function setAnswer(id, sessionDescription) {
let peerConnection = getConnection(id);
if (! peerConnection) {
console.error('peerConnection NOT exist!');
return;
}
peerConnection.setRemoteDescription(sessionDescription)
.then(function() {
console.log('setRemoteDescription(answer) succsess in promise');
}).catch(function(err) {
console.error('setRemoteDescription(answer) ERROR: ', err);
});
}
// --- tricke ICE ---
function addIceCandidate(id, candidate) {
let peerConnection = getConnection(id);
if (peerConnection) {
peerConnection.addIceCandidate(candidate);
}
else {
console.error('PeerConnection not exist!');
return;
}
}
// start PeerConnection
function connect() {
/*
debugger; // SHOULD NOT COME HERE
if (! peerConnection) {
console.log('make Offer');
makeOffer();
}
else {
console.warn('peer already exist.');
}
*/
if (! isReadyToConnect()) {
console.warn('NOT READY to connect');
}
else if (! canConnectMore()) {
console.log('TOO MANY connections');
}
else {
callMe();
}
}
// close PeerConnection
function hangUp() {
/*
if (peerConnection) {
console.log('Hang up.');
peerConnection.close();
peerConnection = null;
pauseVideo(remoteVideo);
}
else {
console.warn('peer NOT exist.');
}
*/
emitRoom({ type: 'bye' });
clearMessage(); // clear firebase
stopAllConnection();
}
// ---- multi party --
function callMe() {
emitRoom({type: 'call me'});
}
</script>
</html>