rosud-call 2.0.1 → 2.0.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/ws-client.js +26 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rosud-call",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Bot messaging SDK — npm install rosud-call",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
package/src/ws-client.js CHANGED
@@ -47,13 +47,19 @@ class WsClient extends EventEmitter {
47
47
  this._stopped = false
48
48
  this._retryDelay = MIN_RETRY_SEC
49
49
  this._pingTimer = null
50
+ this._connectResolve = null
51
+ this._connectReject = null
50
52
  }
51
53
 
52
54
  /** WS 연결 + subscribe */
53
55
  async connect(roomId) {
54
56
  this._room = roomId
55
57
  this._stopped = false
56
- await this._wsConnect()
58
+ return new Promise((resolve, reject) => {
59
+ this._connectResolve = resolve
60
+ this._connectReject = reject
61
+ this._wsConnect().catch(reject)
62
+ })
57
63
  }
58
64
 
59
65
  /** WS 종료 */
@@ -112,10 +118,29 @@ class WsClient extends EventEmitter {
112
118
 
113
119
  if (msg.type === 'subscribed') {
114
120
  this._retryDelay = MIN_RETRY_SEC
121
+ if (this._connectResolve) {
122
+ this._connectResolve()
123
+ this._connectResolve = null
124
+ this._connectReject = null
125
+ }
115
126
  this.emit('connected')
116
127
  return
117
128
  }
118
129
 
130
+ // [보안] subscribe error 처리 — connect() Promise reject
131
+ if (msg.type === 'error') {
132
+ const code = msg.code || 'UNKNOWN'
133
+ const err = new Error(`WS error [${code}]: ${msg.message || ''}`)
134
+ err.code = code
135
+ if (this._connectReject && (code === 'NOT_IN_ROOM' || code === 'RATE_LIMIT' || code === 'VALIDATION_ERROR')) {
136
+ this._connectReject(err)
137
+ this._connectResolve = null
138
+ this._connectReject = null
139
+ }
140
+ this.emit('error', err)
141
+ return
142
+ }
143
+
119
144
  if (msg.type === 'message_new') {
120
145
  const m = msg.message
121
146
  if (this.filterSelf && m.sender_id === this.botId) return