@sockethub/platform-xmpp 5.0.0-alpha.3 → 5.0.0-alpha.4
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/coverage/tmp/coverage-39286-1663949499396-0.json +1 -0
- package/package.json +8 -8
- package/src/incoming-handlers.data.js +7 -3
- package/src/incoming-handlers.js +13 -9
- package/src/incoming-handlers.test.js +0 -1
- package/src/index.js +13 -14
- package/coverage/tmp/coverage-93018-1649152156910-0.json +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sockethub/platform-xmpp",
|
|
3
3
|
"description": "A sockethub platform module implementing XMPP functionality",
|
|
4
|
-
"version": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.4",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Nick Jennings <nick@silverbucket.net>",
|
|
7
7
|
"license": "LGPL-3.0+",
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/sockethub/sockethub/tree/master/packages/platform-xmpp",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@xmpp/client": "^0.13.0"
|
|
26
|
-
"c8": "7.11.0"
|
|
25
|
+
"@xmpp/client": "^0.13.0"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
|
-
"@sockethub/schemas": "^3.0.0-alpha.
|
|
28
|
+
"@sockethub/schemas": "^3.0.0-alpha.4",
|
|
29
|
+
"c8": "7.12.0",
|
|
30
30
|
"chai": "4.3.6",
|
|
31
|
-
"eslint": "8.
|
|
31
|
+
"eslint": "8.23.1",
|
|
32
32
|
"jsdoc-to-markdown": "7.1.1",
|
|
33
|
-
"mocha": "
|
|
33
|
+
"mocha": "10.0.0",
|
|
34
34
|
"proxyquire": "2.1.3",
|
|
35
|
-
"sinon": "
|
|
35
|
+
"sinon": "14.0.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@sockethub/server": ">=5.0.0-alpha.2"
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"coverage": "c8 check-coverage --statements 85 --branches 80 --functions 70 --lines 85",
|
|
54
54
|
"doc": "jsdoc2md --no-gfm --heading-depth 1 src/index.js > API.md"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "c6d34ff44d2be479e4ea42c46da649612342a680"
|
|
57
57
|
}
|
|
@@ -78,11 +78,15 @@ module.exports = [
|
|
|
78
78
|
{
|
|
79
79
|
context: 'xmpp',
|
|
80
80
|
type: 'send',
|
|
81
|
-
published: '2021-04-17T18:50:
|
|
81
|
+
published: '2021-04-17T18:50:25.000Z',
|
|
82
82
|
actor: { type: 'person', id: 'radical@example.org/thinkpad' },
|
|
83
83
|
target: { type: 'person', id: 'user@jabber.org' },
|
|
84
|
-
object: {
|
|
85
|
-
|
|
84
|
+
object: {
|
|
85
|
+
type: 'message',
|
|
86
|
+
content: 'ohai',
|
|
87
|
+
id: 'purple9840c15f',
|
|
88
|
+
'xmpp:stanza-id': '123456789'
|
|
89
|
+
}
|
|
86
90
|
}
|
|
87
91
|
],
|
|
88
92
|
[
|
package/src/incoming-handlers.js
CHANGED
|
@@ -45,6 +45,14 @@ function getMessageReplaceId(stanza) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
function getPresence(stanza) {
|
|
49
|
+
if (stanza.getChild('show')) {
|
|
50
|
+
return stanza.getChild('show').getText();
|
|
51
|
+
} else {
|
|
52
|
+
return stanza.attrs.type === "unavailable" ? "offline" : "online";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
48
56
|
class IncomingHandlers {
|
|
49
57
|
constructor(session) {
|
|
50
58
|
this.session = session;
|
|
@@ -93,11 +101,7 @@ class IncomingHandlers {
|
|
|
93
101
|
if (stanza.getChildText('status')) {
|
|
94
102
|
obj.object.content = stanza.getChildText('status');
|
|
95
103
|
}
|
|
96
|
-
|
|
97
|
-
obj.object.presence = stanza.getChild('show').getText();
|
|
98
|
-
} else {
|
|
99
|
-
obj.object.presence = stanza.attrs.type === "unavailable" ? "offline" : "online";
|
|
100
|
-
}
|
|
104
|
+
obj.object.presence = getPresence(stanza);
|
|
101
105
|
if (stanza.attrs.to) {
|
|
102
106
|
obj.target = {id: stanza.attrs.to, type: 'person'};
|
|
103
107
|
} else {
|
|
@@ -168,7 +172,7 @@ class IncomingHandlers {
|
|
|
168
172
|
[activity.target['id'], activity.actor.name] = from.split('/');
|
|
169
173
|
}
|
|
170
174
|
|
|
171
|
-
if (timestamp) { activity.published = timestamp; }
|
|
175
|
+
if (timestamp) { activity.published = (new Date(timestamp)).toISOString(); }
|
|
172
176
|
|
|
173
177
|
this.session.sendToClient(activity);
|
|
174
178
|
}
|
|
@@ -211,7 +215,7 @@ class IncomingHandlers {
|
|
|
211
215
|
let members = [];
|
|
212
216
|
const entries = query.getChildren('item');
|
|
213
217
|
for (let e in entries) {
|
|
214
|
-
if (!
|
|
218
|
+
if (!Object.hasOwnProperty.call(entries, e)) {
|
|
215
219
|
continue;
|
|
216
220
|
}
|
|
217
221
|
members.push(entries[e].attrs.name);
|
|
@@ -262,7 +266,7 @@ class IncomingHandlers {
|
|
|
262
266
|
if (query) {
|
|
263
267
|
const entries = query.getChildren('item');
|
|
264
268
|
for (let e in entries) {
|
|
265
|
-
if (! entries.
|
|
269
|
+
if (! entries.hasOwn(e)) {
|
|
266
270
|
continue;
|
|
267
271
|
}
|
|
268
272
|
this.session.debug('STANZA ATTRS: ', entries[e].attrs);
|
|
@@ -275,7 +279,7 @@ class IncomingHandlers {
|
|
|
275
279
|
object: {
|
|
276
280
|
type: 'presence',
|
|
277
281
|
status: '',
|
|
278
|
-
presence:
|
|
282
|
+
presence: getPresence(entries[e])
|
|
279
283
|
}
|
|
280
284
|
});
|
|
281
285
|
} else if ((entries[e].attrs.subscription === 'from') &&
|
|
@@ -6,7 +6,6 @@ const parse = require('@xmpp/xml/lib/parse');
|
|
|
6
6
|
const schemas = require('@sockethub/schemas').default;
|
|
7
7
|
|
|
8
8
|
const stanzas = require('./incoming-handlers.data');
|
|
9
|
-
const {os} = require("yarn/lib/cli");
|
|
10
9
|
|
|
11
10
|
describe('Incoming handlers', () => {
|
|
12
11
|
describe('XML stanzas result in the expected AS objects', () => {
|
package/src/index.js
CHANGED
|
@@ -98,7 +98,7 @@ class XMPP {
|
|
|
98
98
|
requireCredentials: [ 'connect' ],
|
|
99
99
|
initialized: false
|
|
100
100
|
};
|
|
101
|
-
}
|
|
101
|
+
}
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Connect to the XMPP server.
|
|
@@ -129,9 +129,8 @@ class XMPP {
|
|
|
129
129
|
}
|
|
130
130
|
this.debug('connect called for ' + job.actor.id);
|
|
131
131
|
this.__client = client(utils.buildXmppCredentials(credentials));
|
|
132
|
-
this.__client.on("offline", (
|
|
132
|
+
this.__client.on("offline", () => {
|
|
133
133
|
this.debug('offline');
|
|
134
|
-
// console.log("offline", a);
|
|
135
134
|
});
|
|
136
135
|
|
|
137
136
|
this.__client.start().then(() => {
|
|
@@ -145,7 +144,7 @@ class XMPP {
|
|
|
145
144
|
delete this.__client;
|
|
146
145
|
return done(err);
|
|
147
146
|
});
|
|
148
|
-
}
|
|
147
|
+
}
|
|
149
148
|
|
|
150
149
|
/**
|
|
151
150
|
* Join a room, optionally defining a display name for that room.
|
|
@@ -180,7 +179,7 @@ class XMPP {
|
|
|
180
179
|
from: job.actor.id,
|
|
181
180
|
to: `${job.target.id}/${job.actor.name || id}`
|
|
182
181
|
})).then(done);
|
|
183
|
-
}
|
|
182
|
+
}
|
|
184
183
|
|
|
185
184
|
/**
|
|
186
185
|
* Leave a room
|
|
@@ -215,7 +214,7 @@ class XMPP {
|
|
|
215
214
|
to: `${job.target.id}/${job.actor.name}` || id,
|
|
216
215
|
type: 'unavailable'
|
|
217
216
|
})).then(done);
|
|
218
|
-
}
|
|
217
|
+
}
|
|
219
218
|
|
|
220
219
|
/**
|
|
221
220
|
* Send a message to a room or private conversation.
|
|
@@ -281,7 +280,7 @@ class XMPP {
|
|
|
281
280
|
}) : undefined
|
|
282
281
|
);
|
|
283
282
|
this.__client.send(message).then(done);
|
|
284
|
-
}
|
|
283
|
+
}
|
|
285
284
|
|
|
286
285
|
/**
|
|
287
286
|
* @description
|
|
@@ -326,7 +325,7 @@ class XMPP {
|
|
|
326
325
|
} else {
|
|
327
326
|
done(`unknown update object type: ${job.object.type}`);
|
|
328
327
|
}
|
|
329
|
-
}
|
|
328
|
+
}
|
|
330
329
|
|
|
331
330
|
/**
|
|
332
331
|
* @description
|
|
@@ -351,7 +350,7 @@ class XMPP {
|
|
|
351
350
|
'request-friend'(job, done) {
|
|
352
351
|
this.debug('request-friend() called for ' + job.actor.id);
|
|
353
352
|
this.__client.send(xml("presence", { type: "subscribe", to:job.target.id })).then(done);
|
|
354
|
-
}
|
|
353
|
+
}
|
|
355
354
|
|
|
356
355
|
/**
|
|
357
356
|
* @description
|
|
@@ -376,7 +375,7 @@ class XMPP {
|
|
|
376
375
|
'remove-friend'(job, done) {
|
|
377
376
|
this.debug('remove-friend() called for ' + job.actor.id);
|
|
378
377
|
this.__client.send(xml("presence", { type: "unsubscribe", to:job.target.id })).then(done);
|
|
379
|
-
}
|
|
378
|
+
}
|
|
380
379
|
|
|
381
380
|
/**
|
|
382
381
|
* @description
|
|
@@ -401,7 +400,7 @@ class XMPP {
|
|
|
401
400
|
'make-friend'(job, done) {
|
|
402
401
|
this.debug('make-friend() called for ' + job.actor.id);
|
|
403
402
|
this.__client.send(xml("presence", { type: "subscribe", to:job.target.id })).then(done);
|
|
404
|
-
}
|
|
403
|
+
}
|
|
405
404
|
|
|
406
405
|
/**
|
|
407
406
|
* Indicate an intent to query something (ie. get a list of users in a room).
|
|
@@ -459,7 +458,7 @@ class XMPP {
|
|
|
459
458
|
from: job.actor.id,
|
|
460
459
|
to: job.target.id
|
|
461
460
|
}, xml("query", {xmlns: 'http://jabber.org/protocol/disco#items'}))).then(done);
|
|
462
|
-
}
|
|
461
|
+
}
|
|
463
462
|
|
|
464
463
|
/**
|
|
465
464
|
* Called when it's time to close any connections or clean data before being wiped
|
|
@@ -471,7 +470,7 @@ class XMPP {
|
|
|
471
470
|
this.__forceDisconnect = true;
|
|
472
471
|
this.__client.stop();
|
|
473
472
|
done();
|
|
474
|
-
}
|
|
473
|
+
}
|
|
475
474
|
|
|
476
475
|
__registerHandlers() {
|
|
477
476
|
const ih = new IncomingHandlers(this);
|
|
@@ -479,7 +478,7 @@ class XMPP {
|
|
|
479
478
|
this.__client.on('error', ih.error.bind(ih));
|
|
480
479
|
this.__client.on('online', ih.online.bind(ih));
|
|
481
480
|
this.__client.on('stanza', ih.stanza.bind(ih));
|
|
482
|
-
}
|
|
481
|
+
}
|
|
483
482
|
}
|
|
484
483
|
|
|
485
484
|
module.exports = XMPP;
|