forked from webber0928/socketDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex1.html
58 lines (54 loc) · 1.86 KB
/
index1.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
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial;}
form { background: #000; padding: 50px; width: 100%; height: 100vh; text-align: center;margin:0px auto;}
form button { width: 20%; background: rgb(130, 224, 255); height: 20vh; border: none; margin: 0px auto;font-size: 3em;}
form input { width: 70%; border: none; height: 20vh; margin: 0px auto; font-size: 3em; }
#er { font-size: 4em; color: #ddd;}
</style>
</head>
<body>
<form action="">
<input id="m" type="text" placeholder="輸入PC端網頁上的手機配對碼">
<button>Send</button>
<h1 id="er"></h1>
</form>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
var socket = io();
var channel = 'chat message';
var code;
$('form').submit(function(){
$('#er').text("");
code = $('#m').val();
socket.emit('ask_channel', code);
setTimeout(function(){
if(code !== channel) $('#er').text("手機配對碼錯誤,請重新輸入");
},1000);
return false;
});
socket.on('answer_channel',function(msg){
if(code == msg) channel = code;
$('h1').text("配對成功~!")
});
var angle;
window.addEventListener("orientationchange", function() {
var msg = {
orientation:window.orientation,
play :'start',
room :channel
};
if(angle !== msg.orientation){
angle = msg.orientation;
(msg.orientation < 0)? msg.play = 'start' : msg.play = 'stop';
socket.emit('linked', msg);
}
}, false);
</script>
</body>
</html>