qiscus-sdk-core 2.12.4 → 2.12.6-logger
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/dist/qiscus-sdk-core.min.js +6 -8
- package/dist/qiscus-sdk-core.min.js.map +1 -1
- package/lib/index.js +1137 -1521
- package/lib/lib/Comment.js +20 -31
- package/lib/lib/Room.js +6 -19
- package/lib/lib/adapters/auth.js +2 -13
- package/lib/lib/adapters/custom-event.js +2 -13
- package/lib/lib/adapters/expired-token.js +84 -133
- package/lib/lib/adapters/hook.js +2 -8
- package/lib/lib/adapters/http.js +57 -58
- package/lib/lib/adapters/mqtt.js +386 -336
- package/lib/lib/adapters/room.js +2 -10
- package/lib/lib/adapters/sync.js +226 -328
- package/lib/lib/adapters/user.js +2 -20
- package/lib/lib/match.js +19 -61
- package/lib/lib/url-builder.js +0 -5
- package/lib/lib/util.js +5 -14
- package/lib/lib/utils.js +10 -24
- package/lib/logger.js +125 -0
- package/package.json +5 -3
package/lib/lib/adapters/sync.js
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports["default"] = SyncAdapter;
|
|
9
|
-
|
|
10
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
-
|
|
12
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
13
|
-
|
|
14
|
-
var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncIterator"));
|
|
15
|
-
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
16
10
|
var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/awaitAsyncGenerator"));
|
|
17
|
-
|
|
18
11
|
var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
|
|
19
|
-
|
|
20
12
|
var _mitt = _interopRequireDefault(require("mitt"));
|
|
21
|
-
|
|
22
13
|
var _urlBuilder = _interopRequireDefault(require("../url-builder"));
|
|
23
|
-
|
|
14
|
+
function _asyncIterator(r) { var n, t, o, e = 2; for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) { if (t && null != (n = r[t])) return n.call(r); if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r)); t = "@@asyncIterator", o = "@@iterator"; } throw new TypeError("Object is not async iterable"); }
|
|
15
|
+
function AsyncFromSyncIterator(r) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var n = r.done; return Promise.resolve(r.value).then(function (r) { return { value: r, done: n }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(r) { this.s = r, this.n = r.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, "return": function _return(r) { var n = this.s["return"]; return void 0 === n ? Promise.resolve({ value: r, done: !0 }) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments)); }, "throw": function _throw(r) { var n = this.s["return"]; return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(r); }
|
|
24
16
|
var noop = function noop() {};
|
|
25
|
-
|
|
26
17
|
var sleep = function sleep(time) {
|
|
27
18
|
return new Promise(function (res) {
|
|
28
19
|
return setTimeout(res, time);
|
|
29
20
|
});
|
|
30
21
|
};
|
|
31
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @param {Function} getHttp - Function to get the HTTP adapter
|
|
25
|
+
* @param {Function} getInterval - Function to get the sync interval
|
|
26
|
+
* @param {Function} getSync - Function to check if sync is enabled
|
|
27
|
+
* @param {Function} getId - Function to get the last message ID
|
|
28
|
+
* @param {import('pino').Logger} logger - Logger function
|
|
29
|
+
* @returns {Object} Synchronization factory object
|
|
30
|
+
*/
|
|
32
31
|
function synchronizeFactory(getHttp, getInterval, getSync, getId, logger) {
|
|
33
32
|
var emitter = (0, _mitt["default"])();
|
|
34
|
-
|
|
35
33
|
var synchronize = function synchronize(messageId) {
|
|
36
34
|
var url = (0, _urlBuilder["default"])('api/v2/sdk/sync').param('last_received_comment_id', messageId).build();
|
|
37
35
|
return getHttp().get(url).then(function (resp) {
|
|
@@ -48,177 +46,142 @@ function synchronizeFactory(getHttp, getInterval, getSync, getId, logger) {
|
|
|
48
46
|
});
|
|
49
47
|
})["catch"](noop);
|
|
50
48
|
};
|
|
51
|
-
|
|
52
49
|
function generator() {
|
|
53
50
|
return _generator.apply(this, arguments);
|
|
54
51
|
}
|
|
55
|
-
|
|
56
52
|
function _generator() {
|
|
57
|
-
_generator = (0, _wrapAsyncGenerator2["default"])(
|
|
53
|
+
_generator = (0, _wrapAsyncGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
58
54
|
var accumulatedInterval, interval, shouldSync;
|
|
59
|
-
return _regenerator["default"].wrap(function
|
|
60
|
-
while (1) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
case 3:
|
|
71
|
-
if (!true) {
|
|
72
|
-
_context.next = 13;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
accumulatedInterval += interval;
|
|
77
|
-
|
|
78
|
-
if (!(accumulatedInterval >= getInterval() && shouldSync())) {
|
|
79
|
-
_context.next = 9;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
accumulatedInterval = 0;
|
|
84
|
-
_context.next = 9;
|
|
85
|
-
return synchronize(getId());
|
|
86
|
-
|
|
87
|
-
case 9:
|
|
88
|
-
_context.next = 11;
|
|
89
|
-
return (0, _awaitAsyncGenerator2["default"])(sleep(interval));
|
|
90
|
-
|
|
91
|
-
case 11:
|
|
92
|
-
_context.next = 3;
|
|
55
|
+
return _regenerator["default"].wrap(function (_context) {
|
|
56
|
+
while (1) switch (_context.prev = _context.next) {
|
|
57
|
+
case 0:
|
|
58
|
+
accumulatedInterval = 0;
|
|
59
|
+
interval = 100;
|
|
60
|
+
shouldSync = function shouldSync() {
|
|
61
|
+
return getHttp() != null && getSync();
|
|
62
|
+
};
|
|
63
|
+
case 1:
|
|
64
|
+
if (!true) {
|
|
65
|
+
_context.next = 4;
|
|
93
66
|
break;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
67
|
+
}
|
|
68
|
+
accumulatedInterval += interval;
|
|
69
|
+
if (!(accumulatedInterval >= getInterval() && shouldSync())) {
|
|
70
|
+
_context.next = 2;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
accumulatedInterval = 0;
|
|
74
|
+
_context.next = 2;
|
|
75
|
+
return synchronize(getId());
|
|
76
|
+
case 2:
|
|
77
|
+
_context.next = 3;
|
|
78
|
+
return (0, _awaitAsyncGenerator2["default"])(sleep(interval));
|
|
79
|
+
case 3:
|
|
80
|
+
_context.next = 1;
|
|
81
|
+
break;
|
|
82
|
+
case 4:
|
|
83
|
+
case "end":
|
|
84
|
+
return _context.stop();
|
|
99
85
|
}
|
|
100
86
|
}, _callee);
|
|
101
87
|
}));
|
|
102
88
|
return _generator.apply(this, arguments);
|
|
103
89
|
}
|
|
104
|
-
|
|
105
90
|
return {
|
|
106
91
|
get synchronize() {
|
|
107
92
|
return synchronize;
|
|
108
93
|
},
|
|
109
|
-
|
|
110
94
|
get on() {
|
|
111
95
|
return emitter.on;
|
|
112
96
|
},
|
|
113
|
-
|
|
114
97
|
get off() {
|
|
115
98
|
return emitter.off;
|
|
116
99
|
},
|
|
117
|
-
|
|
118
100
|
run: function run() {
|
|
119
|
-
return (0, _asyncToGenerator2["default"])(
|
|
120
|
-
var
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
_context2.next = 17;
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
result = _value;
|
|
150
|
-
|
|
151
|
-
try {
|
|
152
|
-
messageId = result.lastMessageId;
|
|
153
|
-
messages = result.messages;
|
|
154
|
-
|
|
155
|
-
if (messageId > getId()) {
|
|
156
|
-
messages.forEach(function (m) {
|
|
157
|
-
return emitter.emit('message.new', m);
|
|
158
|
-
});
|
|
159
|
-
emitter.emit('last-message-id.new', messageId);
|
|
160
|
-
}
|
|
161
|
-
} catch (e) {
|
|
162
|
-
logger('error when sync', e.message);
|
|
101
|
+
return (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
102
|
+
var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, result, messageId, messages, _t;
|
|
103
|
+
return _regenerator["default"].wrap(function (_context2) {
|
|
104
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
105
|
+
case 0:
|
|
106
|
+
_iteratorAbruptCompletion = false;
|
|
107
|
+
_didIteratorError = false;
|
|
108
|
+
_context2.prev = 1;
|
|
109
|
+
_iterator = _asyncIterator(generator());
|
|
110
|
+
case 2:
|
|
111
|
+
_context2.next = 3;
|
|
112
|
+
return _iterator.next();
|
|
113
|
+
case 3:
|
|
114
|
+
if (!(_iteratorAbruptCompletion = !(_step = _context2.sent).done)) {
|
|
115
|
+
_context2.next = 5;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
result = _step.value;
|
|
119
|
+
try {
|
|
120
|
+
messageId = result.lastMessageId;
|
|
121
|
+
messages = result.messages;
|
|
122
|
+
if (messageId > getId()) {
|
|
123
|
+
messages.forEach(function (m) {
|
|
124
|
+
return emitter.emit('message.new', m);
|
|
125
|
+
});
|
|
126
|
+
emitter.emit('last-message-id.new', messageId);
|
|
163
127
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
128
|
+
} catch (e) {
|
|
129
|
+
logger.error('error when sync', {
|
|
130
|
+
message: e.message
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
case 4:
|
|
134
|
+
_iteratorAbruptCompletion = false;
|
|
135
|
+
_context2.next = 2;
|
|
136
|
+
break;
|
|
137
|
+
case 5:
|
|
138
|
+
_context2.next = 7;
|
|
139
|
+
break;
|
|
140
|
+
case 6:
|
|
141
|
+
_context2.prev = 6;
|
|
142
|
+
_t = _context2["catch"](1);
|
|
143
|
+
_didIteratorError = true;
|
|
144
|
+
_iteratorError = _t;
|
|
145
|
+
case 7:
|
|
146
|
+
_context2.prev = 7;
|
|
147
|
+
_context2.prev = 8;
|
|
148
|
+
if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
|
|
149
|
+
_context2.next = 9;
|
|
168
150
|
break;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
151
|
+
}
|
|
152
|
+
_context2.next = 9;
|
|
153
|
+
return _iterator["return"]();
|
|
154
|
+
case 9:
|
|
155
|
+
_context2.prev = 9;
|
|
156
|
+
if (!_didIteratorError) {
|
|
157
|
+
_context2.next = 10;
|
|
172
158
|
break;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
_context2.prev = 24;
|
|
183
|
-
|
|
184
|
-
if (!(!_iteratorNormalCompletion && _iterator["return"] != null)) {
|
|
185
|
-
_context2.next = 28;
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
_context2.next = 28;
|
|
190
|
-
return _iterator["return"]();
|
|
191
|
-
|
|
192
|
-
case 28:
|
|
193
|
-
_context2.prev = 28;
|
|
194
|
-
|
|
195
|
-
if (!_didIteratorError) {
|
|
196
|
-
_context2.next = 31;
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
throw _iteratorError;
|
|
201
|
-
|
|
202
|
-
case 31:
|
|
203
|
-
return _context2.finish(28);
|
|
204
|
-
|
|
205
|
-
case 32:
|
|
206
|
-
return _context2.finish(23);
|
|
207
|
-
|
|
208
|
-
case 33:
|
|
209
|
-
case "end":
|
|
210
|
-
return _context2.stop();
|
|
211
|
-
}
|
|
159
|
+
}
|
|
160
|
+
throw _iteratorError;
|
|
161
|
+
case 10:
|
|
162
|
+
return _context2.finish(9);
|
|
163
|
+
case 11:
|
|
164
|
+
return _context2.finish(7);
|
|
165
|
+
case 12:
|
|
166
|
+
case "end":
|
|
167
|
+
return _context2.stop();
|
|
212
168
|
}
|
|
213
|
-
}, _callee2, null, [[
|
|
169
|
+
}, _callee2, null, [[1, 6, 7, 12], [8,, 9, 11]]);
|
|
214
170
|
}))();
|
|
215
171
|
}
|
|
216
172
|
};
|
|
217
173
|
}
|
|
218
174
|
|
|
175
|
+
/**
|
|
176
|
+
* @param {Function} getHttp - Function to get the HTTP adapter
|
|
177
|
+
* @param {Function} getInterval - Function to get the sync interval
|
|
178
|
+
* @param {Function} getSync - Function to check if sync is enabled
|
|
179
|
+
* @param {Function} getId - Function to get the last event ID
|
|
180
|
+
* @param {import('pino').Logger} logger - Logger function
|
|
181
|
+
* @returns {Object} Synchronization event factory object
|
|
182
|
+
*/
|
|
219
183
|
function synchronizeEventFactory(getHttp, getInterval, getSync, getId, logger) {
|
|
220
184
|
var emitter = (0, _mitt["default"])();
|
|
221
|
-
|
|
222
185
|
var synchronize = function synchronize(messageId) {
|
|
223
186
|
var url = (0, _urlBuilder["default"])('api/v2/sdk/sync_event').param('start_event_id', messageId).build();
|
|
224
187
|
return getHttp().get(url).then(function (resp) {
|
|
@@ -258,220 +221,160 @@ function synchronizeEventFactory(getHttp, getInterval, getSync, getId, logger) {
|
|
|
258
221
|
});
|
|
259
222
|
})["catch"](noop);
|
|
260
223
|
};
|
|
261
|
-
|
|
262
224
|
function generator() {
|
|
263
225
|
return _generator2.apply(this, arguments);
|
|
264
226
|
}
|
|
265
|
-
|
|
266
227
|
function _generator2() {
|
|
267
|
-
_generator2 = (0, _wrapAsyncGenerator2["default"])(
|
|
228
|
+
_generator2 = (0, _wrapAsyncGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
|
268
229
|
var accumulatedInterval, interval, shouldSync;
|
|
269
|
-
return _regenerator["default"].wrap(function
|
|
270
|
-
while (1) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
case 3:
|
|
281
|
-
if (!true) {
|
|
282
|
-
_context3.next = 13;
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
accumulatedInterval += interval;
|
|
287
|
-
|
|
288
|
-
if (!(accumulatedInterval >= getInterval() && shouldSync())) {
|
|
289
|
-
_context3.next = 9;
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
accumulatedInterval = 0;
|
|
294
|
-
_context3.next = 9;
|
|
295
|
-
return synchronize(getId());
|
|
296
|
-
|
|
297
|
-
case 9:
|
|
298
|
-
_context3.next = 11;
|
|
299
|
-
return (0, _awaitAsyncGenerator2["default"])(sleep(interval));
|
|
300
|
-
|
|
301
|
-
case 11:
|
|
302
|
-
_context3.next = 3;
|
|
230
|
+
return _regenerator["default"].wrap(function (_context3) {
|
|
231
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
232
|
+
case 0:
|
|
233
|
+
accumulatedInterval = 0;
|
|
234
|
+
interval = 100;
|
|
235
|
+
shouldSync = function shouldSync() {
|
|
236
|
+
return getHttp() != null && getSync();
|
|
237
|
+
};
|
|
238
|
+
case 1:
|
|
239
|
+
if (!true) {
|
|
240
|
+
_context3.next = 4;
|
|
303
241
|
break;
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
242
|
+
}
|
|
243
|
+
accumulatedInterval += interval;
|
|
244
|
+
if (!(accumulatedInterval >= getInterval() && shouldSync())) {
|
|
245
|
+
_context3.next = 2;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
accumulatedInterval = 0;
|
|
249
|
+
_context3.next = 2;
|
|
250
|
+
return synchronize(getId());
|
|
251
|
+
case 2:
|
|
252
|
+
_context3.next = 3;
|
|
253
|
+
return (0, _awaitAsyncGenerator2["default"])(sleep(interval));
|
|
254
|
+
case 3:
|
|
255
|
+
_context3.next = 1;
|
|
256
|
+
break;
|
|
257
|
+
case 4:
|
|
258
|
+
case "end":
|
|
259
|
+
return _context3.stop();
|
|
309
260
|
}
|
|
310
261
|
}, _callee3);
|
|
311
262
|
}));
|
|
312
263
|
return _generator2.apply(this, arguments);
|
|
313
264
|
}
|
|
314
|
-
|
|
315
265
|
return {
|
|
316
266
|
get synchronize() {
|
|
317
267
|
return synchronize;
|
|
318
268
|
},
|
|
319
|
-
|
|
320
269
|
get on() {
|
|
321
270
|
return emitter.on;
|
|
322
271
|
},
|
|
323
|
-
|
|
324
272
|
get off() {
|
|
325
273
|
return emitter.off;
|
|
326
274
|
},
|
|
327
|
-
|
|
328
275
|
run: function run() {
|
|
329
|
-
return (0, _asyncToGenerator2["default"])(
|
|
330
|
-
var
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (eventId > getId()) {
|
|
365
|
-
emitter.emit('last-event-id.new', eventId);
|
|
366
|
-
result.messageDelivered.forEach(function (it) {
|
|
367
|
-
return emitter.emit('message.delivered', it);
|
|
368
|
-
});
|
|
369
|
-
result.messageDeleted.forEach(function (it) {
|
|
370
|
-
return emitter.emit('message.deleted', it);
|
|
371
|
-
});
|
|
372
|
-
result.messageRead.forEach(function (it) {
|
|
373
|
-
return emitter.emit('message.read', it);
|
|
374
|
-
});
|
|
375
|
-
result.roomCleared.forEach(function (it) {
|
|
376
|
-
return emitter.emit('room.cleared', it);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
} catch (e) {
|
|
380
|
-
logger('error when sync event', e.message);
|
|
276
|
+
return (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
|
277
|
+
var _iteratorAbruptCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, result, eventId, _t2;
|
|
278
|
+
return _regenerator["default"].wrap(function (_context4) {
|
|
279
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
280
|
+
case 0:
|
|
281
|
+
_iteratorAbruptCompletion2 = false;
|
|
282
|
+
_didIteratorError2 = false;
|
|
283
|
+
_context4.prev = 1;
|
|
284
|
+
_iterator2 = _asyncIterator(generator());
|
|
285
|
+
case 2:
|
|
286
|
+
_context4.next = 3;
|
|
287
|
+
return _iterator2.next();
|
|
288
|
+
case 3:
|
|
289
|
+
if (!(_iteratorAbruptCompletion2 = !(_step2 = _context4.sent).done)) {
|
|
290
|
+
_context4.next = 5;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
result = _step2.value;
|
|
294
|
+
try {
|
|
295
|
+
eventId = result.lastId;
|
|
296
|
+
if (eventId > getId()) {
|
|
297
|
+
emitter.emit('last-event-id.new', eventId);
|
|
298
|
+
result.messageDelivered.forEach(function (it) {
|
|
299
|
+
return emitter.emit('message.delivered', it);
|
|
300
|
+
});
|
|
301
|
+
result.messageDeleted.forEach(function (it) {
|
|
302
|
+
return emitter.emit('message.deleted', it);
|
|
303
|
+
});
|
|
304
|
+
result.messageRead.forEach(function (it) {
|
|
305
|
+
return emitter.emit('message.read', it);
|
|
306
|
+
});
|
|
307
|
+
result.roomCleared.forEach(function (it) {
|
|
308
|
+
return emitter.emit('room.cleared', it);
|
|
309
|
+
});
|
|
381
310
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
311
|
+
} catch (e) {
|
|
312
|
+
logger.error('error when sync event', e.message);
|
|
313
|
+
}
|
|
314
|
+
case 4:
|
|
315
|
+
_iteratorAbruptCompletion2 = false;
|
|
316
|
+
_context4.next = 2;
|
|
317
|
+
break;
|
|
318
|
+
case 5:
|
|
319
|
+
_context4.next = 7;
|
|
320
|
+
break;
|
|
321
|
+
case 6:
|
|
322
|
+
_context4.prev = 6;
|
|
323
|
+
_t2 = _context4["catch"](1);
|
|
324
|
+
_didIteratorError2 = true;
|
|
325
|
+
_iteratorError2 = _t2;
|
|
326
|
+
case 7:
|
|
327
|
+
_context4.prev = 7;
|
|
328
|
+
_context4.prev = 8;
|
|
329
|
+
if (!(_iteratorAbruptCompletion2 && _iterator2["return"] != null)) {
|
|
330
|
+
_context4.next = 9;
|
|
386
331
|
break;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
332
|
+
}
|
|
333
|
+
_context4.next = 9;
|
|
334
|
+
return _iterator2["return"]();
|
|
335
|
+
case 9:
|
|
336
|
+
_context4.prev = 9;
|
|
337
|
+
if (!_didIteratorError2) {
|
|
338
|
+
_context4.next = 10;
|
|
390
339
|
break;
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
_context4.prev = 24;
|
|
401
|
-
|
|
402
|
-
if (!(!_iteratorNormalCompletion2 && _iterator2["return"] != null)) {
|
|
403
|
-
_context4.next = 28;
|
|
404
|
-
break;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
_context4.next = 28;
|
|
408
|
-
return _iterator2["return"]();
|
|
409
|
-
|
|
410
|
-
case 28:
|
|
411
|
-
_context4.prev = 28;
|
|
412
|
-
|
|
413
|
-
if (!_didIteratorError2) {
|
|
414
|
-
_context4.next = 31;
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
throw _iteratorError2;
|
|
419
|
-
|
|
420
|
-
case 31:
|
|
421
|
-
return _context4.finish(28);
|
|
422
|
-
|
|
423
|
-
case 32:
|
|
424
|
-
return _context4.finish(23);
|
|
425
|
-
|
|
426
|
-
case 33:
|
|
427
|
-
case "end":
|
|
428
|
-
return _context4.stop();
|
|
429
|
-
}
|
|
340
|
+
}
|
|
341
|
+
throw _iteratorError2;
|
|
342
|
+
case 10:
|
|
343
|
+
return _context4.finish(9);
|
|
344
|
+
case 11:
|
|
345
|
+
return _context4.finish(7);
|
|
346
|
+
case 12:
|
|
347
|
+
case "end":
|
|
348
|
+
return _context4.stop();
|
|
430
349
|
}
|
|
431
|
-
}, _callee4, null, [[
|
|
350
|
+
}, _callee4, null, [[1, 6, 7, 12], [8,, 9, 11]]);
|
|
432
351
|
}))();
|
|
433
352
|
}
|
|
434
353
|
};
|
|
435
354
|
}
|
|
436
|
-
|
|
437
355
|
function SyncAdapter(getHttpAdapter, _ref) {
|
|
438
|
-
var
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
356
|
+
var syncInterval = _ref.syncInterval,
|
|
357
|
+
getShouldSync = _ref.getShouldSync,
|
|
358
|
+
syncOnConnect = _ref.syncOnConnect,
|
|
359
|
+
lastCommentId = _ref.lastCommentId,
|
|
360
|
+
statusLogin = _ref.statusLogin,
|
|
361
|
+
enableSync = _ref.enableSync,
|
|
362
|
+
enableSyncEvent = _ref.enableSyncEvent,
|
|
363
|
+
logger = _ref.logger;
|
|
364
|
+
logger = logger.child('SyncAdapter');
|
|
447
365
|
var emitter = (0, _mitt["default"])();
|
|
448
|
-
|
|
449
|
-
var logger = function logger() {
|
|
450
|
-
var _console;
|
|
451
|
-
|
|
452
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
453
|
-
args[_key] = arguments[_key];
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
return isDebug ? (_console = console).log.apply(_console, ['QSync:'].concat(args)) : {};
|
|
457
|
-
};
|
|
458
|
-
|
|
459
366
|
var lastMessageId = 0;
|
|
460
367
|
var lastEventId = 0;
|
|
461
|
-
|
|
462
368
|
var getInterval = function getInterval() {
|
|
463
369
|
if (statusLogin()) {
|
|
464
370
|
if (getShouldSync()) return syncInterval();
|
|
465
371
|
return syncOnConnect();
|
|
466
372
|
}
|
|
467
|
-
|
|
468
373
|
return 0;
|
|
469
374
|
};
|
|
470
|
-
|
|
471
375
|
var _getShouldSync = function _getShouldSync() {
|
|
472
376
|
return getShouldSync() && enableSync();
|
|
473
377
|
};
|
|
474
|
-
|
|
475
378
|
var syncFactory = synchronizeFactory(getHttpAdapter, getInterval, _getShouldSync, lastCommentId, logger);
|
|
476
379
|
syncFactory.on('last-message-id.new', function (id) {
|
|
477
380
|
return lastMessageId = id;
|
|
@@ -480,13 +383,11 @@ function SyncAdapter(getHttpAdapter, _ref) {
|
|
|
480
383
|
return emitter.emit('message.new', m);
|
|
481
384
|
});
|
|
482
385
|
syncFactory.run()["catch"](function (err) {
|
|
483
|
-
return logger('got error when sync', err);
|
|
386
|
+
return logger.error('got error when sync', err);
|
|
484
387
|
});
|
|
485
|
-
|
|
486
388
|
var _getShouldSyncEvent = function _getShouldSyncEvent() {
|
|
487
389
|
return getShouldSync() && enableSyncEvent();
|
|
488
390
|
};
|
|
489
|
-
|
|
490
391
|
var syncEventFactory = synchronizeEventFactory(getHttpAdapter, getInterval, _getShouldSyncEvent, function () {
|
|
491
392
|
return lastEventId;
|
|
492
393
|
}, logger);
|
|
@@ -506,17 +407,15 @@ function SyncAdapter(getHttpAdapter, _ref) {
|
|
|
506
407
|
return emitter.emit('room.cleared', it);
|
|
507
408
|
});
|
|
508
409
|
syncEventFactory.run()["catch"](function (err) {
|
|
509
|
-
return logger('got error when sync event', err);
|
|
410
|
+
return logger.error('got error when sync event', err);
|
|
510
411
|
});
|
|
511
412
|
return {
|
|
512
413
|
get on() {
|
|
513
414
|
return emitter.on;
|
|
514
415
|
},
|
|
515
|
-
|
|
516
416
|
get off() {
|
|
517
417
|
return emitter.off;
|
|
518
418
|
},
|
|
519
|
-
|
|
520
419
|
synchronize: function synchronize() {
|
|
521
420
|
syncFactory.synchronize();
|
|
522
421
|
},
|
|
@@ -525,5 +424,4 @@ function SyncAdapter(getHttpAdapter, _ref) {
|
|
|
525
424
|
}
|
|
526
425
|
};
|
|
527
426
|
}
|
|
528
|
-
|
|
529
427
|
module.exports = exports.default;
|