@webex/internal-plugin-presence 3.0.0-beta.9 → 3.0.0-beta.90
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/README.md +1 -3
- package/dist/config.js +0 -3
- package/dist/config.js.map +1 -1
- package/dist/constants.js +0 -9
- package/dist/constants.js.map +1 -1
- package/dist/index.js +1 -10
- package/dist/index.js.map +1 -1
- package/dist/presence-batcher.js +0 -15
- package/dist/presence-batcher.js.map +1 -1
- package/dist/presence-worker.js +17 -52
- package/dist/presence-worker.js.map +1 -1
- package/dist/presence.js +7 -46
- package/dist/presence.js.map +1 -1
- package/package.json +9 -9
- package/src/config.js +2 -2
- package/src/constants.js +2 -4
- package/src/index.js +6 -6
- package/src/presence-batcher.js +13 -12
- package/src/presence-worker.js +43 -51
- package/src/presence.js +50 -45
- package/test/integration/spec/presence.js +112 -76
- package/test/unit/spec/presence-worker.js +33 -37
- package/test/unit/spec/presence.js +18 -9
package/dist/presence.js
CHANGED
|
@@ -1,40 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
|
|
11
8
|
exports.default = void 0;
|
|
12
|
-
|
|
13
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));
|
|
14
|
-
|
|
15
10
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
16
|
-
|
|
17
11
|
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/array/is-array"));
|
|
18
|
-
|
|
19
12
|
require("@webex/internal-plugin-device");
|
|
20
|
-
|
|
21
13
|
var _webexCore = require("@webex/webex-core");
|
|
22
|
-
|
|
23
14
|
var _presenceBatcher = _interopRequireDefault(require("./presence-batcher"));
|
|
24
|
-
|
|
25
15
|
var _presenceWorker = _interopRequireDefault(require("./presence-worker"));
|
|
26
|
-
|
|
27
16
|
/*!
|
|
28
17
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
29
18
|
*/
|
|
19
|
+
|
|
30
20
|
var defaultSubscriptionTtl = 600;
|
|
31
21
|
var USER = 'user';
|
|
32
22
|
var USER_PRESENCE_ENABLED = 'user-presence-enabled';
|
|
23
|
+
|
|
33
24
|
/**
|
|
34
25
|
* @class
|
|
35
26
|
* @extends WebexPlugin
|
|
36
27
|
*/
|
|
37
|
-
|
|
38
28
|
var Presence = _webexCore.WebexPlugin.extend({
|
|
39
29
|
namespace: 'Presence',
|
|
40
30
|
children: {
|
|
@@ -48,21 +38,18 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
48
38
|
type: 'any'
|
|
49
39
|
}
|
|
50
40
|
},
|
|
51
|
-
|
|
52
41
|
/**
|
|
53
42
|
* Initialize the presence worker for client
|
|
54
43
|
* @returns {undefined}
|
|
55
44
|
*/
|
|
56
45
|
initialize: function initialize() {
|
|
57
46
|
var _this = this;
|
|
58
|
-
|
|
59
47
|
this.webex.once('ready', function () {
|
|
60
48
|
if (_this.config.initializeWorker) {
|
|
61
49
|
_this.worker.initialize(_this.webex);
|
|
62
50
|
}
|
|
63
51
|
});
|
|
64
52
|
},
|
|
65
|
-
|
|
66
53
|
/**
|
|
67
54
|
* Trigger an event.
|
|
68
55
|
* @param {string} event
|
|
@@ -74,7 +61,6 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
74
61
|
this.trigger(event, payload);
|
|
75
62
|
}
|
|
76
63
|
},
|
|
77
|
-
|
|
78
64
|
/**
|
|
79
65
|
* Enables presence feature
|
|
80
66
|
* @returns {Promise<boolean>} resolves with true, if successful
|
|
@@ -84,7 +70,6 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
84
70
|
return response.value;
|
|
85
71
|
});
|
|
86
72
|
},
|
|
87
|
-
|
|
88
73
|
/**
|
|
89
74
|
* Disables presence feature
|
|
90
75
|
* @returns {Promise<boolean>} resolves with false, if successful
|
|
@@ -94,7 +79,6 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
94
79
|
return response.value;
|
|
95
80
|
});
|
|
96
81
|
},
|
|
97
|
-
|
|
98
82
|
/**
|
|
99
83
|
* Returns true if presence is enabled, false otherwise
|
|
100
84
|
* @returns {Promise<boolean>} resolves with true if presence is enabled
|
|
@@ -102,7 +86,6 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
102
86
|
isEnabled: function isEnabled() {
|
|
103
87
|
return this.webex.internal.feature.getFeature(USER, USER_PRESENCE_ENABLED);
|
|
104
88
|
},
|
|
105
|
-
|
|
106
89
|
/**
|
|
107
90
|
* The status object
|
|
108
91
|
* @typedef {Object} PresenceStatusObject
|
|
@@ -122,7 +105,6 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
122
105
|
* @property {string} lastSeenDeviceUrl: Resource Identifier of the last device to post presence activity for
|
|
123
106
|
* this user.
|
|
124
107
|
*/
|
|
125
|
-
|
|
126
108
|
/**
|
|
127
109
|
* Gets the current presence status of a given person id
|
|
128
110
|
* @param {string} personId
|
|
@@ -132,7 +114,6 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
132
114
|
if (!personId) {
|
|
133
115
|
return _promise.default.reject(new Error('A person id is required'));
|
|
134
116
|
}
|
|
135
|
-
|
|
136
117
|
return this.webex.request({
|
|
137
118
|
method: 'GET',
|
|
138
119
|
service: 'apheleia',
|
|
@@ -141,12 +122,10 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
141
122
|
return response.body;
|
|
142
123
|
});
|
|
143
124
|
},
|
|
144
|
-
|
|
145
125
|
/**
|
|
146
|
-
|
|
147
|
-
|
|
126
|
+
* @typedef {Object} PresenceStatusesObject
|
|
127
|
+
* @property {Array.<PresenceStatusObject>} statusList
|
|
148
128
|
*/
|
|
149
|
-
|
|
150
129
|
/**
|
|
151
130
|
* Gets the current presence statuses of an array of people ids
|
|
152
131
|
* @param {Array} personIds
|
|
@@ -154,11 +133,9 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
154
133
|
*/
|
|
155
134
|
list: function list(personIds) {
|
|
156
135
|
var _this2 = this;
|
|
157
|
-
|
|
158
136
|
if (!personIds || !(0, _isArray.default)(personIds)) {
|
|
159
137
|
return _promise.default.reject(new Error('An array of person ids is required'));
|
|
160
138
|
}
|
|
161
|
-
|
|
162
139
|
return _promise.default.all(personIds.map(function (id) {
|
|
163
140
|
return _this2.batcher.request(id);
|
|
164
141
|
})).then(function (presences) {
|
|
@@ -167,7 +144,6 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
167
144
|
};
|
|
168
145
|
});
|
|
169
146
|
},
|
|
170
|
-
|
|
171
147
|
/**
|
|
172
148
|
* Subscribes to a person's presence status updates
|
|
173
149
|
* Updates are sent via mercury events `apheleia.subscription_update`
|
|
@@ -177,27 +153,22 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
177
153
|
*/
|
|
178
154
|
subscribe: function subscribe(personIds) {
|
|
179
155
|
var _this3 = this;
|
|
180
|
-
|
|
181
156
|
var subscriptionTtl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultSubscriptionTtl;
|
|
182
157
|
var subjects;
|
|
183
158
|
var batches = [];
|
|
184
159
|
var batchLimit = 50;
|
|
185
|
-
|
|
186
160
|
if (!personIds) {
|
|
187
161
|
return _promise.default.reject(new Error('A person id is required'));
|
|
188
162
|
}
|
|
189
|
-
|
|
190
163
|
if ((0, _isArray.default)(personIds)) {
|
|
191
164
|
subjects = personIds;
|
|
192
165
|
} else {
|
|
193
166
|
subjects = [personIds];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
167
|
+
}
|
|
168
|
+
// Limit batches to 50 ids per request
|
|
197
169
|
for (var i = 0; i < subjects.length; i += batchLimit) {
|
|
198
170
|
batches.push(subjects.slice(i, i + batchLimit));
|
|
199
171
|
}
|
|
200
|
-
|
|
201
172
|
return _promise.default.all(batches.map(function (ids) {
|
|
202
173
|
return _this3.webex.request({
|
|
203
174
|
method: 'POST',
|
|
@@ -213,13 +184,11 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
213
184
|
});
|
|
214
185
|
})).then(function (idBatches) {
|
|
215
186
|
var _ref;
|
|
216
|
-
|
|
217
187
|
return {
|
|
218
188
|
responses: (_ref = []).concat.apply(_ref, (0, _toConsumableArray2.default)(idBatches))
|
|
219
189
|
};
|
|
220
190
|
});
|
|
221
191
|
},
|
|
222
|
-
|
|
223
192
|
/**
|
|
224
193
|
* Unsubscribes from a person or group of people's presence subscription
|
|
225
194
|
* @param {string | Array} personIds
|
|
@@ -227,17 +196,14 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
227
196
|
*/
|
|
228
197
|
unsubscribe: function unsubscribe(personIds) {
|
|
229
198
|
var subjects;
|
|
230
|
-
|
|
231
199
|
if (!personIds) {
|
|
232
200
|
return _promise.default.reject(new Error('A person id is required'));
|
|
233
201
|
}
|
|
234
|
-
|
|
235
202
|
if ((0, _isArray.default)(personIds)) {
|
|
236
203
|
subjects = personIds;
|
|
237
204
|
} else {
|
|
238
205
|
subjects = [personIds];
|
|
239
206
|
}
|
|
240
|
-
|
|
241
207
|
return this.webex.request({
|
|
242
208
|
method: 'POST',
|
|
243
209
|
api: 'apheleia',
|
|
@@ -249,7 +215,6 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
249
215
|
}
|
|
250
216
|
});
|
|
251
217
|
},
|
|
252
|
-
|
|
253
218
|
/**
|
|
254
219
|
* Sets the status of the current user
|
|
255
220
|
* @param {string} status - active | inactive | ooo | dnd
|
|
@@ -260,7 +225,6 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
260
225
|
if (!status) {
|
|
261
226
|
return _promise.default.reject(new Error('A status is required'));
|
|
262
227
|
}
|
|
263
|
-
|
|
264
228
|
return this.webex.request({
|
|
265
229
|
method: 'POST',
|
|
266
230
|
api: 'apheleia',
|
|
@@ -274,7 +238,6 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
274
238
|
return response.body;
|
|
275
239
|
});
|
|
276
240
|
},
|
|
277
|
-
|
|
278
241
|
/**
|
|
279
242
|
* Retrieves and subscribes to a user's presence.
|
|
280
243
|
* @param {string} id
|
|
@@ -283,7 +246,6 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
283
246
|
enqueue: function enqueue(id) {
|
|
284
247
|
return this.worker.enqueue(id);
|
|
285
248
|
},
|
|
286
|
-
|
|
287
249
|
/**
|
|
288
250
|
* Retract from subscribing to a user's presence.
|
|
289
251
|
* @param {string} id
|
|
@@ -292,9 +254,8 @@ var Presence = _webexCore.WebexPlugin.extend({
|
|
|
292
254
|
dequeue: function dequeue(id) {
|
|
293
255
|
return this.worker.dequeue(id);
|
|
294
256
|
},
|
|
295
|
-
version: "3.0.0-beta.
|
|
257
|
+
version: "3.0.0-beta.90"
|
|
296
258
|
});
|
|
297
|
-
|
|
298
259
|
var _default2 = Presence;
|
|
299
260
|
exports.default = _default2;
|
|
300
261
|
//# sourceMappingURL=presence.js.map
|
package/dist/presence.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["defaultSubscriptionTtl","USER","USER_PRESENCE_ENABLED","Presence","WebexPlugin","extend","namespace","children","batcher","PresenceBatcher","session","worker","default","PresenceWorker","type","initialize","webex","once","config","initializeWorker","emitEvent","event","payload","trigger","enable","internal","feature","setFeature","then","response","value","disable","isEnabled","getFeature","get","personId","reject","Error","request","method","service","resource","body","list","personIds","all","map","id","presences","statusList","subscribe","subscriptionTtl","subjects","batches","batchLimit","i","length","push","slice","ids","api","includeStatus","responses","idBatches","concat","unsubscribe","setStatus","status","ttl","subject","device","userId","eventType","enqueue","dequeue"],"sources":["presence.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport '@webex/internal-plugin-device';\n\nimport {WebexPlugin} from '@webex/webex-core';\n\nimport PresenceBatcher from './presence-batcher';\nimport PresenceWorker from './presence-worker';\n\nconst defaultSubscriptionTtl = 600;\nconst USER = 'user';\nconst USER_PRESENCE_ENABLED = 'user-presence-enabled';\n\n/**\n * @class\n * @extends WebexPlugin\n */\nconst Presence = WebexPlugin.extend({\n namespace: 'Presence',\n\n children: {\n batcher: PresenceBatcher\n },\n\n session: {\n worker: {\n default() {\n return new PresenceWorker();\n },\n type: 'any'\n }\n },\n\n /**\n * Initialize the presence worker for client\n * @returns {undefined}\n */\n initialize() {\n this.webex.once('ready', () => {\n if (this.config.initializeWorker) {\n this.worker.initialize(this.webex);\n }\n });\n },\n\n /**\n * Trigger an event.\n * @param {string} event\n * @param {string} payload\n * @returns {undefined}\n */\n emitEvent(event, payload) {\n if (payload.type && payload.payload) {\n this.trigger(event, payload);\n }\n },\n\n /**\n * Enables presence feature\n * @returns {Promise<boolean>} resolves with true, if successful\n */\n enable() {\n return this.webex.internal.feature.setFeature(USER, USER_PRESENCE_ENABLED, true)\n .then((response) => response.value);\n },\n\n /**\n * Disables presence feature\n * @returns {Promise<boolean>} resolves with false, if successful\n */\n disable() {\n return this.webex.internal.feature.setFeature(USER, USER_PRESENCE_ENABLED, false)\n .then((response) => response.value);\n },\n\n /**\n * Returns true if presence is enabled, false otherwise\n * @returns {Promise<boolean>} resolves with true if presence is enabled\n */\n isEnabled() {\n return this.webex.internal.feature.getFeature(USER, USER_PRESENCE_ENABLED);\n },\n\n /**\n * The status object\n * @typedef {Object} PresenceStatusObject\n * @property {string} url: Public resource identifier for presence\n * @property {string} subject: User ID for the user the returned composed presence represents\n * @property {string} status: Current composed presence state\n * @property {string} statusTime: DateTime in RFC3339 format that the current status began\n * @property {string} lastActive: DateTime in RFC3339 format that the service last saw activity from the user.\n * @property {string} expires: DEPRECATED - DateTime in RFC3339 format that represents when the current\n * status will expire. Will not exist if expiresTTL is -1.\n * @property {Number} expiresTTL: TTL in seconds until the status will expire. If TTL is -1 the current\n * status has no known expiration.\n * @property {string} expiresTime: DateTime in RFC3339 format that the current status will expire. Missing\n * field means no known expiration.\n * @property {Object} vectorCounters: Used for packet ordering and tracking.\n * @property {Boolean} suppressNotifications: Indicates if notification suppression is recommended for this status.\n * @property {string} lastSeenDeviceUrl: Resource Identifier of the last device to post presence activity for\n * this user.\n */\n\n /**\n * Gets the current presence status of a given person id\n * @param {string} personId\n * @returns {Promise<PresenceStatusObject>} resolves with status object of person\n */\n get(personId) {\n if (!personId) {\n return Promise.reject(new Error('A person id is required'));\n }\n\n return this.webex.request({\n method: 'GET',\n service: 'apheleia',\n resource: `compositions?userId=${personId}`\n })\n .then((response) => response.body);\n },\n\n /**\n * @typedef {Object} PresenceStatusesObject\n * @property {Array.<PresenceStatusObject>} statusList\n */\n /**\n * Gets the current presence statuses of an array of people ids\n * @param {Array} personIds\n * @returns {Promise<PresenceStatusesObject>} resolves with an object with key of `statusList` array\n */\n list(personIds) {\n if (!personIds || !Array.isArray(personIds)) {\n return Promise.reject(new Error('An array of person ids is required'));\n }\n\n return Promise.all(personIds.map((id) =>\n this.batcher.request(id)))\n .then((presences) => ({statusList: presences}));\n },\n\n /**\n * Subscribes to a person's presence status updates\n * Updates are sent via mercury events `apheleia.subscription_update`\n * @param {string | Array} personIds\n * @param {number} subscriptionTtl - Requested length of subscriptions in seconds.\n * @returns {Promise}\n */\n subscribe(personIds, subscriptionTtl = defaultSubscriptionTtl) {\n let subjects;\n const batches = [];\n const batchLimit = 50;\n\n if (!personIds) {\n return Promise.reject(new Error('A person id is required'));\n }\n if (Array.isArray(personIds)) {\n subjects = personIds;\n }\n else {\n subjects = [personIds];\n }\n // Limit batches to 50 ids per request\n for (let i = 0; i < subjects.length; i += batchLimit) {\n batches.push(subjects.slice(i, i + batchLimit));\n }\n\n return Promise.all(batches.map((ids) =>\n this.webex.request({\n method: 'POST',\n api: 'apheleia',\n resource: 'subscriptions',\n body: {\n subjects: ids,\n subscriptionTtl,\n includeStatus: true\n }\n })\n .then((response) => response.body.responses)))\n .then((idBatches) => ({responses: [].concat(...idBatches)}));\n },\n\n /**\n * Unsubscribes from a person or group of people's presence subscription\n * @param {string | Array} personIds\n * @returns {Promise}\n */\n unsubscribe(personIds) {\n let subjects;\n\n if (!personIds) {\n return Promise.reject(new Error('A person id is required'));\n }\n if (Array.isArray(personIds)) {\n subjects = personIds;\n }\n else {\n subjects = [personIds];\n }\n\n return this.webex.request({\n method: 'POST',\n api: 'apheleia',\n resource: 'subscriptions',\n body: {\n subjects,\n subscriptionTtl: 0,\n includeStatus: true\n }\n });\n },\n\n /**\n * Sets the status of the current user\n * @param {string} status - active | inactive | ooo | dnd\n * @param {number} ttl - Time To Live for the event in seconds.\n * @returns {Promise}\n */\n setStatus(status, ttl) {\n if (!status) {\n return Promise.reject(new Error('A status is required'));\n }\n\n return this.webex.request({\n method: 'POST',\n api: 'apheleia',\n resource: 'events',\n body: {\n subject: this.webex.internal.device.userId,\n eventType: status,\n ttl\n }\n })\n .then((response) => response.body);\n },\n\n /**\n * Retrieves and subscribes to a user's presence.\n * @param {string} id\n * @returns {undefined}\n */\n enqueue(id) {\n return this.worker.enqueue(id);\n },\n\n /**\n * Retract from subscribing to a user's presence.\n * @param {string} id\n * @returns {undefined}\n */\n dequeue(id) {\n return this.worker.dequeue(id);\n }\n});\n\nexport default Presence;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAIA;;AAEA;;AAEA;;AACA;;AATA;AACA;AACA;AASA,IAAMA,sBAAsB,GAAG,GAA/B;AACA,IAAMC,IAAI,GAAG,MAAb;AACA,IAAMC,qBAAqB,GAAG,uBAA9B;AAEA;AACA;AACA;AACA;;AACA,IAAMC,QAAQ,GAAGC,sBAAA,CAAYC,MAAZ,CAAmB;EAClCC,SAAS,EAAE,UADuB;EAGlCC,QAAQ,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AAZ,CAAoB1B,EAApB,CAAP;EACD,CAjOiC;;EAmOlC;AACF;AACA;AACA;AACA;EACE2B,OAxOkC,mBAwO1B3B,EAxO0B,EAwOtB;IACV,OAAO,KAAKpC,MAAL,CAAY+D,OAAZ,CAAoB3B,EAApB,CAAP;EACD,CA1OiC;EAAA;AAAA,CAAnB,CAAjB;;gBA6Oe5C,Q"}
|
|
1
|
+
{"version":3,"names":["defaultSubscriptionTtl","USER","USER_PRESENCE_ENABLED","Presence","WebexPlugin","extend","namespace","children","batcher","PresenceBatcher","session","worker","default","PresenceWorker","type","initialize","webex","once","config","initializeWorker","emitEvent","event","payload","trigger","enable","internal","feature","setFeature","then","response","value","disable","isEnabled","getFeature","get","personId","reject","Error","request","method","service","resource","body","list","personIds","all","map","id","presences","statusList","subscribe","subscriptionTtl","subjects","batches","batchLimit","i","length","push","slice","ids","api","includeStatus","responses","idBatches","concat","unsubscribe","setStatus","status","ttl","subject","device","userId","eventType","enqueue","dequeue"],"sources":["presence.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport '@webex/internal-plugin-device';\n\nimport {WebexPlugin} from '@webex/webex-core';\n\nimport PresenceBatcher from './presence-batcher';\nimport PresenceWorker from './presence-worker';\n\nconst defaultSubscriptionTtl = 600;\nconst USER = 'user';\nconst USER_PRESENCE_ENABLED = 'user-presence-enabled';\n\n/**\n * @class\n * @extends WebexPlugin\n */\nconst Presence = WebexPlugin.extend({\n namespace: 'Presence',\n\n children: {\n batcher: PresenceBatcher,\n },\n\n session: {\n worker: {\n default() {\n return new PresenceWorker();\n },\n type: 'any',\n },\n },\n\n /**\n * Initialize the presence worker for client\n * @returns {undefined}\n */\n initialize() {\n this.webex.once('ready', () => {\n if (this.config.initializeWorker) {\n this.worker.initialize(this.webex);\n }\n });\n },\n\n /**\n * Trigger an event.\n * @param {string} event\n * @param {string} payload\n * @returns {undefined}\n */\n emitEvent(event, payload) {\n if (payload.type && payload.payload) {\n this.trigger(event, payload);\n }\n },\n\n /**\n * Enables presence feature\n * @returns {Promise<boolean>} resolves with true, if successful\n */\n enable() {\n return this.webex.internal.feature\n .setFeature(USER, USER_PRESENCE_ENABLED, true)\n .then((response) => response.value);\n },\n\n /**\n * Disables presence feature\n * @returns {Promise<boolean>} resolves with false, if successful\n */\n disable() {\n return this.webex.internal.feature\n .setFeature(USER, USER_PRESENCE_ENABLED, false)\n .then((response) => response.value);\n },\n\n /**\n * Returns true if presence is enabled, false otherwise\n * @returns {Promise<boolean>} resolves with true if presence is enabled\n */\n isEnabled() {\n return this.webex.internal.feature.getFeature(USER, USER_PRESENCE_ENABLED);\n },\n\n /**\n * The status object\n * @typedef {Object} PresenceStatusObject\n * @property {string} url: Public resource identifier for presence\n * @property {string} subject: User ID for the user the returned composed presence represents\n * @property {string} status: Current composed presence state\n * @property {string} statusTime: DateTime in RFC3339 format that the current status began\n * @property {string} lastActive: DateTime in RFC3339 format that the service last saw activity from the user.\n * @property {string} expires: DEPRECATED - DateTime in RFC3339 format that represents when the current\n * status will expire. Will not exist if expiresTTL is -1.\n * @property {Number} expiresTTL: TTL in seconds until the status will expire. If TTL is -1 the current\n * status has no known expiration.\n * @property {string} expiresTime: DateTime in RFC3339 format that the current status will expire. Missing\n * field means no known expiration.\n * @property {Object} vectorCounters: Used for packet ordering and tracking.\n * @property {Boolean} suppressNotifications: Indicates if notification suppression is recommended for this status.\n * @property {string} lastSeenDeviceUrl: Resource Identifier of the last device to post presence activity for\n * this user.\n */\n\n /**\n * Gets the current presence status of a given person id\n * @param {string} personId\n * @returns {Promise<PresenceStatusObject>} resolves with status object of person\n */\n get(personId) {\n if (!personId) {\n return Promise.reject(new Error('A person id is required'));\n }\n\n return this.webex\n .request({\n method: 'GET',\n service: 'apheleia',\n resource: `compositions?userId=${personId}`,\n })\n .then((response) => response.body);\n },\n\n /**\n * @typedef {Object} PresenceStatusesObject\n * @property {Array.<PresenceStatusObject>} statusList\n */\n /**\n * Gets the current presence statuses of an array of people ids\n * @param {Array} personIds\n * @returns {Promise<PresenceStatusesObject>} resolves with an object with key of `statusList` array\n */\n list(personIds) {\n if (!personIds || !Array.isArray(personIds)) {\n return Promise.reject(new Error('An array of person ids is required'));\n }\n\n return Promise.all(personIds.map((id) => this.batcher.request(id))).then((presences) => ({\n statusList: presences,\n }));\n },\n\n /**\n * Subscribes to a person's presence status updates\n * Updates are sent via mercury events `apheleia.subscription_update`\n * @param {string | Array} personIds\n * @param {number} subscriptionTtl - Requested length of subscriptions in seconds.\n * @returns {Promise}\n */\n subscribe(personIds, subscriptionTtl = defaultSubscriptionTtl) {\n let subjects;\n const batches = [];\n const batchLimit = 50;\n\n if (!personIds) {\n return Promise.reject(new Error('A person id is required'));\n }\n if (Array.isArray(personIds)) {\n subjects = personIds;\n } else {\n subjects = [personIds];\n }\n // Limit batches to 50 ids per request\n for (let i = 0; i < subjects.length; i += batchLimit) {\n batches.push(subjects.slice(i, i + batchLimit));\n }\n\n return Promise.all(\n batches.map((ids) =>\n this.webex\n .request({\n method: 'POST',\n api: 'apheleia',\n resource: 'subscriptions',\n body: {\n subjects: ids,\n subscriptionTtl,\n includeStatus: true,\n },\n })\n .then((response) => response.body.responses)\n )\n ).then((idBatches) => ({responses: [].concat(...idBatches)}));\n },\n\n /**\n * Unsubscribes from a person or group of people's presence subscription\n * @param {string | Array} personIds\n * @returns {Promise}\n */\n unsubscribe(personIds) {\n let subjects;\n\n if (!personIds) {\n return Promise.reject(new Error('A person id is required'));\n }\n if (Array.isArray(personIds)) {\n subjects = personIds;\n } else {\n subjects = [personIds];\n }\n\n return this.webex.request({\n method: 'POST',\n api: 'apheleia',\n resource: 'subscriptions',\n body: {\n subjects,\n subscriptionTtl: 0,\n includeStatus: true,\n },\n });\n },\n\n /**\n * Sets the status of the current user\n * @param {string} status - active | inactive | ooo | dnd\n * @param {number} ttl - Time To Live for the event in seconds.\n * @returns {Promise}\n */\n setStatus(status, ttl) {\n if (!status) {\n return Promise.reject(new Error('A status is required'));\n }\n\n return this.webex\n .request({\n method: 'POST',\n api: 'apheleia',\n resource: 'events',\n body: {\n subject: this.webex.internal.device.userId,\n eventType: status,\n ttl,\n },\n })\n .then((response) => response.body);\n },\n\n /**\n * Retrieves and subscribes to a user's presence.\n * @param {string} id\n * @returns {undefined}\n */\n enqueue(id) {\n return this.worker.enqueue(id);\n },\n\n /**\n * Retract from subscribing to a user's presence.\n * @param {string} id\n * @returns {undefined}\n */\n dequeue(id) {\n return this.worker.dequeue(id);\n },\n});\n\nexport default Presence;\n"],"mappings":";;;;;;;;;;;AAIA;AAEA;AAEA;AACA;AATA;AACA;AACA;;AASA,IAAMA,sBAAsB,GAAG,GAAG;AAClC,IAAMC,IAAI,GAAG,MAAM;AACnB,IAAMC,qBAAqB,GAAG,uBAAuB;;AAErD;AACA;AACA;AACA;AACA,IAAMC,QAAQ,GAAGC,sBAAW,CAACC,MAAM,CAAC;EAClCC,SAAS,EAAE,UAAU;EAErBC,QAAQ,EAAE;IACRC,OAAO,EAAEC;EACX,CAAC;EAEDC,OAAO,EAAE;IACPC,MAAM,EAAE;MACNC,OAAO,sBAAG;QACR,OAAO,IAAIC,uBAAc,EAAE;MAC7B,CAAC;MACDC,IAAI,EAAE;IACR;EACF,CAAC;EAED;AACF;AACA;AACA;EACEC,UAAU,wBAAG;IAAA;IACX,IAAI,CAACC,KAAK,CAACC,IAAI,CAAC,OAAO,EAAE,YAAM;MAC7B,IAAI,KAAI,CAACC,MAAM,CAACC,gBAAgB,EAAE;QAChC,KAAI,CAACR,MAAM,CAACI,UAAU,CAAC,KAAI,CAACC,KAAK,CAAC;MACpC;IACF,CAAC,CAAC;EACJ,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEI,SAAS,qBAACC,KAAK,EAAEC,OAAO,EAAE;IACxB,IAAIA,OAAO,CAACR,IAAI,IAAIQ,OAAO,CAACA,OAAO,EAAE;MACnC,IAAI,CAACC,OAAO,CAACF,KAAK,EAAEC,OAAO,CAAC;IAC9B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U;MACfnB,QAAQ,EAAE,QAAQ;MAClBC,IAAI,EAAE;QACJ2B,OAAO,EAAE,IAAI,CAACrD,KAAK,CAACS,QAAQ,CAAC6C,MAAM,CAACC,MAAM;QAC1CC,SAAS,EAAEL,MAAM;QACjBC,GAAG,EAAHA;MACF;IACF,CAAC,CAAC,CACDxC,IAAI,CAAC,UAACC,QAAQ;MAAA,OAAKA,QAAQ,CAACa,IAAI;IAAA,EAAC;EACtC,CAAC;EAED;AACF;AACA;AACA;AACA;EACE+B,OAAO,mBAAC1B,EAAE,EAAE;IACV,OAAO,IAAI,CAACpC,MAAM,CAAC8D,OAAO,CAAC1B,EAAE,CAAC;EAChC,CAAC;EAED;AACF;AACA;AACA;AACA;EACE2B,OAAO,mBAAC3B,EAAE,EAAE;IACV,OAAO,IAAI,CAACpC,MAAM,CAAC+D,OAAO,CAAC3B,EAAE,CAAC;EAChC,CAAC;EAAA;AACH,CAAC,CAAC;AAAC,gBAEY5C,QAAQ;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/internal-plugin-presence",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.90",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"sinon": "^9.2.4"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@webex/internal-plugin-device": "3.0.0-beta.
|
|
27
|
-
"@webex/internal-plugin-mercury": "3.0.0-beta.
|
|
28
|
-
"@webex/internal-plugin-presence": "3.0.0-beta.
|
|
29
|
-
"@webex/test-helper-chai": "3.0.0-beta.
|
|
30
|
-
"@webex/test-helper-mocha": "3.0.0-beta.
|
|
31
|
-
"@webex/test-helper-mock-webex": "3.0.0-beta.
|
|
32
|
-
"@webex/test-helper-test-users": "3.0.0-beta.
|
|
33
|
-
"@webex/webex-core": "3.0.0-beta.
|
|
26
|
+
"@webex/internal-plugin-device": "3.0.0-beta.90",
|
|
27
|
+
"@webex/internal-plugin-mercury": "3.0.0-beta.90",
|
|
28
|
+
"@webex/internal-plugin-presence": "3.0.0-beta.90",
|
|
29
|
+
"@webex/test-helper-chai": "3.0.0-beta.90",
|
|
30
|
+
"@webex/test-helper-mocha": "3.0.0-beta.90",
|
|
31
|
+
"@webex/test-helper-mock-webex": "3.0.0-beta.90",
|
|
32
|
+
"@webex/test-helper-test-users": "3.0.0-beta.90",
|
|
33
|
+
"@webex/webex-core": "3.0.0-beta.90",
|
|
34
34
|
"lodash": "^4.17.21"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/config.js
CHANGED
package/src/constants.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
export const GROUNDSKEEPER_INTERVAL = 20 * 1000; // 20 seconds in ms
|
|
3
2
|
|
|
4
3
|
export const FETCH_DELAY = 300; // ms
|
|
@@ -10,12 +9,11 @@ export const SUBSCRIPTION_DELAY = 60 * 1000; // 1 minute in ms
|
|
|
10
9
|
export const PREMATURE_EXPIRATION_SUBSCRIPTION_TIME = 60 * 1000; // 1 minute in ms
|
|
11
10
|
export const DEFAULT_SUBSCRIPTION_TTL = 10 * 60 * 1000; // 10 minutes in ms
|
|
12
11
|
|
|
13
|
-
export const APHELEIA_SUBSCRIPTION_UPDATE =
|
|
14
|
-
'event:apheleia.subscription_update';
|
|
12
|
+
export const APHELEIA_SUBSCRIPTION_UPDATE = 'event:apheleia.subscription_update';
|
|
15
13
|
export const PRESENCE_UPDATE = 'updated';
|
|
16
14
|
|
|
17
15
|
export const ENVELOPE_TYPE = {
|
|
18
16
|
SUBSCRIPTION: 'subscription',
|
|
19
17
|
PRESENCE: 'presence',
|
|
20
|
-
DELETE: 'delete'
|
|
18
|
+
DELETE: 'delete',
|
|
21
19
|
};
|
package/src/index.js
CHANGED
|
@@ -22,8 +22,8 @@ registerInternalPlugin('presence', Presence, {
|
|
|
22
22
|
},
|
|
23
23
|
extract(response) {
|
|
24
24
|
return Promise.resolve(response);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
27
|
],
|
|
28
28
|
transforms: [
|
|
29
29
|
{
|
|
@@ -31,11 +31,11 @@ registerInternalPlugin('presence', Presence, {
|
|
|
31
31
|
direction: 'inbound',
|
|
32
32
|
fn(ctx, response) {
|
|
33
33
|
response.body.status = response.body.eventType;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
]
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
37
|
},
|
|
38
|
-
config
|
|
38
|
+
config,
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
export {default} from './presence';
|
package/src/presence-batcher.js
CHANGED
|
@@ -18,8 +18,11 @@ const PresenceBatcher = Batcher.extend({
|
|
|
18
18
|
* @returns {Promise}
|
|
19
19
|
*/
|
|
20
20
|
handleHttpSuccess(res) {
|
|
21
|
-
return Promise.all(
|
|
22
|
-
|
|
21
|
+
return Promise.all(
|
|
22
|
+
res.body.statusList.map((presenceResponse) =>
|
|
23
|
+
this.handleItemSuccess(presenceResponse.subject, presenceResponse)
|
|
24
|
+
)
|
|
25
|
+
);
|
|
23
26
|
},
|
|
24
27
|
|
|
25
28
|
/**
|
|
@@ -30,10 +33,9 @@ const PresenceBatcher = Batcher.extend({
|
|
|
30
33
|
* @returns {Promise}
|
|
31
34
|
*/
|
|
32
35
|
handleItemFailure(item, response) {
|
|
33
|
-
return this.getDeferredForResponse(item)
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
});
|
|
36
|
+
return this.getDeferredForResponse(item).then((defer) => {
|
|
37
|
+
defer.reject(response);
|
|
38
|
+
});
|
|
37
39
|
},
|
|
38
40
|
|
|
39
41
|
/**
|
|
@@ -44,10 +46,9 @@ const PresenceBatcher = Batcher.extend({
|
|
|
44
46
|
* @returns {Promise}
|
|
45
47
|
*/
|
|
46
48
|
handleItemSuccess(item, response) {
|
|
47
|
-
return this.getDeferredForResponse(item)
|
|
48
|
-
.
|
|
49
|
-
|
|
50
|
-
});
|
|
49
|
+
return this.getDeferredForResponse(item).then((defer) => {
|
|
50
|
+
defer.resolve(response);
|
|
51
|
+
});
|
|
51
52
|
},
|
|
52
53
|
|
|
53
54
|
/**
|
|
@@ -91,9 +92,9 @@ const PresenceBatcher = Batcher.extend({
|
|
|
91
92
|
method: 'POST',
|
|
92
93
|
api: 'apheleia',
|
|
93
94
|
resource: 'compositions',
|
|
94
|
-
body: {subjects}
|
|
95
|
+
body: {subjects},
|
|
95
96
|
});
|
|
96
|
-
}
|
|
97
|
+
},
|
|
97
98
|
});
|
|
98
99
|
|
|
99
100
|
export default PresenceBatcher;
|
package/src/presence-worker.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import {debounce} from 'lodash';
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -11,7 +10,7 @@ import {
|
|
|
11
10
|
DEFAULT_SUBSCRIPTION_TTL,
|
|
12
11
|
APHELEIA_SUBSCRIPTION_UPDATE,
|
|
13
12
|
PRESENCE_UPDATE,
|
|
14
|
-
ENVELOPE_TYPE
|
|
13
|
+
ENVELOPE_TYPE,
|
|
15
14
|
} from './constants';
|
|
16
15
|
|
|
17
16
|
/**
|
|
@@ -46,12 +45,15 @@ export default class PresenceWorker {
|
|
|
46
45
|
|
|
47
46
|
this.webex = webex;
|
|
48
47
|
|
|
49
|
-
const mercury = this.webex.internal.mercury.connected
|
|
50
|
-
Promise.resolve()
|
|
48
|
+
const mercury = this.webex.internal.mercury.connected
|
|
49
|
+
? Promise.resolve()
|
|
50
|
+
: this.webex.internal.mercury.connect();
|
|
51
51
|
|
|
52
52
|
mercury.then(() => {
|
|
53
|
-
this.webex.internal.mercury.on(
|
|
54
|
-
|
|
53
|
+
this.webex.internal.mercury.on(
|
|
54
|
+
APHELEIA_SUBSCRIPTION_UPDATE,
|
|
55
|
+
this.subscriptionUpdate.bind(this)
|
|
56
|
+
);
|
|
55
57
|
});
|
|
56
58
|
|
|
57
59
|
setInterval(this.groundskeeper.bind(this), GROUNDSKEEPER_INTERVAL);
|
|
@@ -67,7 +69,7 @@ export default class PresenceWorker {
|
|
|
67
69
|
|
|
68
70
|
this.webex.internal.presence.emitEvent(PRESENCE_UPDATE, {
|
|
69
71
|
type: ENVELOPE_TYPE.SUBSCRIPTION,
|
|
70
|
-
payload: event.data
|
|
72
|
+
payload: event.data,
|
|
71
73
|
});
|
|
72
74
|
}
|
|
73
75
|
|
|
@@ -81,8 +83,7 @@ export default class PresenceWorker {
|
|
|
81
83
|
|
|
82
84
|
if (this.watchers[id]) {
|
|
83
85
|
this.watchers[id] += 1;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
+
} else {
|
|
86
87
|
this.watchers[id] = 1;
|
|
87
88
|
}
|
|
88
89
|
|
|
@@ -98,9 +99,10 @@ export default class PresenceWorker {
|
|
|
98
99
|
// not in flight or
|
|
99
100
|
// don't already have the presence or
|
|
100
101
|
// presence has gone stale
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
if (
|
|
103
|
+
!this.flights[id] &&
|
|
104
|
+
(!this.presences[id] || this.presences[id] < now - UPDATE_PRESENCE_DELAY)
|
|
105
|
+
) {
|
|
104
106
|
this.fetchers[id] = id;
|
|
105
107
|
this.debouncedFetch();
|
|
106
108
|
}
|
|
@@ -133,23 +135,21 @@ export default class PresenceWorker {
|
|
|
133
135
|
Object.assign(this.flights, boarding);
|
|
134
136
|
this.fetchers = {};
|
|
135
137
|
|
|
138
|
+
this.webex.internal.presence.list(Object.keys(boarding)).then((response) => {
|
|
139
|
+
const now = new Date().getTime();
|
|
136
140
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const now = new Date().getTime();
|
|
140
|
-
|
|
141
|
-
response.statusList.forEach((presence) => {
|
|
142
|
-
const id = presence.subject;
|
|
141
|
+
response.statusList.forEach((presence) => {
|
|
142
|
+
const id = presence.subject;
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
delete this.flights[id];
|
|
145
|
+
this.presences[id] = now;
|
|
146
|
+
});
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
148
|
+
this.webex.internal.presence.emitEvent(PRESENCE_UPDATE, {
|
|
149
|
+
type: ENVELOPE_TYPE.PRESENCE,
|
|
150
|
+
payload: response,
|
|
152
151
|
});
|
|
152
|
+
});
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
debouncedFetch = debounce(this.checkFetchers, FETCH_DELAY);
|
|
@@ -192,11 +192,9 @@ export default class PresenceWorker {
|
|
|
192
192
|
|
|
193
193
|
if (expiration) {
|
|
194
194
|
// Renew subscription if they're about to expire
|
|
195
|
-
if (this.watchers[id] &&
|
|
196
|
-
now > expiration - PREMATURE_EXPIRATION_SUBSCRIPTION_TIME) {
|
|
195
|
+
if (this.watchers[id] && now > expiration - PREMATURE_EXPIRATION_SUBSCRIPTION_TIME) {
|
|
197
196
|
renewIds.push(id);
|
|
198
|
-
}
|
|
199
|
-
else if (now > expiration) {
|
|
197
|
+
} else if (now > expiration) {
|
|
200
198
|
delete this.subscribers[id];
|
|
201
199
|
}
|
|
202
200
|
}
|
|
@@ -228,7 +226,7 @@ export default class PresenceWorker {
|
|
|
228
226
|
if (trash.length) {
|
|
229
227
|
this.webex.internal.presence.emitEvent(PRESENCE_UPDATE, {
|
|
230
228
|
type: ENVELOPE_TYPE.DELETE,
|
|
231
|
-
payload: trash
|
|
229
|
+
payload: trash,
|
|
232
230
|
});
|
|
233
231
|
}
|
|
234
232
|
}
|
|
@@ -245,32 +243,26 @@ export default class PresenceWorker {
|
|
|
245
243
|
const campers = this.checkCampers();
|
|
246
244
|
const renewSubscriptions = this.checkSubscriptions();
|
|
247
245
|
|
|
248
|
-
const ids = [
|
|
249
|
-
...campers,
|
|
250
|
-
...renewSubscriptions
|
|
251
|
-
];
|
|
246
|
+
const ids = [...campers, ...renewSubscriptions];
|
|
252
247
|
|
|
253
248
|
if (ids.length) {
|
|
254
|
-
this.webex.internal.presence.subscribe(ids)
|
|
255
|
-
.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
this.subscribers[response.subject] = now + DEFAULT_SUBSCRIPTION_TTL;
|
|
268
|
-
}
|
|
269
|
-
});
|
|
249
|
+
this.webex.internal.presence.subscribe(ids).then((body) => {
|
|
250
|
+
const now = new Date().getTime();
|
|
251
|
+
|
|
252
|
+
body.responses.forEach((response) => {
|
|
253
|
+
if (response.responseCode === 200) {
|
|
254
|
+
const ttl = response.subscriptionTtl * 1000;
|
|
255
|
+
|
|
256
|
+
this.subscribers[response.subject] = now + ttl;
|
|
257
|
+
this.presences[response.status.subject] = now;
|
|
258
|
+
} else {
|
|
259
|
+
// If it errored for any reason, set the ttl so we clean it out eventually
|
|
260
|
+
this.subscribers[response.subject] = now + DEFAULT_SUBSCRIPTION_TTL;
|
|
261
|
+
}
|
|
270
262
|
});
|
|
263
|
+
});
|
|
271
264
|
}
|
|
272
265
|
|
|
273
266
|
this.cleanPresences();
|
|
274
267
|
}
|
|
275
268
|
}
|
|
276
|
-
|