@subiz/wsclient 4.0.36 → 4.0.37

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.
@@ -1,12 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(git -C /Users/thanh/Developer/wsclient log --oneline -5 -- '*webphone*')",
5
- "Bash(node --check /Users/thanh/Developer/wsclient/webphone.js)",
6
- "Bash(npx prettier *)",
7
- "Bash(node --check realtime.js)",
8
- "Bash(git *)",
9
- "Bash(node *)"
10
- ]
11
- }
12
- }
package/.prettierrc.js DELETED
@@ -1,19 +0,0 @@
1
- module.exports = {
2
- arrowParens: 'always',
3
- bracketSpacing: false,
4
- embeddedLanguageFormatting: 'auto',
5
- htmlWhitespaceSensitivity: 'css',
6
- insertPragma: false,
7
- jsxBracketSameLine: true,
8
- jsxSingleQuote: true,
9
- printWidth: 120,
10
- proseWrap: 'preserve',
11
- quoteProps: 'as-needed',
12
- requirePragma: false,
13
- semi: false,
14
- singleQuote: true,
15
- tabWidth: 2,
16
- trailingComma: 'all',
17
- useTabs: true,
18
- vueIndentScriptAndStyle: false,
19
- }
package/realtime.test.js DELETED
@@ -1,338 +0,0 @@
1
- var test = require('tape')
2
- var Realtime = require('./realtime.js')
3
-
4
- async function testScript(t, script) {
5
- let events = []
6
- let calls = []
7
- var realtime = new Realtime(
8
- 'https://api5.subiz.com.vn/',
9
- {user_mask: 'mask123'},
10
- (method, url, body, cb) => {
11
- calls.push({method, url, body, cb})
12
- },
13
- 'acctest',
14
- !script.auto_reconnect,
15
- )
16
- realtime.onEvent((ev) => events.push(ev))
17
-
18
- for (let stepi in script.steps) {
19
- let step = script.steps[stepi]
20
- if (step.type == 'status') {
21
- t.equal(realtime.getStatus(), step.status, script.name + '[' + stepi + ']')
22
- continue
23
- }
24
-
25
- if (step.type == 'subscribe') {
26
- realtime.subscribe(step.topics)
27
- continue
28
- }
29
-
30
- if (step.type == 'reconnect') {
31
- realtime.reconnect()
32
- continue
33
- }
34
-
35
- if (step.type == 'wait') {
36
- await sleep(step.timeout)
37
- continue
38
- }
39
-
40
- if (step.type == 'call') {
41
- t.true(step.call_id != undefined) // must define call id in the script
42
- let start = Date.now()
43
- let timeout = step.timeout || 10_000
44
- let istimeout
45
- for (;;) {
46
- if (Date.now() - start > timeout) {
47
- istimeout = true
48
- break
49
- }
50
- // wait util api is called
51
- await sleep(100)
52
- let call
53
- for (let c = 0; c < calls.length; c++) {
54
- if (!calls[c].call_id) {
55
- call = calls[c]
56
- break
57
- }
58
- }
59
- if (!call) continue
60
- call.call_id = step.call_id
61
- const myUrl = new URL(call.url)
62
-
63
- if (step.path) t.equal(myUrl.pathname, step.path)
64
-
65
- if (step.method) t.equal(step.method, call.method)
66
-
67
- if (step.query) {
68
- for (var key of Object.keys(step.query)) {
69
- t.equal(step.query[key], myUrl.searchParams.get(key), script.name)
70
- }
71
- }
72
-
73
- if (step.body) {
74
- let keys = Object.keys(step.body)
75
- let callbody
76
- if (call.body) callbody = JSON.parse(call.body)
77
- for (var key of keys) {
78
- t.equal(JSON.stringify(step.body[key]), JSON.stringify(callbody[key]))
79
- }
80
- }
81
- break
82
- }
83
-
84
- t.true(!istimeout, script.name + ' ' + stepi + ' ' + JSON.stringify(step))
85
- continue
86
- }
87
-
88
- if (step.type == 'response') {
89
- let call
90
- for (var c = 0; c < calls.length; c++) {
91
- if (calls[c].call_id == step.call_id) {
92
- call = calls[c]
93
- break
94
- }
95
- }
96
-
97
- t.true(call != undefined)
98
- call.cb(JSON.stringify(step.body), step.code)
99
- continue
100
- }
101
- t.true(false, script.name + '[' + stepi + ']=' + step.type)
102
- }
103
- // check events
104
- let scriptevents = script.events || []
105
- t.equal(events.length, scriptevents.length)
106
- for (let i in events) {
107
- t.equal(JSON.stringify(events[i]), JSON.stringify(scriptevents[i]))
108
- }
109
- realtime.stop()
110
- }
111
-
112
- test.only('realtime', async (t) => {
113
- let scripts = [
114
- {
115
- name: 'starting status',
116
- steps: [
117
- {type: 'status', status: 'connecting'},
118
- {type: 'subscribe', topics: ['message_sent']},
119
- {type: 'status', status: 'connecting'},
120
- {type: 'call', call_id: '1', path: '/subs', method: 'post', body: {events: ['message_sent']}},
121
- {type: 'wait', timeout: 5000},
122
- {type: 'status', status: 'connecting'},
123
- {type: 'wait', timeout: 60000},
124
- {type: 'status', status: 'dead'},
125
- {type: 'response', call_id: '1', body: {initial_token: 'aaaaaa'}, code: 200},
126
- {type: 'status', status: 'dead'}, // dead must be dead
127
- ],
128
- },
129
- {
130
- name: 'long subscribe',
131
- steps: [
132
- {type: 'subscribe', topics: ['message_sent']},
133
- {type: 'status', status: 'connecting'},
134
- {type: 'call', call_id: '1', path: '/subs', method: 'post', body: {events: ['message_sent']}},
135
- {type: 'wait', timeout: 5000},
136
- {type: 'status', status: 'connecting'},
137
- {type: 'wait', timeout: 3000},
138
- {type: 'status', status: 'connecting'},
139
- {type: 'response', call_id: '1', body: {initial_token: 'aaaaaa'}, code: 200},
140
- {type: 'status', status: 'active'},
141
- ],
142
- events: [],
143
- },
144
- {
145
- name: 'double subscribe -> do nothing',
146
- steps: [
147
- {type: 'subscribe', topics: ['message_sent']},
148
- {type: 'status', status: 'connecting'},
149
- {type: 'call', call_id: '1', path: '/subs', method: 'post', body: {events: ['message_sent']}},
150
- {type: 'response', call_id: '1', body: {initial_token: 'token1'}, code: 200},
151
- {type: 'call', call_id: '2', path: '/poll', query: {token: 'token1'}, method: 'get'},
152
- {type: 'subscribe', topics: ['message_sent', 'message_pong']},
153
- {type: 'call', call_id: '3', path: '/subs', method: 'post', body: {events: ['message_pong']}},
154
- ],
155
- },
156
- {
157
- name: 'polling unstable',
158
- steps: [
159
- {type: 'subscribe', topics: ['message_sent']},
160
- {type: 'status', status: 'connecting'},
161
- {type: 'call', call_id: '1', path: '/subs', method: 'post', body: {events: ['message_sent']}},
162
- {type: 'wait', timeout: 1000},
163
- {type: 'response', call_id: '1', body: {initial_token: 'token1'}, code: 200},
164
- {type: 'status', status: 'active'},
165
- {type: 'call', call_id: '2', path: '/poll', query: {token: 'token1'}, method: 'get'},
166
- {type: 'wait', timeout: 30000},
167
- {type: 'response', call_id: '2', body: 'network disconnected', code: 0},
168
- {type: 'status', status: 'connecting'},
169
- {type: 'call', call_id: '3', path: '/poll', query: {token: 'token1'}, method: 'get'},
170
- {type: 'wait', timeout: 30000},
171
- {type: 'response', call_id: '3', body: '500 keep internal', code: 500},
172
- // more than 60 sec without any data => dead
173
- {type: 'status', status: 'connecting'},
174
- ],
175
- },
176
- {
177
- name: 'polling dead',
178
- steps: [
179
- {type: 'subscribe', topics: ['message_sent']},
180
- {type: 'status', status: 'connecting'},
181
- {type: 'call', call_id: '1', path: '/subs', method: 'post', body: {events: ['message_sent']}},
182
- {type: 'wait', timeout: 1000},
183
- {type: 'response', call_id: '1', body: {initial_token: 'token1'}, code: 200},
184
- {type: 'status', status: 'active'},
185
- {type: 'call', call_id: '2', path: '/poll', query: {token: 'token1'}, method: 'get'},
186
- {type: 'response', call_id: '2', body: '400 dead', code: 400},
187
- {type: 'status', status: 'dead'},
188
- ],
189
- },
190
- {
191
- name: 'basic',
192
- steps: [
193
- {type: 'subscribe', topics: ['message_sent']},
194
- {
195
- type: 'call',
196
- call_id: '1',
197
- path: '/subs',
198
- query: {'user-mask': 'mask123'},
199
- method: 'post',
200
- body: {events: ['message_sent']},
201
- },
202
- {type: 'response', call_id: '1', body: {initial_token: 'token1'}, code: 200},
203
- {type: 'wait', timeout: 1000},
204
- {type: 'call', call_id: '2', path: '/poll', query: {token: 'token1'}, method: 'get'},
205
- {type: 'status', status: 'active'},
206
- {type: 'wait', timeout: 3000},
207
- {type: 'response', call_id: '2', body: {events: [{text: 'xin chao'}], sequential_token: 'token2'}, code: 200},
208
- {type: 'status', status: 'active'},
209
- {type: 'call', call_id: '3', path: '/poll', query: {token: 'token2'}, method: 'get'},
210
- ],
211
- events: [{text: 'xin chao'}],
212
- },
213
- {
214
- name: 'realtime subs when server down and then backup',
215
- steps: [
216
- {type: 'subscribe', topics: ['message_sent']},
217
- {
218
- type: 'call',
219
- call_id: '1',
220
- path: '/subs',
221
- method: 'post',
222
- body: {events: ['message_sent']},
223
- },
224
- {type: 'wait', timeout: 1000},
225
- {type: 'response', call_id: '1', body: '502 too busy', code: 502},
226
- {
227
- type: 'call',
228
- call_id: '1.1',
229
- path: '/subs',
230
- method: 'post',
231
- body: {events: ['message_sent']},
232
- },
233
- {type: 'status', status: 'connecting'},
234
- {type: 'wait', timeout: 1000},
235
- {type: 'response', call_id: '1.1', body: '502 still busy', code: 502},
236
- {type: 'status', status: 'connecting'},
237
- {type: 'wait', timeout: 1000},
238
- {
239
- type: 'call',
240
- call_id: '1.2',
241
- path: '/subs',
242
- method: 'post',
243
- body: {events: ['message_sent']},
244
- },
245
- {type: 'status', status: 'connecting'},
246
- {type: 'response', call_id: '1.2', body: {initial_token: 'token1'}, code: 200},
247
- {type: 'call', call_id: '2', path: '/poll', query: {token: 'token1'}, method: 'get'},
248
- {type: 'status', status: 'active'},
249
- {type: 'wait', timeout: 3000},
250
- {type: 'response', call_id: '2', body: {events: [{text: 'xin chao'}], sequential_token: 'token2'}, code: 200},
251
- {type: 'status', status: 'active'},
252
- {type: 'call', call_id: '3', path: '/poll', query: {token: 'token2'}, method: 'get'},
253
- ],
254
- events: [{text: 'xin chao'}],
255
- },
256
- {
257
- name: 'realtime must stop if there is something wrong with our credential or our code',
258
- steps: [
259
- {type: 'subscribe', topics: ['message_sent']},
260
- {type: 'call', call_id: 1, path: '/subs'},
261
- {type: 'response', call_id: 1, body: '400 invalid mask', code: 400},
262
- {type: 'status', status: 'dead'},
263
- ],
264
- },
265
- {
266
- name: 'reconect',
267
- steps: [
268
- {type: 'subscribe', topics: ['message_sent']},
269
- {type: 'call', call_id: 1, path: '/subs'},
270
- {type: 'response', call_id: 1, body: '400 invalid mask', code: 400},
271
- {type: 'status', status: 'dead'},
272
- {type: 'reconnect'},
273
- {type: 'wait', timeout: 1000},
274
- {type: 'call', call_id: 2, path: '/subs'},
275
- {type: 'wait', timeout: 1000},
276
- {type: 'response', call_id: 2, body: {initial_token: 'token1'}, code: 200},
277
- {type: 'status', status: 'active'},
278
- ],
279
- },
280
- {
281
- name: 'reconect while poll',
282
- steps: [
283
- {type: 'subscribe', topics: ['message_sent']},
284
- {type: 'call', call_id: 1, path: '/subs'},
285
- {type: 'response', call_id: '1', body: {initial_token: 'token1'}, code: 200},
286
- {type: 'call', call_id: '2', path: '/poll', query: {token: 'token1'}, method: 'get'},
287
- {type: 'status', status: 'active'},
288
- {type: 'wait', timeout: 1000},
289
- {type: 'response', call_id: '2', body: {events: [{text: 'xin chao'}], sequential_token: 'token2'}, code: 200},
290
- {type: 'call', call_id: '3', path: '/poll', query: {token: 'token2'}, method: 'get'},
291
- {type: 'response', call_id: '3', body: '400 dead', code: 400},
292
- {type: 'status', status: 'dead'},
293
- {type: 'reconnect'},
294
- {type: 'wait', timeout: 1000},
295
- {type: 'call', call_id: 4, path: '/subs'},
296
- {type: 'wait', timeout: 1000},
297
- {type: 'response', call_id: 4, body: {initial_token: 'token1'}, code: 200},
298
- {type: 'status', status: 'active'},
299
- ],
300
- events: [{text: 'xin chao'}],
301
- },
302
- {
303
- name: 'resub',
304
- auto_reconnect: true,
305
- steps: [
306
- {type: 'subscribe', topics: ['message_sent']},
307
- {type: 'call', call_id: 1, path: '/subs'},
308
- {type: 'response', call_id: '1', body: 'wait a sec', code: 500},
309
- {type: 'status', status: 'connecting'},
310
- {type: 'wait', timeout: 1000},
311
- {type: 'call', call_id: 2, path: '/subs'},
312
- {type: 'wait', timeout: 61000},
313
- {type: 'status', status: 'connecting'},
314
- {type: 'call', call_id: 3, path: '/subs'},
315
- {type: 'wait', timeout: 1000},
316
- {type: 'response', call_id: '3', body: 'wait a sec', code: 500},
317
- {type: 'status', status: 'connecting'},
318
- {type: 'wait', timeout: 1000},
319
- {type: 'call', call_id: 4, path: '/subs'},
320
- {type: 'wait', timeout: 1000},
321
- {type: 'response', call_id: '4', body: {initial_token: 'token1'}, code: 200},
322
- {type: 'call', call_id: '5', path: '/poll', query: {token: 'token1'}, method: 'get'},
323
- {type: 'status', status: 'active'},
324
- {type: 'response', call_id: '5', body: {events: [{text: 'xin chao'}], sequential_token: 'token2'}, code: 200},
325
- ],
326
- events: [{text: 'xin chao'}],
327
- },
328
- ]
329
-
330
- let ps = []
331
- for (const script of scripts) {
332
- // if (script.name != 'resub') continue
333
- ps.push(testScript(t, script))
334
- }
335
- await Promise.all(ps)
336
- })
337
-
338
- let sleep = (ms) => new Promise((rs) => setTimeout(rs, ms))
package/vite.config.js DELETED
@@ -1,16 +0,0 @@
1
- import {defineConfig} from 'vite'
2
- import commonjs from 'vite-plugin-commonjs'
3
-
4
- export default defineConfig({
5
- plugins: [
6
- commonjs({
7
- filter(id) {
8
- if (id.includes('node_modules/redux-storage/build-es')) {
9
- return true
10
- }
11
- },
12
- }),
13
- // Other plugins
14
- ],
15
- // Other configurations
16
- })