w-converhp 1.0.39 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci-test.yml +1 -1
- package/README.md +188 -169
- package/dist/w-converhp-client.umd.js +2 -2
- package/dist/w-converhp-client.umd.js.map +1 -1
- package/dist/w-converhp-server.umd.js +2 -2
- package/dist/w-converhp-server.umd.js.map +1 -1
- package/docs/WConverhpClient.html +9 -809
- package/docs/WConverhpClient.mjs.html +465 -529
- package/docs/WConverhpServer.html +238 -1340
- package/docs/WConverhpServer.mjs.html +590 -392
- package/docs/index.html +2 -2
- package/package.json +7 -7
- package/scla.mjs +31 -49
- package/sclb.mjs +31 -48
- package/sclc.mjs +42 -0
- package/script.txt +18 -0
- package/src/WConverhpClient.mjs +463 -527
- package/src/WConverhpServer.mjs +588 -390
- package/srv.mjs +24 -46
- package/web.html +93 -76
- package/zdata.b1 +0 -1
package/srv.mjs
CHANGED
|
@@ -5,62 +5,31 @@ import WConverhpServer from './src/WConverhpServer.mjs'
|
|
|
5
5
|
let opt = {
|
|
6
6
|
port: 8080,
|
|
7
7
|
apiName: 'api',
|
|
8
|
+
pathStaticFiles: '.', //要存取專案資料夾下web.html, 故不能給dist
|
|
9
|
+
funCheck: () => {
|
|
10
|
+
return true
|
|
11
|
+
},
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
//new
|
|
11
15
|
let wo = new WConverhpServer(opt)
|
|
12
16
|
|
|
13
|
-
wo.on('open', function() {
|
|
14
|
-
console.log(`Server[port:${opt.port}]: open`)
|
|
15
|
-
|
|
16
|
-
//broadcast
|
|
17
|
-
let n = 0
|
|
18
|
-
setInterval(() => {
|
|
19
|
-
n += 1
|
|
20
|
-
let o = {
|
|
21
|
-
text: `server broadcast hi(${n})`,
|
|
22
|
-
data: new Uint8Array([66, 97, 115]), //support Uint8Array data
|
|
23
|
-
}
|
|
24
|
-
wo.broadcast(o, function (prog) {
|
|
25
|
-
console.log('broadcast prog', prog)
|
|
26
|
-
})
|
|
27
|
-
}, 1000)
|
|
28
|
-
|
|
29
|
-
})
|
|
30
|
-
wo.on('error', function(err) {
|
|
31
|
-
console.log(`Server[port:${opt.port}]: error`, err)
|
|
32
|
-
})
|
|
33
|
-
wo.on('clientChange', function(num) {
|
|
34
|
-
console.log(`Server[port:${opt.port}]: now clients: ${num}`)
|
|
35
|
-
})
|
|
36
|
-
wo.on('clientEnter', function(clientId, data) {
|
|
37
|
-
console.log(`Server[port:${opt.port}]: client enter: ${clientId}`)
|
|
38
|
-
|
|
39
|
-
//deliver
|
|
40
|
-
wo.deliver(clientId, `server deliver hi(${clientId})`)
|
|
41
|
-
|
|
42
|
-
})
|
|
43
|
-
wo.on('clientLeave', function(clientId, data) {
|
|
44
|
-
console.log(`Server[port:${opt.port}]: client leave: ${clientId}`)
|
|
45
|
-
})
|
|
46
17
|
wo.on('execute', function(func, input, pm) {
|
|
47
|
-
//console.log(`Server[port:${opt.port}]: execute`, func, input)
|
|
18
|
+
// console.log(`Server[port:${opt.port}]: execute`, func, input)
|
|
48
19
|
console.log(`Server[port:${opt.port}]: execute`, func)
|
|
49
20
|
|
|
50
21
|
try {
|
|
51
22
|
|
|
52
23
|
if (func === 'add') {
|
|
53
24
|
|
|
54
|
-
//save
|
|
55
25
|
if (_.get(input, 'p.d.u8a', null)) {
|
|
56
|
-
|
|
57
|
-
console.log('writeFileSync input.p.d.name', input.p.d.name)
|
|
26
|
+
console.log('input.p.d.u8a', input.p.d.u8a)
|
|
58
27
|
}
|
|
59
28
|
|
|
60
29
|
let r = {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
30
|
+
_add: input.p.a + input.p.b,
|
|
31
|
+
_data: [11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' }],
|
|
32
|
+
_bin: {
|
|
64
33
|
name: 'zdata.b2',
|
|
65
34
|
u8a: new Uint8Array([66, 97, 115]),
|
|
66
35
|
// name: '100mb.7z',
|
|
@@ -71,7 +40,9 @@ wo.on('execute', function(func, input, pm) {
|
|
|
71
40
|
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\1000mb.7z')),
|
|
72
41
|
},
|
|
73
42
|
}
|
|
43
|
+
|
|
74
44
|
pm.resolve(r)
|
|
45
|
+
|
|
75
46
|
}
|
|
76
47
|
else {
|
|
77
48
|
console.log('invalid func')
|
|
@@ -85,14 +56,21 @@ wo.on('execute', function(func, input, pm) {
|
|
|
85
56
|
}
|
|
86
57
|
|
|
87
58
|
})
|
|
88
|
-
wo.on('
|
|
89
|
-
console.log(`Server[port:${opt.port}]:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
59
|
+
wo.on('upload', function(input, pm) {
|
|
60
|
+
console.log(`Server[port:${opt.port}]: upload`, input)
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
let output = input
|
|
64
|
+
pm.resolve(output)
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
console.log('execute error', err)
|
|
68
|
+
pm.reject('execute error')
|
|
69
|
+
}
|
|
70
|
+
|
|
93
71
|
})
|
|
94
72
|
wo.on('handler', function(data) {
|
|
95
73
|
// console.log(`Server[port:${opt.port}]: handler`, data)
|
|
96
74
|
})
|
|
97
75
|
|
|
98
|
-
//node --experimental-modules
|
|
76
|
+
//node --experimental-modules srv.mjs
|
package/web.html
CHANGED
|
@@ -25,41 +25,16 @@
|
|
|
25
25
|
<script>
|
|
26
26
|
|
|
27
27
|
let opt = {
|
|
28
|
-
// FormData,
|
|
28
|
+
// FormData, //使用瀏覽器內建FormData, 非後端不須另外提供
|
|
29
29
|
url: 'http://localhost:8080',
|
|
30
|
+
apiName: 'api',
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
//new
|
|
33
34
|
let WConverhpClient=window['w-converhp-client']
|
|
34
35
|
let wo = new WConverhpClient(opt)
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
console.log('client web: open')
|
|
38
|
-
})
|
|
39
|
-
wo.on('openOnce', function() {
|
|
40
|
-
console.log('client web: openOnce')
|
|
41
|
-
|
|
42
|
-
//uploadU8a
|
|
43
|
-
uploadU8a()
|
|
44
|
-
|
|
45
|
-
})
|
|
46
|
-
wo.on('close', function() {
|
|
47
|
-
console.log('client web: close')
|
|
48
|
-
})
|
|
49
|
-
wo.on('error', function(err) {
|
|
50
|
-
console.log('client web: error', err)
|
|
51
|
-
})
|
|
52
|
-
wo.on('reconn', function() {
|
|
53
|
-
console.log('client web: reconn')
|
|
54
|
-
})
|
|
55
|
-
wo.on('broadcast', function(data) {
|
|
56
|
-
console.log('client web: broadcast', data)
|
|
57
|
-
})
|
|
58
|
-
wo.on('deliver', function(data) {
|
|
59
|
-
console.log('client web: deliver', data)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
function core(name, ab){
|
|
37
|
+
async function execute(name, u8a){
|
|
63
38
|
|
|
64
39
|
//p
|
|
65
40
|
let p = {
|
|
@@ -68,77 +43,107 @@
|
|
|
68
43
|
c: 'test中文',
|
|
69
44
|
d: {
|
|
70
45
|
name: name,
|
|
71
|
-
u8a
|
|
72
|
-
}
|
|
46
|
+
u8a,
|
|
47
|
+
},
|
|
73
48
|
}
|
|
74
49
|
console.log('p',p)
|
|
75
50
|
|
|
76
51
|
//execute
|
|
77
|
-
wo.execute('add', { p
|
|
52
|
+
await wo.execute('add', { p },
|
|
78
53
|
function (prog, p, m) {
|
|
79
54
|
console.log('client web: execute: prog', prog, p, m)
|
|
80
55
|
})
|
|
81
56
|
.then(function(r) {
|
|
82
57
|
console.log('client web: execute: add', r)
|
|
83
|
-
wsemi.downloadFileFromU8Arr(r.
|
|
58
|
+
wsemi.downloadFileFromU8Arr(r._bin.name,r._bin.u8a)
|
|
84
59
|
})
|
|
85
60
|
.catch(function (err) {
|
|
86
61
|
console.log('client web: execute: catch', err)
|
|
87
62
|
})
|
|
88
63
|
|
|
89
|
-
|
|
90
|
-
wo.broadcast('client web broadcast hi', function (prog) {
|
|
91
|
-
console.log('client web: broadcast: prog', prog)
|
|
92
|
-
})
|
|
93
|
-
.catch(function (err) {
|
|
94
|
-
console.log('client web: broadcast: catch', err)
|
|
95
|
-
})
|
|
64
|
+
}
|
|
96
65
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
console.log('client web: deliver: prog', prog)
|
|
100
|
-
})
|
|
101
|
-
.catch(function (err) {
|
|
102
|
-
console.log('client web: deliver: catch', err)
|
|
103
|
-
})
|
|
66
|
+
function executeWithU8a() {
|
|
67
|
+
let core = async()=>{
|
|
104
68
|
|
|
105
|
-
|
|
69
|
+
//u8a
|
|
70
|
+
let u8a = new Uint8Array([66, 97, 115])
|
|
71
|
+
console.log('executeWithU8a u8a', u8a)
|
|
72
|
+
|
|
73
|
+
//execute
|
|
74
|
+
await execute('zdata.b1', u8a)
|
|
106
75
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
let bb = new Blob([u8a])
|
|
110
|
-
wsemi.blob2ab(bb)
|
|
111
|
-
.then(function(ab){
|
|
112
|
-
console.log('uploadU8a ab',ab)
|
|
113
|
-
core('zdata.b1', ab)
|
|
114
|
-
})
|
|
76
|
+
}
|
|
77
|
+
core()
|
|
115
78
|
}
|
|
116
79
|
|
|
117
|
-
function
|
|
80
|
+
function executeWithFile() {
|
|
81
|
+
let core = async()=>{
|
|
118
82
|
|
|
119
|
-
|
|
120
|
-
.
|
|
121
|
-
console.log('domShowInputAndGetFiles msg',msg)
|
|
83
|
+
let msg = await wsemi.domShowInputAndGetFiles({ sizeMbLimit: 100*1000 }) //100g
|
|
84
|
+
console.log('domShowInputAndGetFiles msg',msg)
|
|
122
85
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
86
|
+
//check
|
|
87
|
+
if(Object.keys(msg.errs).length > 0){
|
|
88
|
+
console.log('errs',msg.errs)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
128
91
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
92
|
+
//check
|
|
93
|
+
if(msg.files.length===0){
|
|
94
|
+
return
|
|
95
|
+
}
|
|
132
96
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
console.log('uploadFile ab',ab)
|
|
137
|
-
core(file.name,ab)
|
|
138
|
-
})
|
|
97
|
+
//file
|
|
98
|
+
let file = msg.files[0]
|
|
99
|
+
console.log('file',file)
|
|
139
100
|
|
|
140
|
-
|
|
101
|
+
//blob2u8arr
|
|
102
|
+
let u8a = await wsemi.blob2u8arr(file)
|
|
103
|
+
console.log('executeWithFile u8a',u8a)
|
|
104
|
+
|
|
105
|
+
//execute
|
|
106
|
+
await execute(file.name,u8a)
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
core()
|
|
110
|
+
}
|
|
141
111
|
|
|
112
|
+
function uploadLargeFile(){
|
|
113
|
+
let core = async()=>{
|
|
114
|
+
|
|
115
|
+
let msg = await wsemi.domShowInputAndGetFiles({ sizeMbLimit: 100*1000 }) //100g
|
|
116
|
+
console.log('domShowInputAndGetFiles msg',msg)
|
|
117
|
+
|
|
118
|
+
//check
|
|
119
|
+
if(Object.keys(msg.errs).length > 0){
|
|
120
|
+
console.log('errs',msg.errs)
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//check
|
|
125
|
+
if(msg.files.length===0){
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//file
|
|
130
|
+
let file = msg.files[0]
|
|
131
|
+
console.log('file',file)
|
|
132
|
+
|
|
133
|
+
//upload
|
|
134
|
+
await wo.upload(file.name, file,
|
|
135
|
+
function (prog, p, m) {
|
|
136
|
+
console.log('client web: upload: prog', prog, p, m)
|
|
137
|
+
})
|
|
138
|
+
.then(function(res) {
|
|
139
|
+
console.log('client web: upload: then', res)
|
|
140
|
+
})
|
|
141
|
+
.catch(function (err) {
|
|
142
|
+
console.log('client web: upload: catch', err)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
core()
|
|
142
147
|
}
|
|
143
148
|
|
|
144
149
|
</script>
|
|
@@ -147,12 +152,24 @@
|
|
|
147
152
|
|
|
148
153
|
<body>
|
|
149
154
|
|
|
150
|
-
<div>
|
|
155
|
+
<div style="padding:10px;">
|
|
151
156
|
|
|
152
|
-
<button onclick="
|
|
157
|
+
<button onclick="executeWithU8a()">execute with u8a</button>
|
|
153
158
|
|
|
154
159
|
</div>
|
|
155
160
|
|
|
161
|
+
<div style="padding:10px;">
|
|
162
|
+
|
|
163
|
+
<button onclick="executeWithFile()">execute with file</button>
|
|
164
|
+
|
|
165
|
+
</div>
|
|
166
|
+
|
|
167
|
+
<div style="padding:10px;">
|
|
168
|
+
|
|
169
|
+
<button onclick="uploadLargeFile()">upload large file</button>
|
|
170
|
+
|
|
171
|
+
</div>
|
|
172
|
+
|
|
156
173
|
</body>
|
|
157
174
|
|
|
158
175
|
</html>
|
package/zdata.b1
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Bas
|