-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobile.html
321 lines (261 loc) · 9.16 KB
/
mobile.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
<html>
<head>
<link rel="stylesheet" type="text/css" href="smart-grid.css">
<style>
body {
background-color: black;
}
.container {
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
}
#fullvideo_container {
z-index: 0;
}
#smallvideo_container {
z-index: 1;
}
#fullvideo_div {
}
#smallvideo_row {
width: 100%;
position: absolute;
bottom: 0px;
}
#messages {
height: 120px;
overflow: hidden;
}
#smallvideo_div {
bottom: 0px;
}
.message {
margin: 10px 10px 10px 10px;
padding: 5px 5px 5px 5px;
font-family: sans-serif;
background-color: rgb(128,128,128);
font-size: 30px;
color: rgb(0,0,0);
/*text-shadow: 1px 1 px rgb(255,255,255);*/
}
button {
font-family: sans-serif;
color: black;
border: 2px solid black;
width: 75px;
height: 50px;
margin: 5px 5px 5px 5px;
}
#okbutton {
background-color: white;
}
#helpbutton {
background-color: red;
}
</style>
<script src="peer.min.js"></script>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
var socket = io.connect();
socket.on('connect', function() {
socket.emit('type','mobile');
if (peer_id != null) {
socket.emit('peerid',peer_id);
}
});
socket.on('chatmessage', function (data) {
var newmessage = document.createElement("div");
newmessage.className = "message";
newmessage.innerHTML = data;
var messages = document.getElementById("messages");
if (messages.children.length > 0) {
messages.insertBefore(newmessage, messages.children[0]);
} else {
messages.appendChild(newmessage);
}
//document.getElementById("messages").innerHTML = data + "<br />\n" + document.getElementById("messages").innerHTML;
});
socket.on('peerid', function(data) {
makeCall(data);
});
function sendPanic() {
socket.emit('panic',"");
}
function sendMessage(message) {
socket.emit('chatmessage', message);
};
/* Get User Media */
var my_stream = null;
var peer_id = null;
var peer;
var mediaConstraints = { audio: true, video: true};
//{ width: 640, height: 480, facingMode: "environment" }
if (navigator.mediaDevices.getUserMedia) {
console.log("navigator.mediaDevices.getUserMedia");
navigator.mediaDevices.getUserMedia(mediaConstraints).then(function(stream) {
my_stream = stream;
// var videoElement = document.getElementById('myvideo');
// videoElement.src = window.URL.createObjectURL(stream) || stream;
// videoElement.onloadedmetadata = function(e) {
// //console.log(e);
// ///videoElement.width = e.target.videoWidth;
// //videoElement.height = e.target.videoHeight;
// };
// videoElement.play();
peer = new Peer({host: 'liveweb.itp.io', port: 9000, path: '/'});
peer.on('open', function(id) {
peer_id = id;
console.log(peer_id);
if (socket != null) {
socket.emit('peerid', peer_id);
}
});
peer.on('error', function(error) {
console.log(error);
});
peer.on('call', function(incoming_call) {
console.log("Got a call!");
incoming_call.answer(my_stream);
incoming_call.on('stream', function(remoteStream) {
var ovideoElement = document.getElementById('othervideo');
ovideoElement.src = window.URL.createObjectURL(remoteStream) || remoteStream;
ovideoElement.onloadedmetadata = function(e) {
//ovideoElement.width = e.target.videoWidth;
//ovideoElement.height = e.target.videoHeight;
};
ovideoElement.play();
//var ovideoElement = document.createElement('video');
//ovideoElement.src = window.URL.createObjectURL(remoteStream) || remoteStream;
//ovideoElement.setAttribute("autoplay", "true");
//ovideoElement.setAttribute("id", incoming_call.peer);
//ovideoElement.setAttribute("controls", "controls");
//ovideoElement.play();
////document.body.appendChild(ovideoElement);
//document.getElementById('othervideo').appendChild(ovideoElement);
});
incoming_call.on('close', function() {
var ovideoElement = document.getElementById('othervideo');
ovideoElement.src = null;
//var ovideoElement = document.getElementById(incoming_call.peer);
//ovideoElement.parentElement.removeChild(ovideoElement);
});
incoming_call.on('error', function(err) {
console.log(err);
var ovideoElement = document.getElementById('othervideo');
ovideoElement.src = null;
//var ovideoElement = document.getElementById(incoming_call.peer);
//if (ovideoElement != null) {
// ovideoElement.parentElement.removeChild(ovideoElement);
//}
}); //incoming_call.on('error
}); //peer.on('call')
}).catch(function(err) {
console.log('Failed to get local stream' ,err);
}); //catch
}// if (getusermedia)
function makeCall(peeridtocall) {
var call = peer.call(peeridtocall,my_stream);
call.on('stream', function(remoteStream) {
var ovideoElement = document.getElementById('othervideo');
ovideoElement.src = window.URL.createObjectURL(remoteStream) || remoteStream;
ovideoElement.onloadedmetadata = function(e) {
//ovideoElement.width = e.target.videoWidth;
//ovideoElement.height = e.target.videoHeight;
};
ovideoElement.play();
//var ovideoElement = document.createElement('video');
//ovideoElement.src = window.URL.createObjectURL(remoteStream) || remoteStream;
//ovideoElement.setAttribute("autoplay", "true");
//ovideoElement.setAttribute("id", call.peer);
//ovideoElement.play();
////document.body.appendChild(ovideoElement);
//document.getElementById('othervideo').appendChild(ovideoElement);
});
call.on('close', function() {
var ovideoElement = document.getElementById('othervideo');
ovideoElement.src = null;
//var ovideoElement = document.getElementById(call.peer);
//ovideoElement.parentElement.removeChild(ovideoElement);
});
call.on('error', function(err) {
var ovideoElement = document.getElementById('othervideo');
ovideoElement.src = null;
//var ovideoElement = document.getElementById(call.peer);
//if (ovideoElement != null) {
// ovideoElement.parentElement.removeChild(ovideoElement);
//}
});
}
if (navigator.geolocation)
{
navigator.geolocation.watchPosition(successCallback, errorCallback, {});
function successCallback(currentPosition) {
//var lat = currentPosition.coords.latitude;
//var lng = currentPosition.coords.longitude;
socket.emit('location', {lat: currentPosition.coords.latitude, lng: currentPosition.coords.longitude});
}
function errorCallback(e) {
console.log(e);
}
} else {
console.log("Geolocation Not Allowed");
}
var landscapeOrPortrait = "landscape";
function init() {
if (navigator.getUserMedia) {
console.log("navigator.getUserMedia");
} else {
console.log("navigator.getUserMedia is false");
}
if (navigator.mediaDevices.getUserMedia) {
console.log("navigator.mediaDevices.getUserMedia");
} else {
console.log("navigator.mediaDevices.getUserMedia is false");
}
if (window.innerHeight > window.innerWidth){
landscapeOrPortrait = "portrait";
}
console.log(landscapeOrPortrait);
// if (landscapeOrPortrait == "landscape") {
// // document.getElementById('myvideo').width=null;
// document.getElementById('myvideo').height=window.innerHeight;
// } else {
// document.getElementById('myvideo').width=window.innerWidth;
// // document.getElementById('myvideo').height=null;
// }
}
window.addEventListener('load', init);
</script>
</head>
<body>
<div class="container" id="fullvideo_container">
<div class="row" id="fullvideo_row">
<div id="fullvideo_div" class="columns twelve">
<!-- <video id="myvideo" muted autoplay></video> -->
<img src="stopandfrisk.jpg">
</div>
</div>
</div>
<div class="container" id="smallvideo_container">
<div class="row" id="smallvideo_row">
<div id="messages" class="columns seven">
<div class="message">Last message from a distant witness </div>
<div class="message">Long message from a distant witness which should have a line break or something of the sort depending on the screen size </div>
<div class="message">First message from a distant witness </div>
</div>
<div id="panel" class="columns two">
<button id="okbutton" onclick="sendMessage('Ok');">OK</button>
<button id="helpbutton" onclick="sendPanic();">HELP</button>
</div>
<div id="smallvideo_div" class="columns three">
<video id="othervideo" width="160" height="120" muted autoplay>
<!-- Could put a default source -->
</video>
</div>
</div>
</div>
</body>
</html>