vrpc 3.14.0 → 3.15.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.
@@ -93,6 +93,39 @@ class SubscribeRetrier {
93
93
  this._attempt = 0
94
94
  }
95
95
 
96
+ /**
97
+ * What a SUBACK said, however mqtt.js reports it. mqtt.js 5 turns a
98
+ * refused topic (reason code 0x80 and up) into an error carrying the
99
+ * SUBACK packet, and hands back the subscriptions as requested; older
100
+ * versions answered `qos: 128` in the granted list.
101
+ *
102
+ * @param {Error|null} err The subscribe callback's error
103
+ * @param {Array.<Object>} granted The subscribe callback's `{ topic, qos }`
104
+ * @returns {Object} `{ refused, granted, error }`: the refused topics, the
105
+ * granted `{ topic, qos }`, and an error that is no refusal (or null)
106
+ */
107
+ static outcome (err, granted) {
108
+ const subs = Array.isArray(granted) ? granted : []
109
+ const codes = err && err.packet && Array.isArray(err.packet.granted)
110
+ ? err.packet.granted
111
+ : null
112
+ if (codes) {
113
+ const refused = []
114
+ const ok = []
115
+ subs.forEach(({ topic }, i) => {
116
+ if ((codes[i] & 0x80) !== 0) refused.push(topic)
117
+ else ok.push({ topic, qos: codes[i] })
118
+ })
119
+ return { refused, granted: ok, error: null }
120
+ }
121
+ if (err) return { refused: [], granted: [], error: err }
122
+ return {
123
+ refused: subs.filter(x => x.qos === 128).map(x => x.topic),
124
+ granted: subs.filter(x => x.qos !== 128),
125
+ error: null
126
+ }
127
+ }
128
+
96
129
  _fire () {
97
130
  this._timer = null
98
131
  this._attempt += 1