@webex/internal-plugin-presence 3.5.0-next.11 → 3.5.0-next.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/presence.js CHANGED
@@ -39,7 +39,7 @@ var Presence = _webexCore.WebexPlugin.extend({
39
39
  }
40
40
  },
41
41
  /**
42
- * Initialize the presence worker for client
42
+ * Initialize the presence plugin
43
43
  * @returns {undefined}
44
44
  */
45
45
  initialize: function initialize() {
@@ -50,6 +50,20 @@ var Presence = _webexCore.WebexPlugin.extend({
50
50
  }
51
51
  });
52
52
  },
53
+ /**
54
+ * Initializes the presence worker.
55
+ * @returns {undefined}
56
+ */
57
+ initializeWorker: function initializeWorker() {
58
+ var _this2 = this;
59
+ if (this.webex.ready) {
60
+ this.worker.initialize(this.webex);
61
+ } else {
62
+ this.webex.once('ready', function () {
63
+ _this2.worker.initialize(_this2.webex);
64
+ });
65
+ }
66
+ },
53
67
  /**
54
68
  * Trigger an event.
55
69
  * @param {string} event
@@ -132,12 +146,12 @@ var Presence = _webexCore.WebexPlugin.extend({
132
146
  * @returns {Promise<PresenceStatusesObject>} resolves with an object with key of `statusList` array
133
147
  */
