-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvideocallingbistri.html
220 lines (185 loc) · 7.22 KB
/
videocallingbistri.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
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noindex, nofollow">
<script type="text/javascript" src="/js/lib/dummy.js"></script>
<script type="text/javascript" src="https://api.bistri.com/bistri.conference.min.js"></script>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<style type="text/css">
.pane {
margin: 20px;
text-align: center;
}
video {
width: 100%;
}
</style>
<title>Video Conference</title>
<script type="text/javascript">//<![CDATA[
window.onload=function(){
/*
JS library reference:
http://developers.bistri.com/webrtc-sdk/js-library-reference
*/
var room;
var members;
var localStream;
// when Bistri API client is ready, function
// "onBistriConferenceReady" is invoked
onBistriConferenceReady = function () {
// test if the browser is WebRTC compatible
if ( !bc.isCompatible() ) {
// if the browser is not compatible, display an alert
alert( "your browser is not WebRTC compatible !" );
// then stop the script execution
return;
}
// initialize API client with application keys
// if you don't have your own, you can get them at:
// https://api.developers.bistri.com/login
bc.init( {
"appId": "38077edb",
"appKey": "4f304359baa6d0fd1f9106aaeb116f33"
} );
/* Set events handler */
// when local user is connected to the server
bc.signaling.bind( "onConnected", function () {
// show pane with id "pane_1"
showPanel( "pane_1" );
} );
// when an error occured on the server side
bc.signaling.bind( "onError", function ( error ) {
// display an alert message
alert( error.text + " (" + error.code + ")" );
} );
// when the user has joined a room
bc.signaling.bind( "onJoinedRoom", function ( data ) {
// set the current room name
room = data.room;
members = data.members;
// ask the user to access to his webcam
bc.startStream( "webcam-sd", function( stream ){
// affect stream to "localStream" var
localStream = stream;
// when webcam access has been granted
// show pane with id "pane_2"
showPanel( "pane_2" );
// insert the local webcam stream into div#video_container node
bc.attachStream( stream, q( "#video_container" ), { mirror: true } );
// then, for every single members present in the room ...
for ( var i=0, max=members.length; i<max; i++ ) {
// ... request a call
bc.call( members[ i ].id, room, { "stream": stream } );
}
} );
} );
// when an error occurred while trying to join a room
bc.signaling.bind( "onJoinRoomError", function ( error ) {
// display an alert message
alert( error.text + " (" + error.code + ")" );
} );
// when the local user has quitted the room
bc.signaling.bind( "onQuittedRoom", function( room ) {
// stop the local stream
bc.stopStream( localStream, function(){
// remove the stream from the page
bc.detachStream( localStream );
// show pane with id "pane_1"
showPanel( "pane_1" );
} );
} );
// when a new remote stream is received
bc.streams.bind( "onStreamAdded", function ( remoteStream ) {
// insert the new remote stream into div#video_container node
bc.attachStream( remoteStream, q( "#video_container" ) );
} );
// when a remote stream has been stopped
bc.streams.bind( "onStreamClosed", function ( stream ) {
// remove the stream from the page
bc.detachStream( stream );
} );
// when a local stream cannot be retrieved
bc.streams.bind( "onStreamError", function( error ){
switch( error.name ){
case "PermissionDeniedError":
alert( "Webcam access has not been allowed" );
bc.quitRoom( room );
break
case "DevicesNotFoundError":
if( confirm( "No webcam/mic found on this machine. Process call anyway ?" ) ){
// show pane with id "pane_2"
showPanel( "pane_2" );
for ( var i=0, max=members.length; i<max; i++ ) {
// ... request a call
bc.call( members[ i ].id, room );
}
}
else{
bc.quitRoom( room );
}
break
}
} );
// bind function "joinConference" to button "Join Conference Room"
q( "#join" ).addEventListener( "click", joinConference );
// bind function "quitConference" to button "Quit Conference Room"
q( "#quit" ).addEventListener( "click", quitConference );
// open a new session on the server
bc.connect();
}
// when button "Join Conference Room" has been clicked
function joinConference(){
var roomToJoin = q( "#room_field" ).value;
// if "Conference Name" field is not empty ...
if( roomToJoin ){
// ... join the room
bc.joinRoom( roomToJoin );
}
else{
// otherwise, display an alert
alert( "you must enter a room name !" )
}
}
// when button "Quit Conference Room" has been clicked
function quitConference(){
// quit the current conference room
bc.quitRoom( room );
}
function showPanel( id ){
var panes = document.querySelectorAll( ".pane" );
// for all nodes matching the query ".pane"
for( var i=0, max=panes.length; i<max; i++ ){
// hide all nodes except the one to show
panes[ i ].style.display = panes[ i ].id == id ? "block" : "none";
};
}
function q( query ){
// return the DOM node matching the query
return document.querySelector( query );
}
}//]]>
</script>
<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/undefined"></head>
<body>
<div class="pane" id="pane_0" style="display: none;">
<img src="http://static.tumblr.com/uzwqx7a/8VIm8jofz/logo.png">
</div>
<input type="text" placeholder="Conference Name" id="room_field" class="form-control"><div class="pane" id="pane_1" style="display: block;">
<br>
<input type="button" value="Join Conference Room" id="join" class="btn btn-info btn-default btn-block">
</div>
<div class="pane" id="pane_2" style="display: none">
<div id="video_container"></div>
<input type="button" value="Quit Conference Room" id="quit" class="btn btn-danger btn-default btn-block">
</div>
<script>
// tell the embed parent frame the height of the content
if (window.parent && window.parent.parent){
window.parent.parent.postMessage(["resultsFrame", {
height: document.body.getBoundingClientRect().height,
slug: "SjQ6T"
}], "*")
}
</script>
</body></html>