@webex/plugin-presence 0.0.0-next.1

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.
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
4
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
5
+ _Object$defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));
10
+ var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
11
+ var _isArray = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/array/is-array"));
12
+ require("@webex/internal-plugin-device");
13
+ var _webexCore = require("@webex/webex-core");
14
+ var _presenceBatcher = _interopRequireDefault(require("./presence-batcher"));
15
+ var _presenceWorker = _interopRequireDefault(require("./presence-worker"));
16
+ /*!
17
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
18
+ */
19
+
20
+ var defaultSubscriptionTtl = 600;
21
+ var USER = 'user';
22
+ var USER_PRESENCE_ENABLED = 'user-presence-enabled';
23
+
24
+ /**
25
+ * @class
26
+ * @extends WebexPlugin
27
+ */
28
+ var Presence = _webexCore.WebexPlugin.extend({
29
+ namespace: 'Presence',
30
+ children: {
31
+ batcher: _presenceBatcher.default
32
+ },
33
+ session: {
34
+ worker: {
35
+ default: function _default() {
36
+ return new _presenceWorker.default();
37
+ },
38
+ type: 'any'
39
+ }
40
+ },
41
+ /**
42
+ * Initialize the presence worker for client
43
+ * @returns {undefined}
44
+ */
45
+ initialize: function initialize() {
46
+ var _this = this;
47
+ this.webex.once('ready', function () {
48
+ if (_this.config.initializeWorker) {
49
+ _this.worker.initialize(_this.webex);
50
+ }
51
+ });
52
+ },
53
+ /**
54
+ * Trigger an event.
55
+ * @param {string} event
56
+ * @param {string} payload
57
+ * @returns {undefined}
58
+ */
59
+ emitEvent: function emitEvent(event, payload) {
60
+ if (payload.type && payload.payload) {
61
+ this.trigger(event, payload);
62
+ }
63
+ },
64
+ /**
65
+ * Enables presence feature
66
+ * @returns {Promise<boolean>} resolves with true, if successful
67
+ */
68
+ enable: function enable() {
69
+ return this.webex.internal.feature.setFeature(USER, USER_PRESENCE_ENABLED, true).then(function (response) {
70
+ return response.value;
71
+ });
72
+ },
73
+ /**
74
+ * Disables presence feature
75
+ * @returns {Promise<boolean>} resolves with false, if successful
76
+ */
77
+ disable: function disable() {
78
+ return this.webex.internal.feature.setFeature(USER, USER_PRESENCE_ENABLED, false).then(function (response) {
79
+ return response.value;
80
+ });
81
+ },
82
+ /**
83
+ * Returns true if presence is enabled, false otherwise
84
+ * @returns {Promise<boolean>} resolves with true if presence is enabled
85
+ */
86
+ isEnabled: function isEnabled() {
87
+ return this.webex.internal.feature.getFeature(USER, USER_PRESENCE_ENABLED);
88
+ },
89
+ /**
90
+ * The status object
91
+ * @typedef {Object} PresenceStatusObject
92
+ * @property {string} url: Public resource identifier for presence
93
+ * @property {string} subject: User ID for the user the returned composed presence represents
94
+ * @property {string} status: Current composed presence state
95
+ * @property {string} statusTime: DateTime in RFC3339 format that the current status began
96
+ * @property {string} lastActive: DateTime in RFC3339 format that the service last saw activity from the user.
97
+ * @property {string} expires: DEPRECATED - DateTime in RFC3339 format that represents when the current
98
+ * status will expire. Will not exist if expiresTTL is -1.
99
+ * @property {Number} expiresTTL: TTL in seconds until the status will expire. If TTL is -1 the current
100
+ * status has no known expiration.
101
+ * @property {string} expiresTime: DateTime in RFC3339 format that the current status will expire. Missing
102
+ * field means no known expiration.
103
+ * @property {Object} vectorCounters: Used for packet ordering and tracking.
104
+ * @property {Boolean} suppressNotifications: Indicates if notification suppression is recommended for this status.
105
+ * @property {string} lastSeenDeviceUrl: Resource Identifier of the last device to post presence activity for
106
+ * this user.
107
+ */
108
+ /**
109
+ * Gets the current presence status of a given person id
110
+ * @param {string} personId
111
+ * @returns {Promise<PresenceStatusObject>} resolves with status object of person
112
+ */
113
+ get: function get(personId) {
114
+ if (!personId) {
115
+ return _promise.default.reject(new Error('A person id is required'));
116
+ }
117
+ return this.webex.request({
118
+ method: 'GET',
119
+ service: 'apheleia',
120
+ resource: "compositions?userId=".concat(personId)
121
+ }).then(function (response) {
122
+ return response.body;
123
+ });
124
+ },
125
+ /**
126
+ * @typedef {Object} PresenceStatusesObject
127
+ * @property {Array.<PresenceStatusObject>} statusList
128
+ */
129
+ /**
130
+ * Gets the current presence statuses of an array of people ids
131
+ * @param {Array} personIds
132
+ * @returns {Promise<PresenceStatusesObject>} resolves with an object with key of `statusList` array
133
+ */
134
+ list: function list(personIds) {
135
+ var _this2 = this;
136
+ if (!personIds || !(0, _isArray.default)(personIds)) {
137
+ return _promise.default.reject(new Error('An array of person ids is required'));
138
+ }
139
+ return _promise.default.all(personIds.map(function (id) {
140
+ return _this2.batcher.request(id);
141
+ })).then(function (presences) {
142
+ return {
143
+ statusList: presences
144
+ };
145
+ });
146
+ },
147
+ /**
148
+ * Subscribes to a person's presence status updates
149
+ * Updates are sent via mercury events `apheleia.subscription_update`
150
+ * @param {string | Array} personIds
151
+ * @param {number} subscriptionTtl - Requested length of subscriptions in seconds.
152
+ * @returns {Promise}
153
+ */
154
+ subscribe: function subscribe(personIds) {
155
+ var _this3 = this;
156
+ var subscriptionTtl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultSubscriptionTtl;
157
+ var subjects;
158
+ var batches = [];
159
+ var batchLimit = 50;
160
+ if (!personIds) {
161
+ return _promise.default.reject(new Error('A person id is required'));
162
+ }
163
+ if ((0, _isArray.default)(personIds)) {
164
+ subjects = personIds;
165
+ } else {
166
+ subjects = [personIds];
167
+ }
168
+ // Limit batches to 50 ids per request
169
+ for (var i = 0; i < subjects.length; i += batchLimit) {
170
+ batches.push(subjects.slice(i, i + batchLimit));
171
+ }
172
+ return _promise.default.all(batches.map(function (ids) {
173
+ return _this3.webex.request({
174
+ method: 'POST',
175
+ api: 'apheleia',
176
+ resource: 'subscriptions',
177
+ body: {
178
+ subjects: ids,
179
+ subscriptionTtl: subscriptionTtl,
180
+ includeStatus: true
181
+ }
182
+ }).then(function (response) {
183
+ return response.body.responses;
184
+ });
185
+ })).then(function (idBatches) {
186
+ var _ref;
187
+ return {
188
+ responses: (_ref = []).concat.apply(_ref, (0, _toConsumableArray2.default)(idBatches))
189
+ };
190
+ });
191
+ },
192
+ /**
193
+ * Unsubscribes from a person or group of people's presence subscription
194
+ * @param {string | Array} personIds
195
+ * @returns {Promise}
196
+ */
197
+ unsubscribe: function unsubscribe(personIds) {
198
+ var subjects;
199
+ if (!personIds) {
200
+ return _promise.default.reject(new Error('A person id is required'));
201
+ }
202
+ if ((0, _isArray.default)(personIds)) {
203
+ subjects = personIds;
204
+ } else {
205
+ subjects = [personIds];
206
+ }
207
+ return this.webex.request({
208
+ method: 'POST',
209
+ api: 'apheleia',
210
+ resource: 'subscriptions',
211
+ body: {
212
+ subjects: subjects,
213
+ subscriptionTtl: 0,
214
+ includeStatus: true
215
+ }
216
+ });
217
+ },
218
+ /**
219
+ * Sets the status of the current user
220
+ * @param {string} status - active | inactive | ooo | dnd
221
+ * @param {number} ttl - Time To Live for the event in seconds.
222
+ * @returns {Promise}
223
+ */
224
+ setStatus: function setStatus(status, ttl) {
225
+ if (!status) {
226
+ return _promise.default.reject(new Error('A status is required'));
227
+ }
228
+ return this.webex.request({
229
+ method: 'POST',
230
+ api: 'apheleia',
231
+ resource: 'events',
232
+ body: {
233
+ subject: this.webex.internal.device.userId,
234
+ eventType: status,
235
+ ttl: ttl
236
+ }
237
+ }).then(function (response) {
238
+ return response.body;
239
+ });
240
+ },
241
+ /**
242
+ * Retrieves and subscribes to a user's presence.
243
+ * @param {string} id
244
+ * @returns {undefined}
245
+ */
246
+ enqueue: function enqueue(id) {
247
+ return this.worker.enqueue(id);
248
+ },
249
+ /**
250
+ * Retract from subscribing to a user's presence.
251
+ * @param {string} id
252
+ * @returns {undefined}
253
+ */
254
+ dequeue: function dequeue(id) {
255
+ return this.worker.dequeue(id);
256
+ },
257
+ version: "0.0.0-next.1"
258
+ });
259
+ var _default2 = exports.default = Presence;
260
+ //# sourceMappingURL=presence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["require","_webexCore","_presenceBatcher","_interopRequireDefault","_presenceWorker","defaultSubscriptionTtl","USER","USER_PRESENCE_ENABLED","Presence","WebexPlugin","extend","namespace","children","batcher","PresenceBatcher","session","worker","default","_default","PresenceWorker","type","initialize","_this","webex","once","config","initializeWorker","emitEvent","event","payload","trigger","enable","internal","feature","setFeature","then","response","value","disable","isEnabled","getFeature","get","personId","_promise","reject","Error","request","method","service","resource","concat","body","list","personIds","_this2","_isArray","all","map","id","presences","statusList","subscribe","_this3","subscriptionTtl","arguments","length","undefined","subjects","batches","batchLimit","i","push","slice","ids","api","includeStatus","responses","idBatches","_ref","apply","_toConsumableArray2","unsubscribe","setStatus","status","ttl","subject","device","userId","eventType","enqueue","dequeue","version","_default2","exports"],"sources":["presence.ts"],"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';\nimport {IEventPayload, IPresence, IPresenceStatusObject} from './interface';\n\nconst defaultSubscriptionTtl = 600;\nconst USER = 'user';\nconst USER_PRESENCE_ENABLED = 'user-presence-enabled';\n\n/**\n * @class\n * @extends WebexPlugin\n */\nconst Presence: IPresence = 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(): void {\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: string, payload: IEventPayload): void {\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(): Promise<boolean> {\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(): Promise<boolean> {\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(): Promise<boolean> {\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: string): Promise<IPresenceStatusObject> {\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: string[]): Promise<{statusList: IPresenceStatusObject[]}> {\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(\n personIds: string | string[],\n subscriptionTtl = defaultSubscriptionTtl\n ): Promise<{responses: any[]}> {\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: string | string[]): Promise<{responses: any}> {\n let subjects: string | string[];\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: string, ttl: number): Promise<any> {\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: string): void {\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: string): void {\n return this.worker.dequeue(id);\n },\n});\n\nexport default Presence;\n"],"mappings":";;;;;;;;;;;AAIAA,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,eAAA,GAAAD,sBAAA,CAAAH,OAAA;AATA;AACA;AACA;;AAUA,IAAMK,sBAAsB,GAAG,GAAG;AAClC,IAAMC,IAAI,GAAG,MAAM;AACnB,IAAMC,qBAAqB,GAAG,uBAAuB;;AAErD;AACA;AACA;AACA;AACA,IAAMC,QAAmB,GAAGC,sBAAW,CAACC,MAAM,CAAC;EAC7CC,SAAS,EAAE,UAAU;EAErBC,QAAQ,EAAE;IACRC,OAAO,EAAEC;EACX,CAAC;EAEDC,OAAO,EAAE;IACPC,MAAM,EAAE;MACNC,OAAO,WAAAC,SAAA,EAAG;QACR,OAAO,IAAIC,uBAAc,CAAC,CAAC;MAC7B,CAAC;MACDC,IAAI,EAAE;IACR;EACF,CAAC;EAED;AACF;AACA;AACA;EACEC,UAAU,WAAAA,WAAA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AAI;IAAA,EAAC;EACtC,CAAC;EAED;AACF;AACA;AACA;AACA;EACEsC,OAAO,WAAAA,QAAC/B,EAAU,EAAQ;IACxB,OAAO,IAAI,CAAC1C,MAAM,CAACyE,OAAO,CAAC/B,EAAE,CAAC;EAChC,CAAC;EAED;AACF;AACA;AACA;AACA;EACEgC,OAAO,WAAAA,QAAChC,EAAU,EAAQ;IACxB,OAAO,IAAI,CAAC1C,MAAM,CAAC0E,OAAO,CAAChC,EAAE,CAAC;EAChC,CAAC;EAAAiC,OAAA;AACH,CAAC,CAAC;AAAC,IAAAC,SAAA,GAAAC,OAAA,CAAA5E,OAAA,GAEYT,QAAQ"}
package/jest.config.js ADDED
@@ -0,0 +1,3 @@
1
+ const config = require('@webex/jest-config-legacy');
2
+
3
+ module.exports = config;
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@webex/plugin-presence",
3
+ "description": "JavaScript SDK for the user presence in the Webex",
4
+ "license": "MIT",
5
+ "main": "dist/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "devMain": "src/index.js",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/webex/webex-js-sdk.git",
11
+ "directory": "packages/@webex/plugin-presence"
12
+ },
13
+ "engines": {
14
+ "node": ">=16"
15
+ },
16
+ "browserify": {
17
+ "transform": [
18
+ "babelify",
19
+ "envify"
20
+ ]
21
+ },
22
+ "devDependencies": {
23
+ "@babel/core": "^7.17.10",
24
+ "@webex/babel-config-legacy": "0.0.0",
25
+ "@webex/eslint-config-legacy": "0.0.0",
26
+ "@webex/jest-config-legacy": "0.0.0",
27
+ "@webex/legacy-tools": "0.0.0",
28
+ "@webex/test-helper-chai": "2.60.1-next.3",
29
+ "@webex/test-helper-mocha": "2.60.1-next.3",
30
+ "@webex/test-helper-mock-webex": "2.60.1-next.3",
31
+ "@webex/test-helper-test-users": "2.60.1-next.3",
32
+ "eslint": "^8.24.0",
33
+ "prettier": "^2.7.1",
34
+ "sinon": "^9.2.4"
35
+ },
36
+ "dependencies": {
37
+ "@webex/internal-plugin-device": "2.60.1-next.3",
38
+ "@webex/internal-plugin-mercury": "2.60.1-next.3",
39
+ "@webex/test-helper-chai": "2.60.1-next.3",
40
+ "@webex/test-helper-mocha": "2.60.1-next.3",
41
+ "@webex/test-helper-mock-webex": "2.60.1-next.3",
42
+ "@webex/test-helper-test-users": "2.60.1-next.3",
43
+ "@webex/webex-core": "2.60.1-next.3",
44
+ "lodash": "^4.17.21"
45
+ },
46
+ "scripts": {
47
+ "build": "yarn run -T tsc --declaration true --declarationDir ./dist/types && yarn run build:src",
48
+ "build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts -maps",
49
+ "deploy:npm": "yarn npm publish",
50
+ "test": "yarn test:style && yarn test:unit && yarn test:integration && yarn test:browser",
51
+ "test:browser:broken": "webex-legacy-tools test --integration --unit --runner karma",
52
+ "test:integration": "webex-legacy-tools test --integration --runner mocha",
53
+ "test:style": "eslint ./src/**/*.*",
54
+ "test:unit": "webex-legacy-tools test --unit --runner jest"
55
+ },
56
+ "version": "0.0.0-next.1"
57
+ }
package/process ADDED
@@ -0,0 +1 @@
1
+ module.exports = {browser: true};
package/src/config.ts ADDED
@@ -0,0 +1,11 @@
1
+ /*!
2
+ * Copyright (c) 2024 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ export default {
6
+ presence: {
7
+ batcherWait: 50,
8
+ batcherMaxCalls: 50,
9
+ batcherMaxWait: 150,
10
+ },
11
+ };
@@ -0,0 +1,19 @@
1
+ export const GROUNDSKEEPER_INTERVAL = 20 * 1000; // 20 seconds in ms
2
+
3
+ export const FETCH_DELAY = 300; // ms
4
+
5
+ export const UPDATE_PRESENCE_DELAY = 60 * 1000; // 1 minute in ms
6
+ export const EXPIRED_PRESENCE_TIME = 10 * 60 * 1000; // 10 minutes in ms
7
+
8
+ export const SUBSCRIPTION_DELAY = 60 * 1000; // 1 minute in ms
9
+ export const PREMATURE_EXPIRATION_SUBSCRIPTION_TIME = 60 * 1000; // 1 minute in ms
10
+ export const DEFAULT_SUBSCRIPTION_TTL = 10 * 60 * 1000; // 10 minutes in ms
11
+
12
+ export const APHELEIA_SUBSCRIPTION_UPDATE = 'event:apheleia.subscription_update';
13
+ export const PRESENCE_UPDATE = 'updated';
14
+
15
+ export const ENVELOPE_TYPE = {
16
+ SUBSCRIPTION: 'subscription',
17
+ PRESENCE: 'presence',
18
+ DELETE: 'delete',
19
+ };
package/src/index.ts ADDED
@@ -0,0 +1,42 @@
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import '@webex/internal-plugin-device';
6
+
7
+ import {registerPlugin} from '@webex/webex-core';
8
+ import {has} from 'lodash';
9
+
10
+ import Presence from './presence';
11
+ import config from './config';
12
+ import {IPredicate, IResponse, ITransform} from './interface';
13
+
14
+ registerPlugin('presence', Presence, {
15
+ payloadTransformer: {
16
+ predicates: [
17
+ {
18
+ name: 'normalizeSingleStatusResponse',
19
+ direction: 'inbound',
20
+ test(ctx, response: IResponse) {
21
+ // POST to /apheleia/api/v1/events
22
+ return Promise.resolve(has(response, 'body.eventType') && has(response, 'body.subject'));
23
+ },
24
+ extract(response: IResponse) {
25
+ return Promise.resolve(response);
26
+ },
27
+ },
28
+ ] as IPredicate[],
29
+ transforms: [
30
+ {
31
+ name: 'normalizeSingleStatusResponse',
32
+ direction: 'inbound',
33
+ fn(ctx, response: IResponse) {
34
+ response.body.status = response.body.eventType;
35
+ },
36
+ },
37
+ ] as ITransform[],
38
+ },
39
+ config,
40
+ });
41
+
42
+ export default Presence;
@@ -0,0 +1,72 @@
1
+ export interface IPresenceStatusObject {
2
+ url: string;
3
+ subject: string;
4
+ status: string;
5
+ statusTime: string;
6
+ lastActive: string;
7
+ expiresTTL: number;
8
+ expiresTime: string;
9
+ vectorCounters: object;
10
+ suppressNotifications: boolean;
11
+ lastseeeDeviceUrl: string;
12
+ }
13
+
14
+ export interface IEventPayload {
15
+ type: string;
16
+ payload: any;
17
+ }
18
+
19
+ export interface IPresence {
20
+ initialize(): void;
21
+ emitEvent(event: string, payload: IEventPayload): void;
22
+ enable(): Promise<boolean>;
23
+ disable(): Promise<boolean>;
24
+ isEnabled(): Promise<boolean>;
25
+ get(personId: string): Promise<IPresenceStatusObject>;
26
+ list(personIds: string[]): Promise<{statusList: IPresenceStatusObject[]}>;
27
+ subscribe(personIds: string | string[], subscriptionTtl?: number): Promise<{responses: any[]}>;
28
+ unsubscribe(personIds: string | string[]): Promise<{responses: any}>;
29
+ setStatus(status: string, ttl: number): Promise<any>;
30
+ enqueue(id: string): void;
31
+ dequeue(id: string): void;
32
+ }
33
+
34
+ export interface IWebex {
35
+ internal: any;
36
+ presence: IPresence;
37
+ }
38
+
39
+ export interface IGenericKeyValue {
40
+ [id: string]: number;
41
+ }
42
+
43
+ export interface IPresenceBatcher {
44
+ handleHttpSuccess(res: any): Promise<any>;
45
+ handleItemFailure(item: string, response: any): Promise<any>;
46
+ handleItemSuccess(item: string, response: any): Promise<any>;
47
+ fingerprintRequest(id: string): Promise<string>;
48
+ fingerprintResponse(id: string): Promise<string>;
49
+ prepareRequest(ids: string[]): Promise<string[]>;
50
+ submitHttpRequest(subjects: any): Promise<any>;
51
+ }
52
+
53
+ export interface IResponse {
54
+ body: {
55
+ eventType: string;
56
+ subject: string;
57
+ status?: string;
58
+ };
59
+ }
60
+
61
+ export interface IPredicate {
62
+ name: string;
63
+ direction: string;
64
+ test(ctx: any, response: IResponse): Promise<boolean>;
65
+ extract?(response: IResponse): Promise<IResponse>;
66
+ }
67
+
68
+ export interface ITransform {
69
+ name: string;
70
+ direction: string;
71
+ fn(ctx: any, response: IResponse): void;
72
+ }
@@ -0,0 +1,101 @@
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {Batcher} from '@webex/webex-core';
6
+ import {IPresenceBatcher} from './interface';
7
+
8
+ /**
9
+ * @class
10
+ * @ignore
11
+ */
12
+ const PresenceBatcher: IPresenceBatcher = Batcher.extend({
13
+ namespace: 'Presence',
14
+
15
+ /**
16
+ * @instance
17
+ * @memberof PresenceBatcher
18
+ * @param {HttpResponseObject} res
19
+ * @returns {Promise}
20
+ */
21
+ handleHttpSuccess(res: any): Promise<any> {
22
+ return Promise.all(
23
+ res.body.statusList.map((presenceResponse) =>
24
+ this.handleItemSuccess(presenceResponse.subject, presenceResponse)
25
+ )
26
+ );
27
+ },
28
+
29
+ /**
30
+ * @instance
31
+ * @memberof PresenceBatcher
32
+ * @param {string} item
33
+ * @param {Object} response
34
+ * @returns {Promise}
35
+ */
36
+ handleItemFailure(item: string, response: any): Promise<any> {
37
+ return this.getDeferredForResponse(item).then((defer) => {
38
+ defer.reject(response);
39
+ });
40
+ },
41
+
42
+ /**
43
+ * @instance
44
+ * @memberof PresenceBatcher
45
+ * @param {string} item
46
+ * @param {Object} response
47
+ * @returns {Promise}
48
+ */
49
+ handleItemSuccess(item: string, response: any): Promise<any> {
50
+ return this.getDeferredForResponse(item).then((defer) => {
51
+ defer.resolve(response);
52
+ });
53
+ },
54
+
55
+ /**
56
+ * @instance
57
+ * @memberof PresenceBatcher
58
+ * @param {string} id
59
+ * @returns {Promise<string>}
60
+ */
61
+ fingerprintRequest(id: string): Promise<string> {
62
+ return Promise.resolve(id);
63
+ },
64
+
65
+ /**
66
+ * @instance
67
+ * @memberof PresenceBatcher
68
+ * @param {string} id
69
+ * @returns {Promise<string>}
70
+ */
71
+ fingerprintResponse(id: string): Promise<string> {
72
+ return Promise.resolve(id);
73
+ },
74
+
75
+ /**
76
+ * @instance
77
+ * @memberof PresenceBatcher
78
+ * @param {Array} ids
79
+ * @returns {Promise<Array>}
80
+ */
81
+ prepareRequest(ids: string[]): Promise<string[]> {
82
+ return Promise.resolve(ids);
83
+ },
84
+
85
+ /**
86
+ * @instance
87
+ * @memberof PresenceBatcher
88
+ * @param {Object} subjects
89
+ * @returns {Promise<HttpResponseObject>}
90
+ */
91
+ submitHttpRequest(subjects: any): Promise<any> {
92
+ return this.webex.request({
93
+ method: 'POST',
94
+ api: 'apheleia',
95
+ resource: 'compositions',
96
+ body: {subjects},
97
+ });
98
+ },
99
+ });
100
+
101
+ export default PresenceBatcher;