@webex/plugin-presence 0.0.0-ipv6-multi-turn-urls.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,283 @@
1
+ "use strict";
2
+
3
+ var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
4
+ var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
5
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
6
+ var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
7
+ var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
8
+ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
9
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
10
+ _Object$defineProperty(exports, "__esModule", {
11
+ value: true
12
+ });
13
+ exports.default = void 0;
14
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
15
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));
16
+ var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
17
+ var _isArray = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/array/is-array"));
18
+ require("@webex/internal-plugin-device");
19
+ var _webexCore = require("@webex/webex-core");
20
+ var _presenceBatcher = _interopRequireDefault(require("./presence-batcher"));
21
+ var _presenceWorker = _interopRequireDefault(require("./presence-worker"));
22
+ function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
23
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; } /*!
24
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
25
+ */
26
+ var defaultSubscriptionTtl = 600;
27
+ var USER = 'user';
28
+ var USER_PRESENCE_ENABLED = 'user-presence-enabled';
29
+
30
+ /**
31
+ * @class
32
+ * @extends WebexPlugin
33
+ */
34
+ var Presence = _webexCore.WebexPlugin.extend({
35
+ namespace: 'Presence',
36
+ children: {
37
+ batcher: _presenceBatcher.default
38
+ },
39
+ session: {
40
+ worker: {
41
+ default: function _default() {
42
+ return new _presenceWorker.default();
43
+ },
44
+ type: 'any'
45
+ }
46
+ },
47
+ /**
48
+ * Initialize the presence plugin
49
+ * @returns {undefined}
50
+ */
51
+ initialize: function initialize() {
52
+ var _this = this;
53
+ this.webex.once('ready', function () {
54
+ if (_this.config.initializeWorker) {
55
+ _this.worker.initialize(_this.webex);
56
+ }
57
+ });
58
+ },
59
+ /**
60
+ * Initializes the presence worker.
61
+ * @returns {undefined}
62
+ */
63
+ initializeWorker: function initializeWorker() {
64
+ var _this2 = this;
65
+ if (this.webex.ready) {
66
+ this.worker.initialize(this.webex);
67
+ } else {
68
+ this.webex.once('ready', function () {
69
+ _this2.worker.initialize(_this2.webex);
70
+ });
71
+ }
72
+ },
73
+ /**
74
+ * Trigger an event.
75
+ * @param {string} event
76
+ * @param {string} payload
77
+ * @returns {undefined}
78
+ */
79
+ emitEvent: function emitEvent(event, payload) {
80
+ if (payload.type && payload.payload) {
81
+ this.trigger(event, payload);
82
+ }
83
+ },
84
+ /**
85
+ * Enables presence feature
86
+ * @returns {Promise<boolean>} resolves with true, if successful
87
+ */
88
+ enable: function enable() {
89
+ return this.webex.internal.feature.setFeature(USER, USER_PRESENCE_ENABLED, true).then(function (response) {
90
+ return response.value;
91
+ });
92
+ },
93
+ /**
94
+ * Disables presence feature
95
+ * @returns {Promise<boolean>} resolves with false, if successful
96
+ */
97
+ disable: function disable() {
98
+ return this.webex.internal.feature.setFeature(USER, USER_PRESENCE_ENABLED, false).then(function (response) {
99
+ return response.value;
100
+ });
101
+ },
102
+ /**
103
+ * Returns true if presence is enabled, false otherwise
104
+ * @returns {Promise<boolean>} resolves with true if presence is enabled
105
+ */
106
+ isEnabled: function isEnabled() {
107
+ return this.webex.internal.feature.getFeature(USER, USER_PRESENCE_ENABLED);
108
+ },
109
+ /**
110
+ * The status object
111
+ * @typedef {Object} PresenceStatusObject
112
+ * @property {string} url: Public resource identifier for presence
113
+ * @property {string} subject: User ID for the user the returned composed presence represents
114
+ * @property {string} status: Current composed presence state
115
+ * @property {string} statusTime: DateTime in RFC3339 format that the current status began
116
+ * @property {string} lastActive: DateTime in RFC3339 format that the service last saw activity from the user.
117
+ * @property {string} expires: DEPRECATED - DateTime in RFC3339 format that represents when the current
118
+ * status will expire. Will not exist if expiresTTL is -1.
119
+ * @property {Number} expiresTTL: TTL in seconds until the status will expire. If TTL is -1 the current
120
+ * status has no known expiration.
121
+ * @property {string} expiresTime: DateTime in RFC3339 format that the current status will expire. Missing
122
+ * field means no known expiration.
123
+ * @property {Object} vectorCounters: Used for packet ordering and tracking.
124
+ * @property {Boolean} suppressNotifications: Indicates if notification suppression is recommended for this status.
125
+ * @property {string} lastSeenDeviceUrl: Resource Identifier of the last device to post presence activity for
126
+ * this user.
127
+ */
128
+ /**
129
+ * Gets the current presence status of a given person id
130
+ * @param {string} personId
131
+ * @returns {Promise<PresenceStatusObject>} resolves with status object of person
132
+ */
133
+ get: function get(personId) {
134
+ if (!personId) {
135
+ return _promise.default.reject(new Error('A person id is required'));
136
+ }
137
+ return this.webex.request({
138
+ method: 'GET',
139
+ service: 'apheleia',
140
+ resource: "compositions?userId=".concat(personId)
141
+ }).then(function (response) {
142
+ return response.body;
143
+ });
144
+ },
145
+ /**
146
+ * @typedef {Object} PresenceStatusesObject
147
+ * @property {Array.<PresenceStatusObject>} statusList
148
+ */
149
+ /**
150
+ * Gets the current presence statuses of an array of people ids
151
+ * @param {Array} personIds
152
+ * @returns {Promise<PresenceStatusesObject>} resolves with an object with key of `statusList` array
153
+ */
154
+ list: function list(personIds) {
155
+ var _this3 = this;
156
+ if (!personIds || !(0, _isArray.default)(personIds)) {
157
+ return _promise.default.reject(new Error('An array of person ids is required'));
158
+ }
159
+ return _promise.default.all(personIds.map(function (id) {
160
+ return _this3.batcher.request(id);
161
+ })).then(function (presences) {
162
+ return {
163
+ statusList: presences
164
+ };
165
+ });
166
+ },
167
+ /**
168
+ * Subscribes to a person's presence status updates
169
+ * Updates are sent via mercury events `apheleia.subscription_update`
170
+ * @param {string | Array} personIds
171
+ * @param {number} subscriptionTtl - Requested length of subscriptions in seconds.
172
+ * @returns {Promise}
173
+ */
174
+ subscribe: function subscribe(personIds) {
175
+ var _this4 = this;
176
+ var subscriptionTtl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultSubscriptionTtl;
177
+ var subjects;
178
+ var batches = [];
179
+ var batchLimit = 50;
180
+ if (!personIds) {
181
+ return _promise.default.reject(new Error('A person id is required'));
182
+ }
183
+ if ((0, _isArray.default)(personIds)) {
184
+ subjects = personIds;
185
+ } else {
186
+ subjects = [personIds];
187
+ }
188
+ // Limit batches to 50 ids per request
189
+ for (var i = 0; i < subjects.length; i += batchLimit) {
190
+ batches.push(subjects.slice(i, i + batchLimit));
191
+ }
192
+ return _promise.default.all(batches.map(function (ids) {
193
+ return _this4.webex.request({
194
+ method: 'POST',
195
+ api: 'apheleia',
196
+ resource: 'subscriptions',
197
+ body: {
198
+ subjects: ids,
199
+ subscriptionTtl: subscriptionTtl,
200
+ includeStatus: true
201
+ }
202
+ }).then(function (response) {
203
+ return response.body.responses;
204
+ });
205
+ })).then(function (idBatches) {
206
+ var _ref;
207
+ return {
208
+ responses: (_ref = []).concat.apply(_ref, (0, _toConsumableArray2.default)(idBatches))
209
+ };
210
+ });
211
+ },
212
+ /**
213
+ * Unsubscribes from a person or group of people's presence subscription
214
+ * @param {string | Array} personIds
215
+ * @returns {Promise}
216
+ */
217
+ unsubscribe: function unsubscribe(personIds) {
218
+ var subjects;
219
+ if (!personIds) {
220
+ return _promise.default.reject(new Error('A person id is required'));
221
+ }
222
+ if ((0, _isArray.default)(personIds)) {
223
+ subjects = personIds;
224
+ } else {
225
+ subjects = [personIds];
226
+ }
227
+ return this.webex.request({
228
+ method: 'POST',
229
+ api: 'apheleia',
230
+ resource: 'subscriptions',
231
+ body: {
232
+ subjects: subjects,
233
+ subscriptionTtl: 0,
234
+ includeStatus: true
235
+ }
236
+ });
237
+ },
238
+ /**
239
+ * Sets the status of the current user
240
+ * @param {string} status - active | inactive | ooo | dnd
241
+ * @param {number} ttl - Time To Live for the event in seconds.
242
+ * @returns {Promise}
243
+ */
244
+ setStatus: function setStatus(status, ttl) {
245
+ if (!status) {
246
+ return _promise.default.reject(new Error('A status is required'));
247
+ }
248
+ return this.webex.request({
249
+ method: 'POST',
250
+ api: 'apheleia',
251
+ resource: 'events',
252
+ body: _objectSpread(_objectSpread({
253
+ subject: this.webex.internal.device.userId,
254
+ eventType: status
255
+ }, status !== 'dnd' && {
256
+ label: this.webex.internal.device.userId
257
+ }), {}, {
258
+ ttl: ttl
259
+ })
260
+ }).then(function (response) {
261
+ return response.body;
262
+ });
263
+ },
264
+ /**
265
+ * Retrieves and subscribes to a user's presence.
266
+ * @param {string} id
267
+ * @returns {undefined}
268
+ */
269
+ enqueue: function enqueue(id) {
270
+ return this.worker.enqueue(id);
271
+ },
272
+ /**
273
+ * Retract from subscribing to a user's presence.
274
+ * @param {string} id
275
+ * @returns {undefined}
276
+ */
277
+ dequeue: function dequeue(id) {
278
+ return this.worker.dequeue(id);
279
+ },
280
+ version: "0.0.0-ipv6-multi-turn-urls.1"
281
+ });
282
+ var _default2 = exports.default = Presence;
283
+ //# sourceMappingURL=presence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["require","_webexCore","_presenceBatcher","_interopRequireDefault","_presenceWorker","ownKeys","e","r","t","_Object$keys","_Object$getOwnPropertySymbols","o","filter","_Object$getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","Object","forEach","_defineProperty2","default","_Object$getOwnPropertyDescriptors","_Object$defineProperties","_Object$defineProperty","defaultSubscriptionTtl","USER","USER_PRESENCE_ENABLED","Presence","WebexPlugin","extend","namespace","children","batcher","PresenceBatcher","session","worker","_default","PresenceWorker","type","initialize","_this","webex","once","config","initializeWorker","_this2","ready","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","_this3","_isArray","all","map","id","presences","statusList","subscribe","_this4","subscriptionTtl","undefined","subjects","batches","batchLimit","i","slice","ids","api","includeStatus","responses","idBatches","_ref","_toConsumableArray2","unsubscribe","setStatus","status","ttl","subject","device","userId","eventType","label","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 plugin\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 * Initializes the presence worker.\n * @returns {undefined}\n */\n initializeWorker(): void {\n if (this.webex.ready) {\n this.worker.initialize(this.webex);\n } else {\n this.webex.once('ready', () => {\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 ...(status !== 'dnd' && {label: this.webex.internal.device.userId}),\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;AAA+C,SAAAK,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,YAAA,CAAAH,CAAA,OAAAI,6BAAA,QAAAC,CAAA,GAAAD,6BAAA,CAAAJ,CAAA,GAAAC,CAAA,KAAAI,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAL,CAAA,WAAAM,gCAAA,CAAAP,CAAA,EAAAC,CAAA,EAAAO,U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B,QAAQ,EAAE,QAAQ;MAClBE,IAAI,EAAAzD,aAAA,CAAAA,aAAA;QACFuF,OAAO,EAAE,IAAI,CAAC5D,KAAK,CAACW,QAAQ,CAACkD,MAAM,CAACC,MAAM;QAC1CC,SAAS,EAAEL;MAAM,GACbA,MAAM,KAAK,KAAK,IAAI;QAACM,KAAK,EAAE,IAAI,CAAChE,KAAK,CAACW,QAAQ,CAACkD,MAAM,CAACC;MAAM,CAAC;QAClEH,GAAG,EAAHA;MAAG;IAEP,CAAC,CAAC,CACD7C,IAAI,CAAC,UAACC,QAAQ;MAAA,OAAKA,QAAQ,CAACe,IAAI;IAAA,EAAC;EACtC,CAAC;EAED;AACF;AACA;AACA;AACA;EACEmC,OAAO,WAAAA,QAAC5B,EAAU,EAAQ;IACxB,OAAO,IAAI,CAAC3C,MAAM,CAACuE,OAAO,CAAC5B,EAAE,CAAC;EAChC,CAAC;EAED;AACF;AACA;AACA;AACA;EACE6B,OAAO,WAAAA,QAAC7B,EAAU,EAAQ;IACxB,OAAO,IAAI,CAAC3C,MAAM,CAACwE,OAAO,CAAC7B,EAAE,CAAC;EAChC,CAAC;EAAA8B,OAAA;AACH,CAAC,CAAC;AAAC,IAAAC,SAAA,GAAAC,OAAA,CAAA1F,OAAA,GAEYO,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,58 @@
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": "3.7.0-ipv6-multi-turn-urls.2",
29
+ "@webex/test-helper-mocha": "3.7.0-ipv6-multi-turn-urls.2",
30
+ "@webex/test-helper-mock-webex": "3.7.0-ipv6-multi-turn-urls.2",
31
+ "@webex/test-helper-test-users": "3.7.0-ipv6-multi-turn-urls.2",
32
+ "eslint": "8.24.0",
33
+ "prettier": "2.7.1",
34
+ "sinon": "9.2.4",
35
+ "typedoc": "0.23.26"
36
+ },
37
+ "dependencies": {
38
+ "@webex/internal-plugin-device": "3.7.0-ipv6-multi-turn-urls.2",
39
+ "@webex/internal-plugin-mercury": "3.7.0-ipv6-multi-turn-urls.2",
40
+ "@webex/test-helper-chai": "3.7.0-ipv6-multi-turn-urls.2",
41
+ "@webex/test-helper-mocha": "3.7.0-ipv6-multi-turn-urls.2",
42
+ "@webex/test-helper-mock-webex": "3.7.0-ipv6-multi-turn-urls.2",
43
+ "@webex/test-helper-test-users": "3.7.0-ipv6-multi-turn-urls.2",
44
+ "@webex/webex-core": "3.7.0-ipv6-multi-turn-urls.2",
45
+ "lodash": "4.17.21"
46
+ },
47
+ "scripts": {
48
+ "build": "yarn run -T tsc --declaration true --declarationDir ./dist/types && yarn run build:src",
49
+ "build:docs": "typedoc --out ../../../docs/presence",
50
+ "build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts -maps",
51
+ "deploy:npm": "yarn npm publish",
52
+ "test": "yarn test:style && yarn test:unit && yarn test:integration && yarn test:browser",
53
+ "test:browser:broken": "webex-legacy-tools test --integration --runner karma",
54
+ "test:style": "eslint ./src/**/*.*",
55
+ "test:unit": "webex-legacy-tools test --unit --runner jest"
56
+ },
57
+ "version": "0.0.0-ipv6-multi-turn-urls.1"
58
+ }
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,82 @@
1
+ export enum PresenceStatus {
2
+ ACTIVE = 'active',
3
+ CALENDAR_ITEM = 'calendarItem',
4
+ CALL = 'call',
5
+ CLEAR = 'clear',
6
+ DND = 'dnd',
7
+ INACTIVE = 'inactive',
8
+ MEETING = 'meeting',
9
+ OOO = 'ooo',
10
+ PRESENTING = 'presenting',
11
+ }
12
+
13
+ export interface IPresenceStatusObject {
14
+ url: string;
15
+ subject: string;
16
+ status: PresenceStatus;
17
+ statusTime: string;
18
+ lastActive: string;
19
+ expiresTTL: number;
20
+ vectorCounters: object;
21
+ suppressNotifications: boolean;
22
+ }
23
+
24
+ export interface IEventPayload {
25
+ type: string;
26
+ payload: any;
27
+ }
28
+
29
+ export interface IPresence {
30
+ initialize(): void;
31
+ emitEvent(event: string, payload: IEventPayload): void;
32
+ enable(): Promise<boolean>;
33
+ disable(): Promise<boolean>;
34
+ isEnabled(): Promise<boolean>;
35
+ get(personId: string): Promise<IPresenceStatusObject>;
36
+ list(personIds: string[]): Promise<{statusList: IPresenceStatusObject[]}>;
37
+ subscribe(personIds: string | string[], subscriptionTtl?: number): Promise<{responses: any[]}>;
38
+ unsubscribe(personIds: string | string[]): Promise<{responses: any}>;
39
+ setStatus(status: string, ttl: number): Promise<any>;
40
+ enqueue(id: string): void;
41
+ dequeue(id: string): void;
42
+ }
43
+
44
+ export interface IWebex {
45
+ internal: any;
46
+ presence: IPresence;
47
+ }
48
+
49
+ export interface IGenericKeyValue {
50
+ [id: string]: number;
51
+ }
52
+
53
+ export interface IPresenceBatcher {
54
+ handleHttpSuccess(res: any): Promise<any>;
55
+ handleItemFailure(item: string, response: any): Promise<any>;
56
+ handleItemSuccess(item: string, response: any): Promise<any>;
57
+ fingerprintRequest(id: string): Promise<string>;
58
+ fingerprintResponse(id: string): Promise<string>;
59
+ prepareRequest(ids: string[]): Promise<string[]>;
60
+ submitHttpRequest(subjects: any): Promise<any>;
61
+ }
62
+
63
+ export interface IResponse {
64
+ body: {
65
+ eventType: string;
66
+ subject: string;
67
+ status?: string;
68
+ };
69
+ }
70
+
71
+ export interface IPredicate {
72
+ name: string;
73
+ direction: string;
74
+ test(ctx: any, response: IResponse): Promise<boolean>;
75
+ extract?(response: IResponse): Promise<IResponse>;
76
+ }
77
+
78
+ export interface ITransform {
79
+ name: string;
80
+ direction: string;
81
+ fn(ctx: any, response: IResponse): void;
82
+ }
@@ -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;