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/README.md
CHANGED
|
@@ -4,7 +4,6 @@ An operator for hapi in nodejs and browser.
|
|
|
4
4
|

|
|
5
5
|
[](https://npmjs.org/package/w-converhp)
|
|
6
6
|
[](https://npmjs.org/package/w-converhp)
|
|
7
|
-
[](https://github.com/yuda-lyu/w-converhp)
|
|
8
7
|
[](https://npmjs.org/package/w-converhp)
|
|
9
8
|
[](https://npmjs.org/package/w-converhp)
|
|
10
9
|
[](https://www.jsdelivr.com/package/npm/w-converhp)
|
|
@@ -34,68 +33,44 @@ import WConverhpServer from 'w-converhp/dist/w-converhp-server.umd.js'
|
|
|
34
33
|
let opt = {
|
|
35
34
|
port: 8080,
|
|
36
35
|
apiName: 'api',
|
|
36
|
+
pathStaticFiles: '.', //要存取專案資料夾下web.html, 故不能給dist
|
|
37
|
+
funCheck: () => {
|
|
38
|
+
return true
|
|
39
|
+
},
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
//new
|
|
40
43
|
let wo = new WConverhpServer(opt)
|
|
41
44
|
|
|
42
|
-
wo.on('open', function() {
|
|
43
|
-
console.log(`Server[port:${opt.port}]: open`)
|
|
44
|
-
|
|
45
|
-
//broadcast
|
|
46
|
-
let n = 0
|
|
47
|
-
setInterval(() => {
|
|
48
|
-
n += 1
|
|
49
|
-
let o = {
|
|
50
|
-
text: `server broadcast hi(${n})`,
|
|
51
|
-
data: new Uint8Array([66, 97, 115]), //support Uint8Array data
|
|
52
|
-
}
|
|
53
|
-
wo.broadcast(o, function (prog) {
|
|
54
|
-
console.log('broadcast prog', prog)
|
|
55
|
-
})
|
|
56
|
-
}, 1000)
|
|
57
|
-
|
|
58
|
-
})
|
|
59
|
-
wo.on('error', function(err) {
|
|
60
|
-
console.log(`Server[port:${opt.port}]: error`, err)
|
|
61
|
-
})
|
|
62
|
-
wo.on('clientChange', function(num) {
|
|
63
|
-
console.log(`Server[port:${opt.port}]: now clients: ${num}`)
|
|
64
|
-
})
|
|
65
|
-
wo.on('clientEnter', function(clientId, data) {
|
|
66
|
-
console.log(`Server[port:${opt.port}]: client enter: ${clientId}`)
|
|
67
|
-
|
|
68
|
-
//deliver
|
|
69
|
-
wo.deliver(clientId, `server deliver hi(${clientId})`)
|
|
70
|
-
|
|
71
|
-
})
|
|
72
|
-
wo.on('clientLeave', function(clientId, data) {
|
|
73
|
-
console.log(`Server[port:${opt.port}]: client leave: ${clientId}`)
|
|
74
|
-
})
|
|
75
45
|
wo.on('execute', function(func, input, pm) {
|
|
76
|
-
//console.log(`Server[port:${opt.port}]: execute`, func, input)
|
|
46
|
+
// console.log(`Server[port:${opt.port}]: execute`, func, input)
|
|
77
47
|
console.log(`Server[port:${opt.port}]: execute`, func)
|
|
78
48
|
|
|
79
49
|
try {
|
|
80
50
|
|
|
81
51
|
if (func === 'add') {
|
|
82
52
|
|
|
83
|
-
//save
|
|
84
53
|
if (_.get(input, 'p.d.u8a', null)) {
|
|
85
|
-
|
|
86
|
-
// console.log('writeFileSync input.p.d.name', input.p.d.name)
|
|
54
|
+
console.log('input.p.d.u8a', input.p.d.u8a)
|
|
87
55
|
}
|
|
88
56
|
|
|
89
57
|
let r = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
58
|
+
_add: input.p.a + input.p.b,
|
|
59
|
+
_data: [11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' }],
|
|
60
|
+
_bin: {
|
|
93
61
|
name: 'zdata.b2',
|
|
94
62
|
u8a: new Uint8Array([66, 97, 115]),
|
|
95
|
-
//
|
|
63
|
+
// name: '100mb.7z',
|
|
64
|
+
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\100mb.7z')),
|
|
65
|
+
// name: '500mb.7z',
|
|
66
|
+
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\500mb.7z')),
|
|
67
|
+
// name: '1000mb.7z',
|
|
68
|
+
// u8a: new Uint8Array(fs.readFileSync('D:\\開源-JS-006-2-w-converhp\\_temp\\1000mb.7z')),
|
|
96
69
|
},
|
|
97
70
|
}
|
|
71
|
+
|
|
98
72
|
pm.resolve(r)
|
|
73
|
+
|
|
99
74
|
}
|
|
100
75
|
else {
|
|
101
76
|
console.log('invalid func')
|
|
@@ -109,27 +84,23 @@ wo.on('execute', function(func, input, pm) {
|
|
|
109
84
|
}
|
|
110
85
|
|
|
111
86
|
})
|
|
112
|
-
wo.on('
|
|
113
|
-
console.log(`Server[port:${opt.port}]:
|
|
87
|
+
wo.on('upload', function(input, pm) {
|
|
88
|
+
console.log(`Server[port:${opt.port}]: upload`, input)
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
let output = input
|
|
92
|
+
pm.resolve(output)
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
console.log('execute error', err)
|
|
96
|
+
pm.reject('execute error')
|
|
97
|
+
}
|
|
98
|
+
|
|
114
99
|
})
|
|
115
|
-
wo.on('
|
|
116
|
-
console.log(`Server[port:${opt.port}]:
|
|
100
|
+
wo.on('handler', function(data) {
|
|
101
|
+
// console.log(`Server[port:${opt.port}]: handler`, data)
|
|
117
102
|
})
|
|
118
103
|
|
|
119
|
-
// Server running at: http://localhost:8080
|
|
120
|
-
// Server[port:8080]: open
|
|
121
|
-
// Server[port:8080]: execute add
|
|
122
|
-
// Server[port:8080]: broadcast client nodejs[port:8080] broadcast hi
|
|
123
|
-
// Server[port:8080]: deliver client nodejs[port:8080] deliver hi
|
|
124
|
-
// Server[port:8080]: client enter: [random key]
|
|
125
|
-
// Server[port:8080]: now clients: 1
|
|
126
|
-
// broadcast prog 100
|
|
127
|
-
// Server[port:8080]: execute add
|
|
128
|
-
// Server[port:8080]: broadcast client web broadcast hi
|
|
129
|
-
// Server[port:8080]: deliver client web deliver hi
|
|
130
|
-
// Server[port:8080]: client enter: [random key]
|
|
131
|
-
// Server[port:8080]: now clients: 2
|
|
132
|
-
// broadcast prog 100
|
|
133
104
|
```
|
|
134
105
|
#### Example for w-converhp-client:
|
|
135
106
|
> **Link:** [[dev source code](https://github.com/yuda-lyu/w-converhp/blob/master/scla.mjs)]
|
|
@@ -137,6 +108,7 @@ wo.on('deliver', function(data) {
|
|
|
137
108
|
import WConverhpClient from 'w-converhp/dist/w-converhp-client.umd.js'
|
|
138
109
|
|
|
139
110
|
let opt = {
|
|
111
|
+
FormData,
|
|
140
112
|
url: 'http://localhost:8080',
|
|
141
113
|
apiName: 'api',
|
|
142
114
|
}
|
|
@@ -144,80 +116,90 @@ let opt = {
|
|
|
144
116
|
//new
|
|
145
117
|
let wo = new WConverhpClient(opt)
|
|
146
118
|
|
|
147
|
-
|
|
148
|
-
console.log('client nodejs[port:8080]: open')
|
|
149
|
-
})
|
|
150
|
-
wo.on('openOnce', function() {
|
|
151
|
-
console.log('client nodejs[port:8080]: openOnce')
|
|
119
|
+
async function execute(name, u8a) {
|
|
152
120
|
|
|
153
121
|
//p
|
|
154
|
-
let name = 'zdata.b1'
|
|
155
122
|
let p = {
|
|
156
123
|
a: 12,
|
|
157
124
|
b: 34.56,
|
|
158
125
|
c: 'test中文',
|
|
159
126
|
d: {
|
|
160
|
-
name
|
|
161
|
-
u8a
|
|
162
|
-
|
|
163
|
-
}
|
|
127
|
+
name,
|
|
128
|
+
u8a,
|
|
129
|
+
},
|
|
164
130
|
}
|
|
131
|
+
console.log('p', p)
|
|
165
132
|
|
|
166
133
|
//execute
|
|
167
|
-
wo.execute('add', { p },
|
|
134
|
+
await wo.execute('add', { p },
|
|
168
135
|
function (prog, p, m) {
|
|
169
|
-
console.log('client
|
|
136
|
+
console.log('client web: execute: prog', prog, p, m)
|
|
170
137
|
})
|
|
171
138
|
.then(function(r) {
|
|
172
|
-
console.log('client
|
|
139
|
+
console.log('client web: execute: add', r)
|
|
140
|
+
console.log('r._bin.name', r._bin.name, 'r._bin.u8a', r._bin.u8a)
|
|
141
|
+
// w.downloadFileFromU8Arr(r._bin.name, r._bin.u8a)
|
|
173
142
|
})
|
|
174
|
-
.catch(function(err) {
|
|
175
|
-
console.log('client
|
|
143
|
+
.catch(function (err) {
|
|
144
|
+
console.log('client web: execute: catch', err)
|
|
176
145
|
})
|
|
177
146
|
|
|
178
|
-
|
|
179
|
-
wo.broadcast('client nodejs[port:8080] broadcast hi', function (prog) {
|
|
180
|
-
console.log('client nodejs[port:8080]: broadcast: prog', prog)
|
|
181
|
-
})
|
|
182
|
-
.catch(function(err) {
|
|
183
|
-
console.log('client nodejs[port:8080]: broadcast: catch', err)
|
|
184
|
-
})
|
|
147
|
+
}
|
|
185
148
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
console.log('client nodejs[port:8080]: deliver: prog', prog)
|
|
189
|
-
})
|
|
190
|
-
.catch(function(err) {
|
|
191
|
-
console.log('client nodejs[port:8080]: deliver: catch', err)
|
|
192
|
-
})
|
|
149
|
+
function executeWithU8a() {
|
|
150
|
+
let core = async() => {
|
|
193
151
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
152
|
+
//u8a
|
|
153
|
+
let u8a = new Uint8Array([66, 97, 115])
|
|
154
|
+
console.log('executeWithU8a u8a', u8a)
|
|
155
|
+
|
|
156
|
+
//execute
|
|
157
|
+
await execute('zdata.b1', u8a)
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
core()
|
|
161
|
+
}
|
|
162
|
+
executeWithU8a()
|
|
163
|
+
|
|
164
|
+
function executeWithFile() {
|
|
165
|
+
let core = async() => {
|
|
166
|
+
|
|
167
|
+
//u8a
|
|
168
|
+
let u8a = new Uint8Array(fs.readFileSync('../_data/10mb.7z'))
|
|
169
|
+
console.log('executeWithFile u8a', u8a)
|
|
170
|
+
|
|
171
|
+
//execute
|
|
172
|
+
await execute('10mb.7z', u8a)
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
core()
|
|
176
|
+
}
|
|
177
|
+
executeWithFile()
|
|
178
|
+
|
|
179
|
+
function uploadLargeFile() {
|
|
180
|
+
let core = async() => {
|
|
181
|
+
|
|
182
|
+
//u8a
|
|
183
|
+
let u8a = new Uint8Array(fs.readFileSync('../_data/1000mb.7z'))
|
|
184
|
+
console.log('u8a.length', u8a.length)
|
|
185
|
+
console.log('uploadLargeFile u8a', u8a)
|
|
186
|
+
|
|
187
|
+
await wo.upload('1000mb.7z', u8a,
|
|
188
|
+
function (prog, p, m) {
|
|
189
|
+
console.log('client web: upload: prog', prog, p, m)
|
|
190
|
+
})
|
|
191
|
+
.then(function(res) {
|
|
192
|
+
console.log('client web: upload: then', res)
|
|
193
|
+
})
|
|
194
|
+
.catch(function (err) {
|
|
195
|
+
console.log('client web: upload: catch', err)
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
core()
|
|
200
|
+
}
|
|
201
|
+
uploadLargeFile()
|
|
210
202
|
|
|
211
|
-
// client nodejs[port:8080]: open
|
|
212
|
-
// client nodejs[port:8080]: openOnce
|
|
213
|
-
// client nodejs[port:8080]: execute: add {
|
|
214
|
-
// ab: 46.56,
|
|
215
|
-
// v: [ 11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' } ],
|
|
216
|
-
// file: { name: 'zdata.b2', u8a: Uint8Array [ 66, 97, 115 ] }
|
|
217
|
-
// }
|
|
218
|
-
// client nodejs[port:8080]: deliver { mode: 'deliver', data: 'server deliver hi([random key])' }
|
|
219
|
-
// client nodejs[port:8080]: broadcast { text: 'server broadcast hi(1)', data: Uint8Array [ 66, 97, 115 ] }
|
|
220
|
-
// client nodejs[port:8080]: broadcast { text: 'server broadcast hi(2)', data: Uint8Array [ 66, 97, 115 ] }
|
|
221
203
|
```
|
|
222
204
|
|
|
223
205
|
### In a browser(UMD module):
|
|
@@ -225,95 +207,132 @@ wo.on('deliver', function(data) {
|
|
|
225
207
|
|
|
226
208
|
[Necessary] Add script for w-converhp-client.
|
|
227
209
|
```alias
|
|
228
|
-
<script src="https://cdn.jsdelivr.net/npm/w-converhp@
|
|
210
|
+
<script src="https://cdn.jsdelivr.net/npm/w-converhp@2.0.0/dist/w-converhp-client.umd.js"></script>
|
|
229
211
|
```
|
|
230
212
|
#### Example for w-converhp-client:
|
|
231
213
|
> **Link:** [[dev source code](https://github.com/yuda-lyu/w-converhp/blob/master/web.html)]
|
|
232
214
|
```alias
|
|
233
215
|
|
|
234
216
|
let opt = {
|
|
217
|
+
// FormData, //使用瀏覽器內建FormData, 非後端不須另外提供
|
|
235
218
|
url: 'http://localhost:8080',
|
|
219
|
+
apiName: 'api',
|
|
236
220
|
}
|
|
237
221
|
|
|
238
222
|
//new
|
|
239
223
|
let WConverhpClient=window['w-converhp-client']
|
|
240
224
|
let wo = new WConverhpClient(opt)
|
|
241
225
|
|
|
242
|
-
|
|
243
|
-
console.log('client web: open')
|
|
244
|
-
})
|
|
245
|
-
wo.on('openOnce', function() {
|
|
246
|
-
console.log('client web: openOnce')
|
|
226
|
+
async function execute(name, u8a){
|
|
247
227
|
|
|
248
228
|
//p
|
|
249
|
-
let name = 'zdata.b1'
|
|
250
229
|
let p = {
|
|
251
230
|
a: 12,
|
|
252
231
|
b: 34.56,
|
|
253
232
|
c: 'test中文',
|
|
254
233
|
d: {
|
|
255
234
|
name: name,
|
|
256
|
-
u8a
|
|
257
|
-
|
|
258
|
-
}
|
|
235
|
+
u8a,
|
|
236
|
+
},
|
|
259
237
|
}
|
|
238
|
+
console.log('p',p)
|
|
260
239
|
|
|
261
240
|
//execute
|
|
262
|
-
wo.execute('add', { p
|
|
241
|
+
await wo.execute('add', { p },
|
|
263
242
|
function (prog, p, m) {
|
|
264
243
|
console.log('client web: execute: prog', prog, p, m)
|
|
265
244
|
})
|
|
266
245
|
.then(function(r) {
|
|
267
246
|
console.log('client web: execute: add', r)
|
|
247
|
+
wsemi.downloadFileFromU8Arr(r._bin.name,r._bin.u8a)
|
|
268
248
|
})
|
|
269
249
|
.catch(function (err) {
|
|
270
250
|
console.log('client web: execute: catch', err)
|
|
271
251
|
})
|
|
272
252
|
|
|
273
|
-
|
|
274
|
-
wo.broadcast('client web broadcast hi', function (prog) {
|
|
275
|
-
console.log('client web: broadcast: prog', prog)
|
|
276
|
-
})
|
|
277
|
-
.catch(function (err) {
|
|
278
|
-
console.log('client web: broadcast: catch', err)
|
|
279
|
-
})
|
|
253
|
+
}
|
|
280
254
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
console.log('client web: deliver: prog', prog)
|
|
284
|
-
})
|
|
285
|
-
.catch(function (err) {
|
|
286
|
-
console.log('client web: deliver: catch', err)
|
|
287
|
-
})
|
|
255
|
+
function executeWithU8a() {
|
|
256
|
+
let core = async()=>{
|
|
288
257
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
258
|
+
//u8a
|
|
259
|
+
let u8a = new Uint8Array([66, 97, 115])
|
|
260
|
+
console.log('executeWithU8a u8a', u8a)
|
|
261
|
+
|
|
262
|
+
//execute
|
|
263
|
+
await execute('zdata.b1', u8a)
|
|
264
|
+
|
|
265
|
+
}
|
|
266
|
+
core()
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function executeWithFile() {
|
|
270
|
+
let core = async()=>{
|
|
271
|
+
|
|
272
|
+
let msg = await wsemi.domShowInputAndGetFiles({ sizeMbLimit: 100*1000 }) //100g
|
|
273
|
+
console.log('domShowInputAndGetFiles msg',msg)
|
|
274
|
+
|
|
275
|
+
//check
|
|
276
|
+
if(Object.keys(msg.errs).length > 0){
|
|
277
|
+
console.log('errs',msg.errs)
|
|
278
|
+
return
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
//check
|
|
282
|
+
if(msg.files.length===0){
|
|
283
|
+
return
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
//file
|
|
287
|
+
let file = msg.files[0]
|
|
288
|
+
console.log('file',file)
|
|
289
|
+
|
|
290
|
+
//blob2u8arr
|
|
291
|
+
let u8a = await wsemi.blob2u8arr(file)
|
|
292
|
+
console.log('executeWithFile u8a',u8a)
|
|
293
|
+
|
|
294
|
+
//execute
|
|
295
|
+
await execute(file.name,u8a)
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
core()
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function uploadLargeFile(){
|
|
302
|
+
let core = async()=>{
|
|
303
|
+
|
|
304
|
+
let msg = await wsemi.domShowInputAndGetFiles({ sizeMbLimit: 100*1000 }) //100g
|
|
305
|
+
console.log('domShowInputAndGetFiles msg',msg)
|
|
306
|
+
|
|
307
|
+
//check
|
|
308
|
+
if(Object.keys(msg.errs).length > 0){
|
|
309
|
+
console.log('errs',msg.errs)
|
|
310
|
+
return
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
//check
|
|
314
|
+
if(msg.files.length===0){
|
|
315
|
+
return
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
//file
|
|
319
|
+
let file = msg.files[0]
|
|
320
|
+
console.log('file',file)
|
|
321
|
+
|
|
322
|
+
//upload
|
|
323
|
+
await wo.upload(file.name, file,
|
|
324
|
+
function (prog, p, m) {
|
|
325
|
+
console.log('client web: upload: prog', prog, p, m)
|
|
326
|
+
})
|
|
327
|
+
.then(function(res) {
|
|
328
|
+
console.log('client web: upload: then', res)
|
|
329
|
+
})
|
|
330
|
+
.catch(function (err) {
|
|
331
|
+
console.log('client web: upload: catch', err)
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
}
|
|
335
|
+
core()
|
|
336
|
+
}
|
|
308
337
|
|
|
309
|
-
// client web: open
|
|
310
|
-
// client web: openOnce
|
|
311
|
-
// client web: execute: add {
|
|
312
|
-
// ab: 46.56,
|
|
313
|
-
// v: [ 11, 22.22, 'abc', { x: '21', y: 65.43, z: 'test中文' } ],
|
|
314
|
-
// file: { name: 'zdata.b2', u8a: Uint8Array [ 66, 97, 115 ] }
|
|
315
|
-
// }
|
|
316
|
-
// client web: deliver { mode: 'deliver', data: 'server deliver hi([random key])' }
|
|
317
|
-
// client web: broadcast { text: 'server broadcast hi(1)', data: Uint8Array [ 66, 97, 115 ] }
|
|
318
|
-
// client web: broadcast { text: 'server broadcast hi(2)', data: Uint8Array [ 66, 97, 115 ] }
|
|
319
338
|
```
|