/
web.html
100 lines (84 loc) · 3.72 KB
/
web.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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-tw">
<head>
<meta http-equiv="content-type" content="text/html charset=UTF-8" />
<title>socket.io</title>
<script nomodule src="https://cdn.jsdelivr.net/npm/@babel/polyfill/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/wsemi/dist/wsemi.umd.js"></script>
<script src="dist/w-comor-socketio-client.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/w-consolelog/dist/w-consolelog.umd.js"></script>
<script>
console.log = window['w-consolelog']
</script>
<script>
//使用本機瀏覽會因為跨域無法瀏覽, 錯誤訊息為: from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
//記得使用瀏覽器瀏覽: http://localhost:8080/web.html
//opt
let opt = {
url: 'http://localhost:8080',
token: '*',
open: function() {
console.log('client web: open')
},
close: function() {
console.log('client web: close')
},
error: function(err) {
console.log('client web: error:', err)
},
reconn: function() {
console.log('client web: reconn')
},
}
//WComorSocketioClient
let WComorSocketioClient = window['w-comor-socketio-client']
new WComorSocketioClient(opt)
.then(function(wo) {
console.log('client web: funcs: ', wo)
function core(ps) {
wo.group.plus(ps)
.then(function(r) {
console.log('client web: plus(' + JSON.stringify(ps) + ') = ', r)
})
.catch(function(err) {
console.log('client web: plus: catch: ', err)
})
wo.group.div(ps)
.then(function(r) {
console.log('client web: div(' + JSON.stringify(ps) + ') = ', r)
})
.catch(function(err) {
console.log('client web: div: catch: ', err)
})
wo.add(ps)
.then(function(r) {
console.log('client web: add(' + JSON.stringify(ps) + ') = ', r)
})
.catch(function(err) {
console.log('client web: add: catch: ', err)
})
wo.minu(ps)
.then(function(r) {
console.log('client web: minu(' + JSON.stringify(ps) + ') = ', r)
})
.catch(function(err) {
console.log('client web: minu: catch: ', err)
})
}
let i = 100
setInterval(function() {
i += 1
core({
p1: i,
p2: 10,
})
}, 1000)
})
.catch(function(err) {
console.log('client web: catch: ', err)
})
</script>
</head>
<body>
</body>
</html>