@webex/internal-plugin-presence 2.59.2 → 2.59.3-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.
- package/.eslintrc.js +6 -6
- package/README.md +42 -42
- package/babel.config.js +3 -3
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/presence-batcher.js +42 -42
- package/dist/presence-batcher.js.map +1 -1
- package/dist/presence-worker.js +43 -43
- package/dist/presence-worker.js.map +1 -1
- package/dist/presence.js +75 -75
- package/dist/presence.js.map +1 -1
- package/jest.config.js +3 -3
- package/package.json +19 -18
- package/process +1 -1
- package/src/config.js +11 -11
- package/src/constants.js +19 -19
- package/src/index.js +41 -41
- package/src/presence-batcher.js +100 -100
- package/src/presence-worker.js +268 -268
- package/src/presence.js +262 -262
- package/test/integration/spec/presence.js +213 -213
- package/test/unit/spec/presence-worker.js +264 -264
- package/test/unit/spec/presence.js +68 -68
|
@@ -1,213 +1,213 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import '@webex/internal-plugin-mercury';
|
|
6
|
-
import '@webex/internal-plugin-presence';
|
|
7
|
-
|
|
8
|
-
import {assert} from '@webex/test-helper-chai';
|
|
9
|
-
import WebexCore from '@webex/webex-core';
|
|
10
|
-
import testUsers from '@webex/test-helper-test-users';
|
|
11
|
-
import {expectEvent} from '@webex/test-helper-mocha';
|
|
12
|
-
import sinon from 'sinon';
|
|
13
|
-
|
|
14
|
-
describe('plugin-presence', function () {
|
|
15
|
-
this.timeout(10000);
|
|
16
|
-
describe('Presence', () => {
|
|
17
|
-
let mccoy, spock;
|
|
18
|
-
|
|
19
|
-
beforeEach('create users', () =>
|
|
20
|
-
testUsers.create({count: 2}).then((users) => {
|
|
21
|
-
[spock, mccoy] = users;
|
|
22
|
-
spock.webex = new WebexCore({
|
|
23
|
-
credentials: {
|
|
24
|
-
authorization: users[0].token,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
mccoy.webex = new WebexCore({
|
|
28
|
-
credentials: {
|
|
29
|
-
authorization: users[1].token,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
beforeEach('register with wdm', () =>
|
|
36
|
-
Promise.all([spock.webex.internal.device.register(), mccoy.webex.internal.device.register()])
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
beforeEach('register spock with mercury', () => spock.webex.internal.mercury.connect());
|
|
40
|
-
|
|
41
|
-
afterEach('deregister spock with mercury', () => spock.webex.internal.mercury.disconnect());
|
|
42
|
-
|
|
43
|
-
describe('#enable()', () => {
|
|
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
|
-
}));
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('#disable()', () => {
|
|
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
|
-
}));
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('#isEnabled()', () => {
|
|
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
|
-
}));
|
|
77
|
-
|
|
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
|
-
}));
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('#get()', () => {
|
|
88
|
-
it("gets a person's status by id", () =>
|
|
89
|
-
spock.webex.internal.presence.get(mccoy.id).then((presenceResponse) => {
|
|
90
|
-
assert.property(presenceResponse, 'subject');
|
|
91
|
-
assert.equal(presenceResponse.subject, mccoy.id);
|
|
92
|
-
}));
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('#list()', () => {
|
|
96
|
-
it('returns an object with the status of all requested people', () =>
|
|
97
|
-
spock.webex.internal.presence.list([mccoy.id, spock.id]).then((presenceResponse) => {
|
|
98
|
-
assert.equal(presenceResponse.statusList.length, 2);
|
|
99
|
-
assert.property(presenceResponse.statusList[0], 'subject');
|
|
100
|
-
assert.equal(presenceResponse.statusList[0].subject, mccoy.id);
|
|
101
|
-
assert.property(presenceResponse.statusList[1], 'subject');
|
|
102
|
-
assert.equal(presenceResponse.statusList[1].subject, spock.id);
|
|
103
|
-
}));
|
|
104
|
-
|
|
105
|
-
describe('batching of presence requests', () => {
|
|
106
|
-
let batchTestUsers;
|
|
107
|
-
|
|
108
|
-
beforeEach('create more users', () =>
|
|
109
|
-
testUsers.create({count: 6}).then((users) => {
|
|
110
|
-
batchTestUsers = users;
|
|
111
|
-
})
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
it('executes network requests for max limit', () => {
|
|
115
|
-
spock.webex.internal.presence.config.batcherMaxCalls = 2;
|
|
116
|
-
sinon.spy(spock.webex.internal.presence.batcher, 'submitHttpRequest');
|
|
117
|
-
|
|
118
|
-
return spock.webex.internal.presence
|
|
119
|
-
.list(batchTestUsers.map((user) => user.id))
|
|
120
|
-
.then((presenceResponse) => {
|
|
121
|
-
assert.equal(presenceResponse.statusList.length, 6);
|
|
122
|
-
assert.calledThrice(spock.webex.internal.presence.batcher.submitHttpRequest);
|
|
123
|
-
spock.webex.internal.presence.batcher.submitHttpRequest.restore();
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe('#subscribe', () => {
|
|
130
|
-
afterEach(
|
|
131
|
-
() =>
|
|
132
|
-
spock && spock.webex && spock.webex.internal.presence.unsubscribe([mccoy.id, spock.id])
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
it('subscribes to a person id and returns subscription status', () =>
|
|
136
|
-
spock.webex.internal.presence.subscribe(mccoy.id).then((presenceResponse) => {
|
|
137
|
-
assert.property(presenceResponse, 'responses');
|
|
138
|
-
assert.equal(presenceResponse.responses.length, 1);
|
|
139
|
-
assert.equal(presenceResponse.responses[0].subject, mccoy.id);
|
|
140
|
-
}));
|
|
141
|
-
|
|
142
|
-
it('subscribes and returns subscription status of a list of people ids', () =>
|
|
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
|
-
}));
|
|
149
|
-
|
|
150
|
-
// Note: The presence service no longer accepts setting status to "inactive".
|
|
151
|
-
// Inactivity is now determined by a "last active time" of greater than 10 minutes.
|
|
152
|
-
it("should receive a mercury event for a subscribed person's change", () =>
|
|
153
|
-
spock.webex.internal.presence
|
|
154
|
-
.subscribe(mccoy.id)
|
|
155
|
-
// 'active' status
|
|
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
|
-
)
|
|
174
|
-
// 'dnd' status
|
|
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
|
-
));
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
describe('#unsubscribe', () => {
|
|
192
|
-
it('unsubscribes to presence updates of a single person id', () =>
|
|
193
|
-
spock.webex.internal.presence
|
|
194
|
-
.unsubscribe(mccoy.id)
|
|
195
|
-
.then((res) => assert.statusCode(res, 200)));
|
|
196
|
-
|
|
197
|
-
it('unsubscribes to presence updates of a list of people ids', () =>
|
|
198
|
-
spock.webex.internal.presence
|
|
199
|
-
.unsubscribe([mccoy.id, spock.id])
|
|
200
|
-
.then((res) => assert.statusCode(res, 200)));
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe('#setStatus', () => {
|
|
204
|
-
it('sets the presence status of the current user', () =>
|
|
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
|
-
}));
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
});
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import '@webex/internal-plugin-mercury';
|
|
6
|
+
import '@webex/internal-plugin-presence';
|
|
7
|
+
|
|
8
|
+
import {assert} from '@webex/test-helper-chai';
|
|
9
|
+
import WebexCore from '@webex/webex-core';
|
|
10
|
+
import testUsers from '@webex/test-helper-test-users';
|
|
11
|
+
import {expectEvent} from '@webex/test-helper-mocha';
|
|
12
|
+
import sinon from 'sinon';
|
|
13
|
+
|
|
14
|
+
describe('plugin-presence', function () {
|
|
15
|
+
this.timeout(10000);
|
|
16
|
+
describe('Presence', () => {
|
|
17
|
+
let mccoy, spock;
|
|
18
|
+
|
|
19
|
+
beforeEach('create users', () =>
|
|
20
|
+
testUsers.create({count: 2}).then((users) => {
|
|
21
|
+
[spock, mccoy] = users;
|
|
22
|
+
spock.webex = new WebexCore({
|
|
23
|
+
credentials: {
|
|
24
|
+
authorization: users[0].token,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
mccoy.webex = new WebexCore({
|
|
28
|
+
credentials: {
|
|
29
|
+
authorization: users[1].token,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
beforeEach('register with wdm', () =>
|
|
36
|
+
Promise.all([spock.webex.internal.device.register(), mccoy.webex.internal.device.register()])
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
beforeEach('register spock with mercury', () => spock.webex.internal.mercury.connect());
|
|
40
|
+
|
|
41
|
+
afterEach('deregister spock with mercury', () => spock.webex.internal.mercury.disconnect());
|
|
42
|
+
|
|
43
|
+
describe('#enable()', () => {
|
|
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
|
+
}));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('#disable()', () => {
|
|
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
|
+
}));
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('#isEnabled()', () => {
|
|
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
|
+
}));
|
|
77
|
+
|
|
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
|
+
}));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('#get()', () => {
|
|
88
|
+
it("gets a person's status by id", () =>
|
|
89
|
+
spock.webex.internal.presence.get(mccoy.id).then((presenceResponse) => {
|
|
90
|
+
assert.property(presenceResponse, 'subject');
|
|
91
|
+
assert.equal(presenceResponse.subject, mccoy.id);
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('#list()', () => {
|
|
96
|
+
it('returns an object with the status of all requested people', () =>
|
|
97
|
+
spock.webex.internal.presence.list([mccoy.id, spock.id]).then((presenceResponse) => {
|
|
98
|
+
assert.equal(presenceResponse.statusList.length, 2);
|
|
99
|
+
assert.property(presenceResponse.statusList[0], 'subject');
|
|
100
|
+
assert.equal(presenceResponse.statusList[0].subject, mccoy.id);
|
|
101
|
+
assert.property(presenceResponse.statusList[1], 'subject');
|
|
102
|
+
assert.equal(presenceResponse.statusList[1].subject, spock.id);
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
describe('batching of presence requests', () => {
|
|
106
|
+
let batchTestUsers;
|
|
107
|
+
|
|
108
|
+
beforeEach('create more users', () =>
|
|
109
|
+
testUsers.create({count: 6}).then((users) => {
|
|
110
|
+
batchTestUsers = users;
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
it('executes network requests for max limit', () => {
|
|
115
|
+
spock.webex.internal.presence.config.batcherMaxCalls = 2;
|
|
116
|
+
sinon.spy(spock.webex.internal.presence.batcher, 'submitHttpRequest');
|
|
117
|
+
|
|
118
|
+
return spock.webex.internal.presence
|
|
119
|
+
.list(batchTestUsers.map((user) => user.id))
|
|
120
|
+
.then((presenceResponse) => {
|
|
121
|
+
assert.equal(presenceResponse.statusList.length, 6);
|
|
122
|
+
assert.calledThrice(spock.webex.internal.presence.batcher.submitHttpRequest);
|
|
123
|
+
spock.webex.internal.presence.batcher.submitHttpRequest.restore();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('#subscribe', () => {
|
|
130
|
+
afterEach(
|
|
131
|
+
() =>
|
|
132
|
+
spock && spock.webex && spock.webex.internal.presence.unsubscribe([mccoy.id, spock.id])
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
it('subscribes to a person id and returns subscription status', () =>
|
|
136
|
+
spock.webex.internal.presence.subscribe(mccoy.id).then((presenceResponse) => {
|
|
137
|
+
assert.property(presenceResponse, 'responses');
|
|
138
|
+
assert.equal(presenceResponse.responses.length, 1);
|
|
139
|
+
assert.equal(presenceResponse.responses[0].subject, mccoy.id);
|
|
140
|
+
}));
|
|
141
|
+
|
|
142
|
+
it('subscribes and returns subscription status of a list of people ids', () =>
|
|
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
|
+
}));
|
|
149
|
+
|
|
150
|
+
// Note: The presence service no longer accepts setting status to "inactive".
|
|
151
|
+
// Inactivity is now determined by a "last active time" of greater than 10 minutes.
|
|
152
|
+
it("should receive a mercury event for a subscribed person's change", () =>
|
|
153
|
+
spock.webex.internal.presence
|
|
154
|
+
.subscribe(mccoy.id)
|
|
155
|
+
// 'active' status
|
|
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
|
+
)
|
|
174
|
+
// 'dnd' status
|
|
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
|
+
));
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe('#unsubscribe', () => {
|
|
192
|
+
it('unsubscribes to presence updates of a single person id', () =>
|
|
193
|
+
spock.webex.internal.presence
|
|
194
|
+
.unsubscribe(mccoy.id)
|
|
195
|
+
.then((res) => assert.statusCode(res, 200)));
|
|
196
|
+
|
|
197
|
+
it('unsubscribes to presence updates of a list of people ids', () =>
|
|
198
|
+
spock.webex.internal.presence
|
|
199
|
+
.unsubscribe([mccoy.id, spock.id])
|
|
200
|
+
.then((res) => assert.statusCode(res, 200)));
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('#setStatus', () => {
|
|
204
|
+
it('sets the presence status of the current user', () =>
|
|
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
|
+
}));
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|