@subiz/wsclient 4.0.32 → 4.0.34

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/wsclient",
3
- "version": "4.0.32",
3
+ "version": "4.0.34",
4
4
  "main": "realtime.js",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -16,7 +16,7 @@
16
16
  "description": "",
17
17
  "devDependencies": {
18
18
  "tape": "^5.9.0",
19
- "vite": "^6.3.3",
19
+ "vite": "^6.3.5",
20
20
  "vite-plugin-commonjs": "^0.10.4"
21
21
  },
22
22
  "dependencies": {
package/realtime.js CHANGED
@@ -30,7 +30,7 @@ function Conn(apiUrl, credential, onDead, onEvents, callAPI, accid) {
30
30
  // The first loop begins after the first subscription call completes successfully
31
31
  var polling = function (backoff) {
32
32
  if (is_dead) return
33
- callAPI('get', apiUrl + 'poll?token=' + lastToken + '&account-id=' + accid, undefined, function (body, code) {
33
+ callAPI('get', apiUrl + 'poll?token=' + lastToken + '&v=5&account-id=' + accid, undefined, function (body, code) {
34
34
  if (is_dead) return
35
35
  if (retryable(code)) {
36
36
  is_polling_stuck = true
@@ -99,7 +99,8 @@ function Conn(apiUrl, credential, onDead, onEvents, callAPI, accid) {
99
99
  else if (credential.user_mask) query += '&user-mask=' + encodeURIComponent(credential.user_mask)
100
100
  else if (access_token) query += '&access-token=' + access_token
101
101
 
102
- var fullurl = apiUrl + 'subs' + query + '&account-id=' + encodeURIComponent(accid || credential.account_id)
102
+ var fullurl =
103
+ apiUrl + 'subs' + query + '&v=5&account-id=' + encodeURIComponent(accid || credential.account_id)
103
104
  callAPI('post', fullurl, JSON.stringify({events: topics}), function (body, code) {
104
105
  if (done) return
105
106
  if (is_dead) {
@@ -234,14 +235,14 @@ function Realtime(apiUrls, credential, callAPI, accid, skipautoreconnect) {
234
235
  // reconnect make sure there is alway a Conn running in the background
235
236
  // if the Conn is dead, it recreate a new one
236
237
  var conn
237
- let reconnect = function () {
238
+ var reconnect = function () {
238
239
  var randomUrl = apiUrls[Math.floor(Math.random() * apiUrls.length)]
239
240
  if (conn) conn.kill() // kill old connection
240
- let myconn = new Conn(
241
+ var myconn = new Conn(
241
242
  randomUrl,
242
243
  credential,
243
244
  function (code, body, status) {
244
- if (myconn != conn) return // outdated
245
+ if (conn === undefined || myconn != conn) return // outdated
245
246
  conn = undefined // prevent dupplicate dead fire
246
247
  pubsub.emit('interrupted', code, body, status)
247
248
  if (!skipautoreconnect) setTimeout(reconnect, 2000) // reconnect and resubscribe after 2 sec
package/realtime.test.js CHANGED
@@ -114,9 +114,9 @@ test.only('realtime', async (t) => {
114
114
  {
115
115
  name: 'starting status',
116
116
  steps: [
117
- {type: 'status', status: 'active'},
117
+ {type: 'status', status: 'connecting'},
118
118
  {type: 'subscribe', topics: ['message_sent']},
119
- {type: 'status', status: 'active'},
119
+ {type: 'status', status: 'connecting'},
120
120
  {type: 'call', call_id: '1', path: '/subs', method: 'post', body: {events: ['message_sent']}},
121
121
  {type: 'wait', timeout: 5000},
122
122
  {type: 'status', status: 'connecting'},
@@ -130,7 +130,7 @@ test.only('realtime', async (t) => {
130
130
  name: 'long subscribe',
131
131
  steps: [
132
132
  {type: 'subscribe', topics: ['message_sent']},
133
- {type: 'status', status: 'active'},
133
+ {type: 'status', status: 'connecting'},
134
134
  {type: 'call', call_id: '1', path: '/subs', method: 'post', body: {events: ['message_sent']}},
135
135
  {type: 'wait', timeout: 5000},
136
136
  {type: 'status', status: 'connecting'},
@@ -145,7 +145,7 @@ test.only('realtime', async (t) => {
145
145
  name: 'double subscribe -> do nothing',
146
146
  steps: [
147
147
  {type: 'subscribe', topics: ['message_sent']},
148
- {type: 'status', status: 'active'},
148
+ {type: 'status', status: 'connecting'},
149
149
  {type: 'call', call_id: '1', path: '/subs', method: 'post', body: {events: ['message_sent']}},
150
150
  {type: 'response', call_id: '1', body: {initial_token: 'token1'}, code: 200},
151
151
  {type: 'call', call_id: '2', path: '/poll', query: {token: 'token1'}, method: 'get'},
@@ -157,7 +157,7 @@ test.only('realtime', async (t) => {
157
157
  name: 'polling unstable',
158
158
  steps: [
159
159
  {type: 'subscribe', topics: ['message_sent']},
160
- {type: 'status', status: 'active'},
160
+ {type: 'status', status: 'connecting'},
161
161
  {type: 'call', call_id: '1', path: '/subs', method: 'post', body: {events: ['message_sent']}},
162
162
  {type: 'wait', timeout: 1000},
163
163
  {type: 'response', call_id: '1', body: {initial_token: 'token1'}, code: 200},
@@ -177,7 +177,7 @@ test.only('realtime', async (t) => {
177
177
  name: 'polling dead',
178
178
  steps: [
179
179
  {type: 'subscribe', topics: ['message_sent']},
180
- {type: 'status', status: 'active'},
180
+ {type: 'status', status: 'connecting'},
181
181
  {type: 'call', call_id: '1', path: '/subs', method: 'post', body: {events: ['message_sent']}},
182
182
  {type: 'wait', timeout: 1000},
183
183
  {type: 'response', call_id: '1', body: {initial_token: 'token1'}, code: 200},
@@ -329,7 +329,7 @@ test.only('realtime', async (t) => {
329
329
 
330
330
  let ps = []
331
331
  for (const script of scripts) {
332
- if (script.name != 'resub') continue
332
+ // if (script.name != 'resub') continue
333
333
  ps.push(testScript(t, script))
334
334
  }
335
335
  await Promise.all(ps)