134
148
  list: function list(personIds) {
135
- var _this2 = this;
149
+ var _this3 = this;
136
150
  if (!personIds || !(0, _isArray.default)(personIds)) {
137
151
  return _promise.default.reject(new Error('An array of person ids is required'));
138
152
  }
139
153
  return _promise.default.all(personIds.map(function (id) {
140
- return _this2.batcher.request(id);
154
+ return _this3.batcher.request(id);
141
155
  })).then(function (presences) {
142
156
  return {
143
157
  statusList: presences
@@ -152,7 +166,7 @@ var Presence = _webexCore.WebexPlugin.extend({
152
166
  * @returns {Promise}
153
167
  */
154
168
  subscribe: function subscribe(personIds) {
155
- var _this3 = this;
169
+ var _this4 = this;
156
170
  var subscriptionTtl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultSubscriptionTtl;
157
171
  var subjects;
158
172
  var batches = [];
@@ -170,7 +184,7 @@ var Presence = _webexCore.WebexPlugin.extend({
170
184
  batches.push(subjects.slice(i, i + batchLimit));
171
185
  }
172
186
  return _promise.default.all(batches.map(function (ids) {
173
- return _this3.webex.request({
187
+ return _this4.webex.request({
174
188
  method: 'POST',
175
189
  api: 'apheleia',
176
190
  resource: 'subscriptions',
@@ -255,7 +269,7 @@ var Presence = _webexCore.WebexPlugin.extend({
255
269
  dequeue: function dequeue(id) {
256
270
  return this.worker.dequeue(id);
257
271
  },
258
- version: "3.5.0-next.11"
272
+ version: "3.5.0-next.12"
259
273
  });
260
274
  var _default2 = exports.default = Presence;
261
275
  //# sourceMappingURL=presence.js.map
@@ -1 +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","label","enqueue","dequeue","version","_default2","exports"],"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 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) {\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":";;;;;;;;;;;AAIAA,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,eAAA,GAAAD,sBAAA,CAAAH,OAAA;AATA;AACA;AACA;;AASA,IAAMK,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,WAAAC,SAAA,EAAG;QACR,OAAO,IAAIC,uBAAc,CAAC,CAAC;MAC7B,CAAC;MACDC,IAAI,EAAE;IACR;EACF,CAAC;EAED;AACF;AACA;AACA;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ACF;IACF,CAAC,CAAC,CACDjD,IAAI,CAAC,UAACC,QAAQ;MAAA,OAAKA,QAAQ,CAACe,IAAI;IAAA,EAAC;EACtC,CAAC;EAED;AACF;AACA;AACA;AACA;EACEuC,OAAO,WAAAA,QAAChC,EAAE,EAAE;IACV,OAAO,IAAI,CAAC1C,MAAM,CAAC0E,OAAO,CAAChC,EAAE,CAAC;EAChC,CAAC;EAED;AACF;AACA;AACA;AACA;EACEiC,OAAO,WAAAA,QAACjC,EAAE,EAAE;IACV,OAAO,IAAI,CAAC1C,MAAM,CAAC2E,OAAO,CAACjC,EAAE,CAAC;EAChC,CAAC;EAAAkC,OAAA;AACH,CAAC,CAAC;AAAC,IAAAC,SAAA,GAAAC,OAAA,CAAA7E,OAAA,GAEYT,QAAQ"}
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","_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","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","label","enqueue","dequeue","version","_default2","exports"],"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 plugin\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 * Initializes the presence worker.\n * @returns {undefined}\n */\n initializeWorker() {\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, 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 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) {\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":";;;;;;;;;;;AAIAA,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,eAAA,GAAAD,sBAAA,CAAAH,OAAA;AATA;AACA;AACA;;AASA,IAAMK,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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;MACjB;IACF,CAAC,CAAC;EACJ,CAAC;EAED;AACF;AACA;AACA;AACA;AACA;EACEO,SAAS,WAAAA,UAACC,MAAM,EAAEC,GAAG,EAAE;IACrB,IAAI,CAACD,MAAM,EAAE;MACX,OAAOxC,QAAA,CAAA5B,OAAA,CAAQ6B,MAAM,CAAC,IAAIC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1D;IAEA,OAAO,IAAI,CAACxB,KAAK,CACdyB,OAAO,CAAC;MACPC,MAAM,EAAE,MAAM;MACd2B,GAAG,EAAE,UAAU;MACfzB,QAAQ,EAAE,QAAQ;MAClBE,IAAI,EAAE;QACJkC,OAAO,EAAE,IAAI,CAAChE,KAAK,CAACW,QAAQ,CAACsD,MAAM,CAACC,MAAM;QAC1CC,SAAS,EAAEL,MAAM;QACjBM,KAAK,EAAE,IAAI,CAACpE,KAAK,CAACW,QAAQ,CAACsD,MAAM,CAACC,MAAM;QACxCH,GAAG,EAAHA;MACF;IACF,CAAC,CAAC,CACDjD,IAAI,CAAC,UAACC,QAAQ;MAAA,OAAKA,QAAQ,CAACe,IAAI;IAAA,EAAC;EACtC,CAAC;EAED;AACF;AACA;AACA;AACA;EACEuC,OAAO,WAAAA,QAAChC,EAAE,EAAE;IACV,OAAO,IAAI,CAAC5C,MAAM,CAAC4E,OAAO,CAAChC,EAAE,CAAC;EAChC,CAAC;EAED;AACF;AACA;AACA;AACA;EACEiC,OAAO,WAAAA,QAACjC,EAAE,EAAE;IACV,OAAO,IAAI,CAAC5C,MAAM,CAAC6E,OAAO,CAACjC,EAAE,CAAC;EAChC,CAAC;EAAAkC,OAAA;AACH,CAAC,CAAC;AAAC,IAAAC,SAAA,GAAAC,OAAA,CAAA/E,OAAA,GAEYT,QAAQ"}
package/package.json CHANGED
@@ -24,22 +24,22 @@
24
24
  "@webex/eslint-config-legacy": "0.0.0",
25
25
  "@webex/jest-config-legacy": "0.0.0",
26
26
  "@webex/legacy-tools": "0.0.0",
27
- "@webex/test-helper-chai": "3.5.0-next.11",
28
- "@webex/test-helper-mocha": "3.5.0-next.11",
29
- "@webex/test-helper-mock-webex": "3.5.0-next.11",
30
- "@webex/test-helper-test-users": "3.5.0-next.11",
27
+ "@webex/test-helper-chai": "3.5.0-next.12",
28
+ "@webex/test-helper-mocha": "3.5.0-next.12",
29
+ "@webex/test-helper-mock-webex": "3.5.0-next.12",
30
+ "@webex/test-helper-test-users": "3.5.0-next.12",
31
31
  "eslint": "^8.24.0",
32
32
  "prettier": "^2.7.1",
33
33
  "sinon": "^9.2.4"
34
34
  },
35
35
  "dependencies": {
36
- "@webex/internal-plugin-device": "3.5.0-next.11",
37
- "@webex/internal-plugin-mercury": "3.5.0-next.11",
38
- "@webex/test-helper-chai": "3.5.0-next.11",
39
- "@webex/test-helper-mocha": "3.5.0-next.11",
40
- "@webex/test-helper-mock-webex": "3.5.0-next.11",
41
- "@webex/test-helper-test-users": "3.5.0-next.11",
42
- "@webex/webex-core": "3.5.0-next.11",
36
+ "@webex/internal-plugin-device": "3.5.0-next.12",
37
+ "@webex/internal-plugin-mercury": "3.5.0-next.12",
38
+ "@webex/test-helper-chai": "3.5.0-next.12",
39
+ "@webex/test-helper-mocha": "3.5.0-next.12",
40
+ "@webex/test-helper-mock-webex": "3.5.0-next.12",
41
+ "@webex/test-helper-test-users": "3.5.0-next.12",
42
+ "@webex/webex-core": "3.5.0-next.12",
43
43
  "lodash": "^4.17.21"
44
44
  },
45
45
  "scripts": {
@@ -51,5 +51,5 @@
51
51
  "test:style": "eslint ./src/**/*.*",
52
52
  "test:unit": "webex-legacy-tools test --unit --runner jest"
53
53
  },
54
- "version": "3.5.0-next.11"
54
+ "version": "3.5.0-next.12"
55
55
  }
package/src/presence.js CHANGED
@@ -34,7 +34,7 @@ const Presence = WebexPlugin.extend({
34
34
  },
35
35
 
36
36
  /**
37
- * Initialize the presence worker for client
37
+ * Initialize the presence plugin
38
38
  * @returns {undefined}
39
39
  */
40
40
  initialize() {
@@ -45,6 +45,20 @@ const Presence = WebexPlugin.extend({
45
45
  });
46
46
  },
47
47
 
48
+ /**
49
+ * Initializes the presence worker.
50
+ * @returns {undefined}
51
+ */
52
+ initializeWorker() {
53
+ if (this.webex.ready) {
54
+ this.worker.initialize(this.webex);
55
+ } else {
56
+ this.webex.once('ready', () => {
57
+ this.worker.initialize(this.webex);
58
+ });
59
+ }
60
+ },
61
+
48
62
  /**
49
63
  * Trigger an event.
50
64
  * @param {string} event
@@ -88,5 +88,20 @@ describe.skip('plugin-presence', () => {
88
88
  assert.equal(request.args[0].body.label, testGuid);
89
89
  });
90
90
  });
91
+
92
+ describe('#initializeWorker()', () => {
93
+ it('initializes the worker once webex is ready', () => {
94
+ webex.internal.presence.worker = {initialize: sinon.spy()};
95
+ webex.presence.config.initializeWorker = false;
96
+
97
+ webex.internal.presence.initializeWorker();
98
+
99
+ assert.notCalled(webex.internal.presence.worker.initialize);
100
+
101
+ webex.trigger('ready');
102
+
103
+ assert.calledOnce(webex.internal.presence.worker.initialize);
104
+ });
105
+ });
91
106
  });
92
107
  });