@webex/internal-plugin-presence 3.0.0-beta.9 → 3.0.0-bnr.0
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/internal-plugin-presence.d.ts +8 -0
- 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/dist/tsdoc-metadata.json +11 -0
- package/dist/types/config.d.ts +8 -0
- package/dist/types/constants.d.ts +14 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/presence-batcher.d.ts +6 -0
- package/dist/types/presence-worker.d.ts +68 -0
- package/dist/types/presence.d.ts +6 -0
- 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/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
|
-
|
package/src/presence.js
CHANGED
|
@@ -21,7 +21,7 @@ const Presence = WebexPlugin.extend({
|
|
|
21
21
|
namespace: 'Presence',
|
|
22
22
|
|
|
23
23
|
children: {
|
|
24
|
-
batcher: PresenceBatcher
|
|
24
|
+
batcher: PresenceBatcher,
|
|
25
25
|
},
|
|
26
26
|
|
|
27
27
|
session: {
|
|
@@ -29,8 +29,8 @@ const Presence = WebexPlugin.extend({
|
|
|
29
29
|
default() {
|
|
30
30
|
return new PresenceWorker();
|
|
31
31
|
},
|
|
32
|
-
type: 'any'
|
|
33
|
-
}
|
|
32
|
+
type: 'any',
|
|
33
|
+
},
|
|
34
34
|
},
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -62,7 +62,8 @@ const Presence = WebexPlugin.extend({
|
|
|
62
62
|
* @returns {Promise<boolean>} resolves with true, if successful
|
|
63
63
|
*/
|
|
64
64
|
enable() {
|
|
65
|
-
return this.webex.internal.feature
|
|
65
|
+
return this.webex.internal.feature
|
|
66
|
+
.setFeature(USER, USER_PRESENCE_ENABLED, true)
|
|
66
67
|
.then((response) => response.value);
|
|
67
68
|
},
|
|
68
69
|
|
|
@@ -71,7 +72,8 @@ const Presence = WebexPlugin.extend({
|
|
|
71
72
|
* @returns {Promise<boolean>} resolves with false, if successful
|
|
72
73
|
*/
|
|
73
74
|
disable() {
|
|
74
|
-
return this.webex.internal.feature
|
|
75
|
+
return this.webex.internal.feature
|
|
76
|
+
.setFeature(USER, USER_PRESENCE_ENABLED, false)
|
|
75
77
|
.then((response) => response.value);
|
|
76
78
|
},
|
|
77
79
|
|
|
@@ -113,17 +115,18 @@ const Presence = WebexPlugin.extend({
|
|
|
113
115
|
return Promise.reject(new Error('A person id is required'));
|
|
114
116
|
}
|
|
115
117
|
|
|
116
|
-
return this.webex
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
return this.webex
|
|
119
|
+
.request({
|
|
120
|
+
method: 'GET',
|
|
121
|
+
service: 'apheleia',
|
|
122
|
+
resource: `compositions?userId=${personId}`,
|
|
123
|
+
})
|
|
121
124
|
.then((response) => response.body);
|
|
122
125
|
},
|
|
123
126
|
|
|
124
127
|
/**
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
* @typedef {Object} PresenceStatusesObject
|
|
129
|
+
* @property {Array.<PresenceStatusObject>} statusList
|
|
127
130
|
*/
|
|
128
131
|
/**
|
|
129
132
|
* Gets the current presence statuses of an array of people ids
|
|
@@ -135,9 +138,9 @@ const Presence = WebexPlugin.extend({
|
|
|
135
138
|
return Promise.reject(new Error('An array of person ids is required'));
|
|
136
139
|
}
|
|
137
140
|
|
|
138
|
-
return Promise.all(personIds.map((id) =>
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
return Promise.all(personIds.map((id) => this.batcher.request(id))).then((presences) => ({
|
|
142
|
+
statusList: presences,
|
|
143
|
+
}));
|
|
141
144
|
},
|
|
142
145
|
|
|
143
146
|
/**
|
|
@@ -157,8 +160,7 @@ const Presence = WebexPlugin.extend({
|
|
|
157
160
|
}
|
|
158
161
|
if (Array.isArray(personIds)) {
|
|
159
162
|
subjects = personIds;
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
163
|
+
} else {
|
|
162
164
|
subjects = [personIds];
|
|
163
165
|
}
|
|
164
166
|
// Limit batches to 50 ids per request
|
|
@@ -166,19 +168,22 @@ const Presence = WebexPlugin.extend({
|
|
|
166
168
|
batches.push(subjects.slice(i, i + batchLimit));
|
|
167
169
|
}
|
|
168
170
|
|
|
169
|
-
return Promise.all(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
171
|
+
return Promise.all(
|
|
172
|
+
batches.map((ids) =>
|
|
173
|
+
this.webex
|
|
174
|
+
.request({
|
|
175
|
+
method: 'POST',
|
|
176
|
+
api: 'apheleia',
|
|
177
|
+
resource: 'subscriptions',
|
|
178
|
+
body: {
|
|
179
|
+
subjects: ids,
|
|
180
|
+
subscriptionTtl,
|
|
181
|
+
includeStatus: true,
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
.then((response) => response.body.responses)
|
|
185
|
+
)
|
|
186
|
+
).then((idBatches) => ({responses: [].concat(...idBatches)}));
|
|
182
187
|
},
|
|
183
188
|
|
|
184
189
|
/**
|
|
@@ -194,8 +199,7 @@ const Presence = WebexPlugin.extend({
|
|
|
194
199
|
}
|
|
195
200
|
if (Array.isArray(personIds)) {
|
|
196
201
|
subjects = personIds;
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
202
|
+
} else {
|
|
199
203
|
subjects = [personIds];
|
|
200
204
|
}
|
|
201
205
|
|
|
@@ -206,8 +210,8 @@ const Presence = WebexPlugin.extend({
|
|
|
206
210
|
body: {
|
|
207
211
|
subjects,
|
|
208
212
|
subscriptionTtl: 0,
|
|
209
|
-
includeStatus: true
|
|
210
|
-
}
|
|
213
|
+
includeStatus: true,
|
|
214
|
+
},
|
|
211
215
|
});
|
|
212
216
|
},
|
|
213
217
|
|
|
@@ -222,16 +226,17 @@ const Presence = WebexPlugin.extend({
|
|
|
222
226
|
return Promise.reject(new Error('A status is required'));
|
|
223
227
|
}
|
|
224
228
|
|
|
225
|
-
return this.webex
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
229
|
+
return this.webex
|
|
230
|
+
.request({
|
|
231
|
+
method: 'POST',
|
|
232
|
+
api: 'apheleia',
|
|
233
|
+
resource: 'events',
|
|
234
|
+
body: {
|
|
235
|
+
subject: this.webex.internal.device.userId,
|
|
236
|
+
eventType: status,
|
|
237
|
+
ttl,
|
|
238
|
+
},
|
|
239
|
+
})
|
|
235
240
|
.then((response) => response.body);
|
|
236
241
|
},
|
|
237
242
|
|
|
@@ -251,7 +256,7 @@ const Presence = WebexPlugin.extend({
|
|
|
251
256
|
*/
|
|
252
257
|
dequeue(id) {
|
|
253
258
|
return this.worker.dequeue(id);
|
|
254
|
-
}
|
|
259
|
+
},
|
|
255
260
|
});
|
|
256
261
|
|
|
257
262
|
export default Presence;
|
|
@@ -16,77 +16,85 @@ describe('plugin-presence', function () {
|
|
|
16
16
|
describe('Presence', () => {
|
|
17
17
|
let mccoy, spock;
|
|
18
18
|
|
|
19
|
-
beforeEach('create users', () =>
|
|
20
|
-
.then((users) => {
|
|
19
|
+
beforeEach('create users', () =>
|
|
20
|
+
testUsers.create({count: 2}).then((users) => {
|
|
21
21
|
[spock, mccoy] = users;
|
|
22
22
|
spock.webex = new WebexCore({
|
|
23
23
|
credentials: {
|
|
24
|
-
authorization: users[0].token
|
|
25
|
-
}
|
|
24
|
+
authorization: users[0].token,
|
|
25
|
+
},
|
|
26
26
|
});
|
|
27
27
|
mccoy.webex = new WebexCore({
|
|
28
28
|
credentials: {
|
|
29
|
-
authorization: users[1].token
|
|
30
|
-
}
|
|
29
|
+
authorization: users[1].token,
|
|
30
|
+
},
|
|
31
31
|
});
|
|
32
|
-
})
|
|
32
|
+
})
|
|
33
|
+
);
|
|
33
34
|
|
|
34
|
-
beforeEach('register with wdm', () =>
|
|
35
|
-
spock.webex.internal.device.register(),
|
|
36
|
-
|
|
37
|
-
]));
|
|
35
|
+
beforeEach('register with wdm', () =>
|
|
36
|
+
Promise.all([spock.webex.internal.device.register(), mccoy.webex.internal.device.register()])
|
|
37
|
+
);
|
|
38
38
|
|
|
39
39
|
beforeEach('register spock with mercury', () => spock.webex.internal.mercury.connect());
|
|
40
40
|
|
|
41
41
|
afterEach('deregister spock with mercury', () => spock.webex.internal.mercury.disconnect());
|
|
42
42
|
|
|
43
43
|
describe('#enable()', () => {
|
|
44
|
-
it('enables presence', () =>
|
|
45
|
-
.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
it('enables presence', () =>
|
|
45
|
+
spock.webex.internal.presence
|
|
46
|
+
.enable()
|
|
47
|
+
.then((isEnabled) => {
|
|
48
|
+
assert.equal(isEnabled, true);
|
|
49
|
+
})
|
|
50
|
+
.then(() => spock.webex.internal.presence.isEnabled())
|
|
51
|
+
.then((isEnabled) => {
|
|
52
|
+
assert.equal(isEnabled, true);
|
|
53
|
+
}));
|
|
52
54
|
});
|
|
53
55
|
|
|
54
56
|
describe('#disable()', () => {
|
|
55
|
-
it('disables presence', () =>
|
|
56
|
-
.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
it('disables presence', () =>
|
|
58
|
+
spock.webex.internal.presence
|
|
59
|
+
.disable()
|
|
60
|
+
.then((isEnabled) => {
|
|
61
|
+
assert.equal(isEnabled, false);
|
|
62
|
+
})
|
|
63
|
+
.then(() => spock.webex.internal.presence.isEnabled())
|
|
64
|
+
.then((isEnabled) => {
|
|
65
|
+
assert.equal(isEnabled, false);
|
|
66
|
+
}));
|
|
63
67
|
});
|
|
64
68
|
|
|
65
69
|
describe('#isEnabled()', () => {
|
|
66
|
-
it('returns true when presence is enabled', () =>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
it('returns true when presence is enabled', () =>
|
|
71
|
+
spock.webex.internal.presence
|
|
72
|
+
.enable()
|
|
73
|
+
.then(() => spock.webex.internal.presence.isEnabled())
|
|
74
|
+
.then((isEnabled) => {
|
|
75
|
+
assert.equal(isEnabled, true);
|
|
76
|
+
}));
|
|
71
77
|
|
|
72
|
-
it('returns false when presence is disabled', () =>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
it('returns false when presence is disabled', () =>
|
|
79
|
+
spock.webex.internal.presence
|
|
80
|
+
.disable()
|
|
81
|
+
.then(() => spock.webex.internal.presence.isEnabled())
|
|
82
|
+
.then((isEnabled) => {
|
|
83
|
+
assert.equal(isEnabled, false);
|
|
84
|
+
}));
|
|
77
85
|
});
|
|
78
86
|
|
|
79
87
|
describe('#get()', () => {
|
|
80
|
-
it(
|
|
81
|
-
.then((presenceResponse) => {
|
|
88
|
+
it("gets a person's status by id", () =>
|
|
89
|
+
spock.webex.internal.presence.get(mccoy.id).then((presenceResponse) => {
|
|
82
90
|
assert.property(presenceResponse, 'subject');
|
|
83
91
|
assert.equal(presenceResponse.subject, mccoy.id);
|
|
84
92
|
}));
|
|
85
93
|
});
|
|
86
94
|
|
|
87
95
|
describe('#list()', () => {
|
|
88
|
-
it('returns an object with the status of all requested people', () =>
|
|
89
|
-
.then((presenceResponse) => {
|
|
96
|
+
it('returns an object with the status of all requested people', () =>
|
|
97
|
+
spock.webex.internal.presence.list([mccoy.id, spock.id]).then((presenceResponse) => {
|
|
90
98
|
assert.equal(presenceResponse.statusList.length, 2);
|
|
91
99
|
assert.property(presenceResponse.statusList[0], 'subject');
|
|
92
100
|
assert.equal(presenceResponse.statusList[0].subject, mccoy.id);
|
|
@@ -97,16 +105,18 @@ describe('plugin-presence', function () {
|
|
|
97
105
|
describe('batching of presence requests', () => {
|
|
98
106
|
let batchTestUsers;
|
|
99
107
|
|
|
100
|
-
beforeEach('create more users', () =>
|
|
101
|
-
.then((users) => {
|
|
108
|
+
beforeEach('create more users', () =>
|
|
109
|
+
testUsers.create({count: 6}).then((users) => {
|
|
102
110
|
batchTestUsers = users;
|
|
103
|
-
})
|
|
111
|
+
})
|
|
112
|
+
);
|
|
104
113
|
|
|
105
114
|
it('executes network requests for max limit', () => {
|
|
106
115
|
spock.webex.internal.presence.config.batcherMaxCalls = 2;
|
|
107
116
|
sinon.spy(spock.webex.internal.presence.batcher, 'submitHttpRequest');
|
|
108
117
|
|
|
109
|
-
return spock.webex.internal.presence
|
|
118
|
+
return spock.webex.internal.presence
|
|
119
|
+
.list(batchTestUsers.map((user) => user.id))
|
|
110
120
|
.then((presenceResponse) => {
|
|
111
121
|
assert.equal(presenceResponse.statusList.length, 6);
|
|
112
122
|
assert.calledThrice(spock.webex.internal.presence.batcher.submitHttpRequest);
|
|
@@ -117,61 +127,87 @@ describe('plugin-presence', function () {
|
|
|
117
127
|
});
|
|
118
128
|
|
|
119
129
|
describe('#subscribe', () => {
|
|
120
|
-
afterEach(
|
|
130
|
+
afterEach(
|
|
131
|
+
() =>
|
|
132
|
+
spock && spock.webex && spock.webex.internal.presence.unsubscribe([mccoy.id, spock.id])
|
|
133
|
+
);
|
|
121
134
|
|
|
122
|
-
it('subscribes to a person id and returns subscription status', () =>
|
|
123
|
-
.then((presenceResponse) => {
|
|
135
|
+
it('subscribes to a person id and returns subscription status', () =>
|
|
136
|
+
spock.webex.internal.presence.subscribe(mccoy.id).then((presenceResponse) => {
|
|
124
137
|
assert.property(presenceResponse, 'responses');
|
|
125
138
|
assert.equal(presenceResponse.responses.length, 1);
|
|
126
139
|
assert.equal(presenceResponse.responses[0].subject, mccoy.id);
|
|
127
140
|
}));
|
|
128
141
|
|
|
129
142
|
it('subscribes and returns subscription status of a list of people ids', () =>
|
|
130
|
-
spock.webex.internal.presence.subscribe([mccoy.id, spock.id])
|
|
131
|
-
.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}));
|
|
143
|
+
spock.webex.internal.presence.subscribe([mccoy.id, spock.id]).then((presenceResponse) => {
|
|
144
|
+
assert.property(presenceResponse, 'responses');
|
|
145
|
+
assert.equal(presenceResponse.responses.length, 2);
|
|
146
|
+
assert.equal(presenceResponse.responses[0].subject, mccoy.id);
|
|
147
|
+
assert.equal(presenceResponse.responses[1].subject, spock.id);
|
|
148
|
+
}));
|
|
137
149
|
|
|
138
150
|
// Note: The presence service no longer accepts setting status to "inactive".
|
|
139
151
|
// Inactivity is now determined by a "last active time" of greater than 10 minutes.
|
|
140
|
-
it(
|
|
141
|
-
spock.webex.internal.presence
|
|
152
|
+
it("should receive a mercury event for a subscribed person's change", () =>
|
|
153
|
+
spock.webex.internal.presence
|
|
154
|
+
.subscribe(mccoy.id)
|
|
142
155
|
// 'active' status
|
|
143
|
-
.then(() =>
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
156
|
+
.then(() =>
|
|
157
|
+
Promise.all([
|
|
158
|
+
expectEvent(
|
|
159
|
+
10000,
|
|
160
|
+
'event:apheleia.subscription_update',
|
|
161
|
+
spock.webex.internal.mercury,
|
|
162
|
+
'spock should get the presence active event'
|
|
163
|
+
),
|
|
164
|
+
mccoy.webex.internal.presence.setStatus('active', 1500),
|
|
165
|
+
])
|
|
166
|
+
)
|
|
167
|
+
.then(([event]) =>
|
|
168
|
+
assert.equal(
|
|
169
|
+
event.data.status,
|
|
170
|
+
'active',
|
|
171
|
+
'mccoy presence event status should be active'
|
|
172
|
+
)
|
|
173
|
+
)
|
|
148
174
|
// 'dnd' status
|
|
149
|
-
.then(() =>
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
175
|
+
.then(() =>
|
|
176
|
+
Promise.all([
|
|
177
|
+
expectEvent(
|
|
178
|
+
10000,
|
|
179
|
+
'event:apheleia.subscription_update',
|
|
180
|
+
spock.webex.internal.mercury,
|
|
181
|
+
'spock should get the presence dnd event'
|
|
182
|
+
),
|
|
183
|
+
mccoy.webex.internal.presence.setStatus('dnd', 1500),
|
|
184
|
+
])
|
|
185
|
+
)
|
|
186
|
+
.then(([event]) =>
|
|
187
|
+
assert.equal(event.data.status, 'dnd', 'mccoy presence event status should be dnd')
|
|
188
|
+
));
|
|
154
189
|
});
|
|
155
190
|
|
|
156
191
|
describe('#unsubscribe', () => {
|
|
157
192
|
it('unsubscribes to presence updates of a single person id', () =>
|
|
158
|
-
spock.webex.internal.presence
|
|
193
|
+
spock.webex.internal.presence
|
|
194
|
+
.unsubscribe(mccoy.id)
|
|
159
195
|
.then((res) => assert.statusCode(res, 200)));
|
|
160
196
|
|
|
161
197
|
it('unsubscribes to presence updates of a list of people ids', () =>
|
|
162
|
-
spock.webex.internal.presence
|
|
198
|
+
spock.webex.internal.presence
|
|
199
|
+
.unsubscribe([mccoy.id, spock.id])
|
|
163
200
|
.then((res) => assert.statusCode(res, 200)));
|
|
164
201
|
});
|
|
165
202
|
|
|
166
203
|
describe('#setStatus', () => {
|
|
167
204
|
it('sets the presence status of the current user', () =>
|
|
168
|
-
spock.webex.internal.presence.setStatus('dnd', 1500)
|
|
169
|
-
.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}));
|
|
205
|
+
spock.webex.internal.presence.setStatus('dnd', 1500).then((statusResponse) => {
|
|
206
|
+
assert.property(statusResponse, 'subject');
|
|
207
|
+
assert.property(statusResponse, 'status');
|
|
208
|
+
assert.equal(statusResponse.subject, spock.id);
|
|
209
|
+
assert.equal(statusResponse.status, 'dnd');
|
|
210
|
+
}));
|
|
175
211
|
});
|
|
176
212
|
});
|
|
177
213
|
});
|