sockethub 4.1.0 → 5.0.0-alpha.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/bin/sockethub +23 -20
- package/coverage/tmp/coverage-15699-1646422276150-0.json +1 -0
- package/dist/bootstrap/init.js +1 -1
- package/dist/bootstrap/init.js.map +1 -1
- package/dist/bootstrap/platforms.js +14 -18
- package/dist/janitor.js +11 -5
- package/dist/janitor.js.map +1 -1
- package/dist/middleware/create-activity-object.js.map +1 -1
- package/dist/middleware/expand-activity-stream.js +33 -0
- package/dist/middleware/expand-activity-stream.js.map +1 -0
- package/dist/middleware/expand-activity-stream.test.data.js +360 -0
- package/dist/middleware/expand-activity-stream.test.data.js.map +1 -0
- package/dist/middleware/store-credentials.js +1 -1
- package/dist/middleware/store-credentials.js.map +1 -1
- package/dist/middleware/validate.js +30 -104
- package/dist/middleware/validate.js.map +1 -1
- package/dist/middleware/validate.test.data.js +151 -111
- package/dist/middleware/validate.test.data.js.map +1 -1
- package/dist/middleware.js +47 -77
- package/dist/middleware.js.map +1 -1
- package/dist/platform-instance.js +47 -54
- package/dist/platform-instance.js.map +1 -1
- package/dist/platform.js +29 -10
- package/dist/platform.js.map +1 -1
- package/dist/process-manager.js +5 -2
- package/dist/process-manager.js.map +1 -1
- package/dist/routes.js +3 -5
- package/dist/routes.js.map +1 -1
- package/dist/sockethub-client.js +2604 -0
- package/dist/sockethub-client.js.map +1 -0
- package/dist/sockethub-client.min.js +2 -0
- package/dist/sockethub-client.min.js.LICENSE.txt +24 -0
- package/dist/sockethub.js +67 -36
- package/dist/sockethub.js.map +1 -1
- package/package.json +40 -36
- package/src/bootstrap/init.ts +6 -2
- package/src/bootstrap/platforms.js +14 -18
- package/src/crypto.ts +3 -3
- package/src/janitor.ts +18 -10
- package/src/middleware/create-activity-object.ts +1 -2
- package/src/middleware/expand-activity-stream.test.data.ts +365 -0
- package/src/middleware/expand-activity-stream.test.ts +78 -0
- package/src/middleware/expand-activity-stream.ts +27 -0
- package/src/middleware/store-credentials.test.ts +12 -12
- package/src/middleware/store-credentials.ts +4 -4
- package/src/middleware/validate.test.data.ts +154 -120
- package/src/middleware/validate.test.ts +7 -10
- package/src/middleware/validate.ts +30 -123
- package/src/middleware.test.ts +59 -26
- package/src/middleware.ts +44 -76
- package/src/platform-instance.test.ts +8 -10
- package/src/platform-instance.ts +58 -57
- package/src/platform.ts +30 -14
- package/src/process-manager.ts +7 -4
- package/src/routes.ts +3 -6
- package/src/serve.ts +1 -1
- package/src/sockethub-client.test.ts +235 -0
- package/src/sockethub-client.ts +164 -0
- package/src/sockethub.ts +75 -68
- package/views/examples/dummy.ejs +6 -6
- package/views/examples/feeds.ejs +8 -8
- package/views/examples/irc.ejs +64 -58
- package/views/examples/shared.js +31 -29
- package/views/examples/xmpp.ejs +48 -57
- package/webpack.minified.config.js +14 -0
- package/webpack.normal.config.js +14 -0
- package/coverage/tmp/coverage-24546-1630615250805-0.json +0 -1
- package/dist/client/sockethub-client.js +0 -171
- package/dist/client/sockethub-client.js.map +0 -1
- package/src/client/sockethub-client.js +0 -178
- package/test/middleware-suite.js +0 -101
package/views/examples/dummy.ejs
CHANGED
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
|
|
31
31
|
// our user info
|
|
32
32
|
sc.ActivityStreams.Object.create({
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
|
|
33
|
+
'id': 'https://sockethub.org/examples/dummyUser',
|
|
34
|
+
'type': "person",
|
|
35
|
+
name: "Sockethub Examples - Dummy User"
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
// errors
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
function displayMessage(msg) {
|
|
44
44
|
msg.actor = sc.ActivityStreams.Object.get(msg.actor);
|
|
45
45
|
bdebug('displaying message: ', msg);
|
|
46
|
-
$('#messages').append($('<li>').text(msg.actor.
|
|
46
|
+
$('#messages').append($('<li>').text(msg.actor.name + ': ' + msg.object.title));
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
sc.socket.on('completed', function (msg) {
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
}
|
|
76
76
|
const msg = {
|
|
77
77
|
context: 'dummy',
|
|
78
|
-
'
|
|
78
|
+
'type': type,
|
|
79
79
|
actor: 'https://sockethub.org/examples/dummyUser',
|
|
80
80
|
object: {
|
|
81
|
-
'
|
|
81
|
+
'type': 'message',
|
|
82
82
|
content: text
|
|
83
83
|
}
|
|
84
84
|
};
|
package/views/examples/feeds.ejs
CHANGED
|
@@ -55,21 +55,21 @@
|
|
|
55
55
|
|
|
56
56
|
function displayMessage(msg) {
|
|
57
57
|
console.log('displaying message: ', msg);
|
|
58
|
-
$('#messages').append($('<li>').html(`<b>${msg.object.
|
|
58
|
+
$('#messages').append($('<li>').html(`<b>${msg.object.name}</b>: ${msg.object.html}`));
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// handler for user input, emit messages to sockethub server
|
|
62
62
|
$('form').submit(function () {
|
|
63
63
|
const msg = {
|
|
64
64
|
context: 'feeds',
|
|
65
|
-
'
|
|
65
|
+
'type': 'fetch',
|
|
66
66
|
actor: 'https://sockethub.org/examples/feeds',
|
|
67
67
|
object: {
|
|
68
|
-
'
|
|
68
|
+
'type': 'parameters'
|
|
69
69
|
},
|
|
70
70
|
target: {
|
|
71
|
-
'
|
|
72
|
-
'
|
|
71
|
+
'type': 'feed',
|
|
72
|
+
'id': $('#m').val()
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
|
|
@@ -81,9 +81,9 @@
|
|
|
81
81
|
|
|
82
82
|
// our feed actor info
|
|
83
83
|
sc.ActivityStreams.Object.create({
|
|
84
|
-
'
|
|
85
|
-
'
|
|
86
|
-
|
|
84
|
+
'id': 'https://sockethub.org/examples/feeds',
|
|
85
|
+
'type': "website",
|
|
86
|
+
name: "Sockethub Examples - Feeds"
|
|
87
87
|
});
|
|
88
88
|
</script>
|
|
89
89
|
</body>
|
package/views/examples/irc.ejs
CHANGED
|
@@ -51,13 +51,12 @@
|
|
|
51
51
|
|
|
52
52
|
<script src="<%= address %>jquery.js"></script>
|
|
53
53
|
<script src="<%= address %>socket.io.js"></script>
|
|
54
|
-
<script src="<%= address %>activity-streams.min.js"></script>
|
|
55
54
|
<script src="<%= address %>sockethub-client.js"></script>
|
|
56
55
|
<script src="<%= address %>examples/shared.js"></script>
|
|
57
56
|
<script>
|
|
58
57
|
debug = function (msg, obj) { console.log(msg, obj); };
|
|
59
58
|
const examplesShared = new ExamplesShared();
|
|
60
|
-
const ircServer = 'irc.
|
|
59
|
+
const ircServer = 'irc.libera.chat';
|
|
61
60
|
localStorage.debug = 'sockethub:*';
|
|
62
61
|
const sc = new SockethubClient(io('<%= address %>', { path: '/sockethub' }));
|
|
63
62
|
let channel = 'sockethub-test';
|
|
@@ -73,16 +72,16 @@
|
|
|
73
72
|
if (target.indexOf('#') === 0) {
|
|
74
73
|
msg.target = ircServer + '/' + target;
|
|
75
74
|
sc.ActivityStreams.Object.create({
|
|
76
|
-
'
|
|
77
|
-
'
|
|
78
|
-
|
|
75
|
+
'id': ircServer + '/' + target,
|
|
76
|
+
'type': "room",
|
|
77
|
+
name: target
|
|
79
78
|
});
|
|
80
79
|
} else {
|
|
81
80
|
msg.target = target + '@' + ircServer;
|
|
82
81
|
sc.ActivityStreams.Object.create({
|
|
83
|
-
'
|
|
84
|
-
'
|
|
85
|
-
|
|
82
|
+
'id': target + '@' + ircServer,
|
|
83
|
+
'type': "person",
|
|
84
|
+
name: target
|
|
86
85
|
});
|
|
87
86
|
}
|
|
88
87
|
}
|
|
@@ -93,21 +92,20 @@
|
|
|
93
92
|
if (msg.object.content.indexOf('/me') === 0) {
|
|
94
93
|
// show completed emotes from us
|
|
95
94
|
// rewrite as object to what the incoming objects should look like
|
|
96
|
-
msg.object['
|
|
95
|
+
msg.object['type'] = 'me';
|
|
97
96
|
msg.object.content = msg.object.content.substr(4);
|
|
98
97
|
} else if (msg.object.content.indexOf('/nick') === 0) {
|
|
99
|
-
msg.object['
|
|
100
|
-
msg['
|
|
98
|
+
msg.object['type'] = 'address';
|
|
99
|
+
msg['type'] = 'update';
|
|
101
100
|
__normalizeTargetFromContent('/nick');
|
|
102
101
|
delete msg.object.content;
|
|
103
102
|
} else if (msg.object.content.indexOf('/notice') === 0) {
|
|
104
103
|
// show completed emotes from us
|
|
105
104
|
// rewrite as object to what the incoming objects should look like
|
|
106
|
-
msg.object['
|
|
105
|
+
msg.object['type'] = 'notice';
|
|
107
106
|
__normalizeTargetFromContent('/notice');
|
|
108
|
-
msg.object.content = msg.object.content.substr(8 + object.target.
|
|
107
|
+
msg.object.content = msg.object.content.substr(8 + object.target.name.length + 1);
|
|
109
108
|
}
|
|
110
|
-
|
|
111
109
|
}
|
|
112
110
|
return msg;
|
|
113
111
|
}
|
|
@@ -118,9 +116,9 @@
|
|
|
118
116
|
// our irc user info
|
|
119
117
|
nick = _nick; // set global nick
|
|
120
118
|
sc.ActivityStreams.Object.create({
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
id: nick,
|
|
120
|
+
type: "person",
|
|
121
|
+
name: nick,
|
|
124
122
|
url: "http://sockethub.org",
|
|
125
123
|
image: {
|
|
126
124
|
url: "http://example.org/image.jpg",
|
|
@@ -131,76 +129,73 @@
|
|
|
131
129
|
});
|
|
132
130
|
__updateCredentials();
|
|
133
131
|
}
|
|
134
|
-
__updateActor(nick);
|
|
135
132
|
|
|
136
133
|
function __updateCredentials() {
|
|
137
134
|
// sending irc credentials to sockethub server
|
|
138
135
|
const credentials = {
|
|
139
|
-
actor: nick
|
|
136
|
+
actor: nick,
|
|
140
137
|
context: 'irc',
|
|
138
|
+
type: 'credentials',
|
|
141
139
|
object: {
|
|
142
|
-
|
|
140
|
+
type: 'credentials',
|
|
143
141
|
nick: nick,
|
|
144
142
|
server: ircServer,
|
|
145
143
|
secure: true
|
|
146
144
|
}
|
|
147
145
|
};
|
|
148
146
|
debug('sending credentials: ', credentials);
|
|
149
|
-
sc.socket.emit('credentials', credentials)
|
|
147
|
+
sc.socket.emit('credentials', credentials, (err) => {
|
|
148
|
+
if (err) { console.log('failed to set credentials ', err); }
|
|
149
|
+
else { console.log('credentials set'); }
|
|
150
|
+
});
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
|
|
153
|
-
sc.socket.on('failed', function (msg) {
|
|
154
|
-
debug('failed ', msg);
|
|
155
|
-
$('#messages').append($('<li>').text(msg.error));
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
sc.socket.on('completed', function (msg) {
|
|
153
|
+
function handleMessage(msg) {
|
|
159
154
|
msg = sc.ActivityStreams.Stream(msg);
|
|
160
|
-
debug('completed ', msg);
|
|
161
|
-
|
|
162
155
|
msg = __normalizeMessage(msg);
|
|
163
|
-
if (
|
|
164
|
-
|
|
156
|
+
if (msg.error) {
|
|
157
|
+
debug('error', msg);
|
|
158
|
+
$('#messages').append($('<li>').text(msg.error));
|
|
159
|
+
// } else if (msg.type === 'connect') {
|
|
160
|
+
// __updateActor(nick);
|
|
161
|
+
} else if ((typeof msg.object === 'object') &&
|
|
162
|
+
(typeof msg.object.content === 'string')) {
|
|
165
163
|
examplesShared.processIncomingMessage(msg);
|
|
166
|
-
} else if ((msg
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
} else if ((msg.type === 'update') &&
|
|
165
|
+
(msg.object.type === 'address') &&
|
|
166
|
+
(msg.actor.name === nick)) {
|
|
169
167
|
// our nick has been updated
|
|
170
|
-
__updateActor(msg.target.
|
|
168
|
+
__updateActor(msg.target.name);
|
|
171
169
|
examplesShared.processIncomingMessage(msg);
|
|
172
|
-
} else if (msg
|
|
170
|
+
} else if (msg.type === 'join') {
|
|
173
171
|
$('.modal').css('display', 'none');
|
|
174
172
|
$('input#m').prop('disabled', false);
|
|
175
173
|
$('button#send').prop('disabled', false);
|
|
176
174
|
} else {
|
|
177
|
-
debug('nothing to do for
|
|
175
|
+
debug('nothing to do for message ', msg);
|
|
176
|
+
examplesShared.processIncomingMessage(msg);
|
|
178
177
|
}
|
|
179
|
-
}
|
|
178
|
+
}
|
|
180
179
|
|
|
181
180
|
// handle incoming messages from the sockethub server
|
|
182
|
-
sc.socket.on('message',
|
|
183
|
-
msg = sc.ActivityStreams.Stream(msg);
|
|
184
|
-
debug('processing message: ', msg);
|
|
185
|
-
examplesShared.processIncomingMessage(msg);
|
|
186
|
-
});
|
|
181
|
+
sc.socket.on('message', handleMessage);
|
|
187
182
|
|
|
188
183
|
// handler for user input, emit messages to sockethub server
|
|
189
184
|
$('#chat').submit(function () {
|
|
190
185
|
let msg = {
|
|
191
|
-
|
|
186
|
+
type: 'send',
|
|
192
187
|
context: 'irc',
|
|
193
|
-
actor: nick
|
|
188
|
+
actor: nick,
|
|
194
189
|
object: {
|
|
195
|
-
|
|
190
|
+
type: 'message',
|
|
196
191
|
content: $('#m').val()
|
|
197
192
|
},
|
|
198
|
-
target:
|
|
193
|
+
target: channel
|
|
199
194
|
};
|
|
200
195
|
|
|
201
196
|
msg = __normalizeMessage(msg);
|
|
202
197
|
debug('sending message: ', msg);
|
|
203
|
-
sc.socket.emit('message', msg);
|
|
198
|
+
sc.socket.emit('message', msg, handleMessage);
|
|
204
199
|
$('#m').val('');
|
|
205
200
|
return false;
|
|
206
201
|
});
|
|
@@ -209,23 +204,34 @@
|
|
|
209
204
|
$('#join').click(function () {
|
|
210
205
|
channel = $('#j').val();
|
|
211
206
|
|
|
207
|
+
__updateActor(nick);
|
|
212
208
|
// the irc chatroom we're connecting to
|
|
213
209
|
sc.ActivityStreams.Object.create({
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
210
|
+
id: channel,
|
|
211
|
+
type: "room",
|
|
212
|
+
name: channel
|
|
217
213
|
});
|
|
218
214
|
debug('socket id: ', sc.socket.id);
|
|
219
215
|
|
|
220
|
-
const
|
|
221
|
-
|
|
216
|
+
const connect = {
|
|
217
|
+
type: 'connect',
|
|
218
|
+
context: 'irc',
|
|
219
|
+
actor: nick,
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const join = {
|
|
223
|
+
type: 'join',
|
|
222
224
|
context: 'irc',
|
|
223
|
-
actor: nick
|
|
224
|
-
target:
|
|
225
|
+
actor: nick,
|
|
226
|
+
target: channel
|
|
225
227
|
};
|
|
226
228
|
|
|
227
|
-
debug('sending
|
|
228
|
-
sc.socket.emit('message', msg)
|
|
229
|
+
debug('sending connect: ', connect);
|
|
230
|
+
sc.socket.emit('message', connect, (msg) => {
|
|
231
|
+
handleMessage(msg);
|
|
232
|
+
debug('sending join: ', join);
|
|
233
|
+
sc.socket.emit('message', join, handleMessage);
|
|
234
|
+
});
|
|
229
235
|
return false;
|
|
230
236
|
});
|
|
231
237
|
</script>
|
package/views/examples/shared.js
CHANGED
|
@@ -3,23 +3,23 @@ function ExamplesShared() {}
|
|
|
3
3
|
|
|
4
4
|
ExamplesShared.prototype.__displayPresenceUpdate = function (msg) {
|
|
5
5
|
const status = (msg.object.status) ? ': ' + msg.object.status : '';
|
|
6
|
-
let actor = msg.actor
|
|
6
|
+
let actor = msg.actor.id;
|
|
7
7
|
if (msg.object.presence !== 'offline') {
|
|
8
8
|
actor = document.createElement('a');
|
|
9
|
-
actor.appendChild(document.createTextNode(msg.actor
|
|
10
|
-
actor.title = msg.actor
|
|
11
|
-
actor.href = msg.actor
|
|
9
|
+
actor.appendChild(document.createTextNode(msg.actor.id));
|
|
10
|
+
actor.title = msg.actor.id;
|
|
11
|
+
actor.href = msg.actor.id;
|
|
12
12
|
$('#messages').append(actor);
|
|
13
|
-
// actor = '<a class="actor" href="' + msg.actor
|
|
13
|
+
// actor = '<a class="actor" href="' + msg.actor.id + '>' + msg.actor.id + '</a>';
|
|
14
14
|
}
|
|
15
15
|
$('#messages')
|
|
16
16
|
.append($('<li>').text(
|
|
17
|
-
'[ ' + msg.actor
|
|
17
|
+
'[ ' + msg.actor.id + ' is ' + msg.object.presence + ']' + status));
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
ExamplesShared.prototype.__displayMessageContent = function (msg) {
|
|
21
21
|
const name = (typeof msg.actor === 'object') ?
|
|
22
|
-
msg.actor.
|
|
22
|
+
msg.actor.name || msg.actor.id : msg.type;
|
|
23
23
|
$('#messages').append($('<li>').text(name + ': ' + msg.object.content));
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -30,38 +30,40 @@ ExamplesShared.prototype.__displayUnknownContent = function (msg) {
|
|
|
30
30
|
|
|
31
31
|
ExamplesShared.prototype.processIncomingMessage = function (msg) {
|
|
32
32
|
console.log('incoming message: ', msg);
|
|
33
|
-
if (msg
|
|
34
|
-
|
|
35
|
-
.append($('<li>').text(`
|
|
36
|
-
|
|
33
|
+
if (msg.type === 'query') {
|
|
34
|
+
if (msg.object.members) {
|
|
35
|
+
$('#messages').append($('<li>').text(` users in ${msg.actor.name}`))
|
|
36
|
+
.append($('<li>').text(` [ ${msg.object.members.join(', ')} ]`));
|
|
37
|
+
}
|
|
38
|
+
} else if ((msg.type === 'pong') || (msg.type === 'ping')) {
|
|
37
39
|
$('#messages').append($('<li>').text(
|
|
38
|
-
`${msg
|
|
39
|
-
} else if ((msg
|
|
40
|
+
`${msg.type} received from ${msg.actor.id} at ${msg.published}`));
|
|
41
|
+
} else if ((msg.type === 'update') && (msg.object.type === 'address')) {
|
|
40
42
|
$('#messages').append($('<li>').text(
|
|
41
|
-
`${msg.actor.
|
|
42
|
-
} else if ((msg
|
|
43
|
+
`${msg.actor.name} is now known as ${msg.target.name}`));
|
|
44
|
+
} else if ((msg.type === 'update') && (msg.object.type === 'presence')) {
|
|
43
45
|
this.__displayPresenceUpdate(msg);
|
|
44
|
-
} else if ((msg
|
|
45
|
-
(msg.object
|
|
46
|
-
const action = msg
|
|
46
|
+
} else if ((msg.type === 'add' || msg.type === 'remove') &&
|
|
47
|
+
(msg.object.type === 'relationship')) {
|
|
48
|
+
const action = msg.type === 'add' ? 'set' : 'removed';
|
|
47
49
|
$('#messages').append($('<li>').text(
|
|
48
|
-
`${msg.actor.
|
|
50
|
+
`${msg.actor.name} ${action} ${msg.object.relationship} of
|
|
49
51
|
${msg.object.subject.role}`));
|
|
50
|
-
} else if (msg
|
|
52
|
+
} else if (msg.type === 'join') {
|
|
51
53
|
$('#messages').append($('<li>').text(
|
|
52
|
-
`${msg.actor.
|
|
53
|
-
} else if ((msg
|
|
54
|
-
$('#messages').append($('<li>').text(`connected to ${msg.actor
|
|
55
|
-
} else if (msg
|
|
54
|
+
`${msg.actor.name} has joined ${msg.target.name}`));
|
|
55
|
+
} else if ((msg.type === 'announce') && (msg.actor.type === 'service')) {
|
|
56
|
+
$('#messages').append($('<li>').text(`connected to ${msg.actor.id}`));
|
|
57
|
+
} else if (msg.type === 'error') {
|
|
56
58
|
console.log('error received: ', msg);
|
|
57
|
-
} else if (msg
|
|
59
|
+
} else if (msg.type === 'close') {
|
|
58
60
|
console.log('close event received... offline.');
|
|
59
|
-
} else if (msg.object && msg.object
|
|
61
|
+
} else if (msg.object && msg.object.type === 'me') {
|
|
60
62
|
$('#messages').append($('<li>').text(
|
|
61
|
-
`* ${msg.actor.
|
|
62
|
-
} else if (msg.object && msg.object
|
|
63
|
+
`* ${msg.actor.name} ${msg.object.content}`));
|
|
64
|
+
} else if (msg.object && msg.object.type === 'notice') {
|
|
63
65
|
$('#messages').append($(
|
|
64
|
-
'<li>').text(`NOTICE from ${msg.actor.
|
|
66
|
+
'<li>').text(`NOTICE from ${msg.actor.name}: ${msg.object.content}`));
|
|
65
67
|
} else if (msg.object && msg.object.content) {
|
|
66
68
|
this.__displayMessageContent(msg);
|
|
67
69
|
} else {
|
package/views/examples/xmpp.ejs
CHANGED
|
@@ -40,10 +40,8 @@
|
|
|
40
40
|
<div class="modal">
|
|
41
41
|
<h3>Click `Join` to connect to the XMPP server.</h3>
|
|
42
42
|
<form id="intro" action="">
|
|
43
|
-
<input id="
|
|
43
|
+
<input id="userAddress" autocomplete="off" value="username@jabber.org"><button class="invis" disabled> </button>
|
|
44
44
|
<input id="password" type="password" autocomplete="off" value="password"><button class="invis" disabled> </button>
|
|
45
|
-
<input id="server" autocomplete="off" value="jabber.org"><button class="invis" disabled> </button>
|
|
46
|
-
<input id="port" type="number" autocomplete="off" value="5222"><button class="invis" disabled> </button>
|
|
47
45
|
<input id="resource" autocomplete="off" value="SockethubExample" disabled><button id="join">Join</button>
|
|
48
46
|
</form>
|
|
49
47
|
</div>
|
|
@@ -55,7 +53,6 @@
|
|
|
55
53
|
|
|
56
54
|
<script src="<%= address %>jquery.js"></script>
|
|
57
55
|
<script src="<%= address %>socket.io.js"></script>
|
|
58
|
-
<script src="<%= address %>activity-streams.min.js"></script>
|
|
59
56
|
<script src="<%= address %>sockethub-client.js"></script>
|
|
60
57
|
<script src="<%= address %>examples/shared.js"></script>
|
|
61
58
|
|
|
@@ -64,11 +61,9 @@
|
|
|
64
61
|
const examplesShared = new ExamplesShared();
|
|
65
62
|
localStorage.debug = 'sockethub:*';
|
|
66
63
|
let config = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
username: 'username',
|
|
64
|
+
type: 'credentials',
|
|
65
|
+
userAddress: 'username@jabber.org',
|
|
70
66
|
password: '123456',
|
|
71
|
-
port: 5222,
|
|
72
67
|
resource: 'Home'
|
|
73
68
|
};
|
|
74
69
|
let actorString = '';
|
|
@@ -79,16 +74,12 @@
|
|
|
79
74
|
function __updateActor(username) {
|
|
80
75
|
console.log('updating actor object for: ' + username);
|
|
81
76
|
// our xmpp user info
|
|
82
|
-
config.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
sc.ActivityStreams.Object.create({
|
|
89
|
-
'@id': actorString,
|
|
90
|
-
'@type': "person",
|
|
91
|
-
displayName: new URL('http://' + username).username,
|
|
77
|
+
config.userAddress = username; // set global userAddress
|
|
78
|
+
actorString = config.userAddress + '/' + config.resource;
|
|
79
|
+
const asObject = {
|
|
80
|
+
id: actorString,
|
|
81
|
+
type: "person",
|
|
82
|
+
name: new URL('http://' + username).username,
|
|
92
83
|
url: "http://sockethub.org",
|
|
93
84
|
image: {
|
|
94
85
|
url: "http://example.org/image.jpg",
|
|
@@ -96,39 +87,26 @@
|
|
|
96
87
|
width: 250,
|
|
97
88
|
height: 250
|
|
98
89
|
}
|
|
99
|
-
}
|
|
90
|
+
};
|
|
91
|
+
console.log('creating activity stream object ', asObject);
|
|
92
|
+
sc.ActivityStreams.Object.create(asObject);
|
|
100
93
|
}
|
|
101
94
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
sc.socket.on('completed', function (msg) {
|
|
109
|
-
msg = sc.ActivityStreams.Stream(msg);
|
|
110
|
-
debug('received completed job: ', msg);
|
|
111
|
-
|
|
112
|
-
// msg = __normalizeMessage(msg);
|
|
113
|
-
if ((typeof msg.object === 'object') &&
|
|
114
|
-
(typeof msg.object.content === 'string')) {
|
|
115
|
-
if (msg.object['@type'] === 'message') {
|
|
116
|
-
examplesShared.processIncomingMessage(msg);
|
|
117
|
-
}
|
|
118
|
-
} else if ((msg['@type'] === 'update') &&
|
|
119
|
-
(msg.object['@type'] === 'address') &&
|
|
120
|
-
(msg.actor.displayName === nick)) {
|
|
121
|
-
// our nick has been updated
|
|
122
|
-
__updateActor(msg.target.displayName);
|
|
123
|
-
} else if (msg['@type'] === 'connect') {
|
|
95
|
+
function handleMessage(msg) {
|
|
96
|
+
if (msg.error) {
|
|
97
|
+
debug('received error: ', msg);
|
|
98
|
+
console.error(msg.error);
|
|
99
|
+
} else if (msg['type'] === 'connect') {
|
|
124
100
|
$('.modal').css('display', 'none');
|
|
101
|
+
} else if (msg['type'] === 'join') {
|
|
125
102
|
$('input#m').prop('disabled', false);
|
|
126
103
|
$('button#send').prop('disabled', false);
|
|
104
|
+
} else {
|
|
105
|
+
examplesShared.processIncomingMessage(msg);
|
|
127
106
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
107
|
+
}
|
|
130
108
|
// handle incoming messages from the sockethub server
|
|
131
|
-
sc.socket.on('message',
|
|
109
|
+
sc.socket.on('message', handleMessage);
|
|
132
110
|
|
|
133
111
|
$('.actor').click(function (e) {
|
|
134
112
|
e.preventDefault();
|
|
@@ -141,24 +119,27 @@
|
|
|
141
119
|
const input = $('#m').val();
|
|
142
120
|
const [target, text_message] = input.split(':');
|
|
143
121
|
|
|
144
|
-
if ((!
|
|
145
|
-
console.log(
|
|
122
|
+
if ((!target || !text_message)) {
|
|
123
|
+
console.log(
|
|
124
|
+
'unable to send message without target specified ' +
|
|
125
|
+
'[room@server.org: hello world]: ',
|
|
126
|
+
target, text_message, input);
|
|
127
|
+
return false;
|
|
146
128
|
}
|
|
147
129
|
const msg = {
|
|
148
|
-
|
|
130
|
+
type: 'send',
|
|
149
131
|
context: 'xmpp',
|
|
150
132
|
actor: actorString,
|
|
151
133
|
object: {
|
|
152
|
-
|
|
134
|
+
type: 'message',
|
|
153
135
|
content: text_message
|
|
154
136
|
},
|
|
155
137
|
target: target
|
|
156
138
|
};
|
|
157
139
|
|
|
158
140
|
console.log('[normalize?] sending ', msg);
|
|
159
|
-
// msg = __normalizeMessage(msg);
|
|
160
141
|
debug('sending message: ', msg);
|
|
161
|
-
sc.socket.emit('message', msg);
|
|
142
|
+
sc.socket.emit('message', msg, handleMessage);
|
|
162
143
|
$('#m').val('');
|
|
163
144
|
return false;
|
|
164
145
|
});
|
|
@@ -166,32 +147,42 @@
|
|
|
166
147
|
// handler for user input, emit messages to sockethub server
|
|
167
148
|
$('#join').click(function (e) {
|
|
168
149
|
e.preventDefault();
|
|
169
|
-
config.
|
|
150
|
+
config.userAddress = $('#userAddress').val();
|
|
170
151
|
config.password = $('#password').val();
|
|
171
|
-
config.server = $('#server').val();
|
|
172
|
-
config.port = parseInt($('#port').val(), 0);
|
|
173
152
|
config.resource = $('#resource').val();
|
|
174
153
|
|
|
175
|
-
__updateActor(config.
|
|
154
|
+
__updateActor(config.userAddress);
|
|
176
155
|
|
|
177
156
|
setTimeout(function () {
|
|
178
157
|
// sending irc credentials to sockethub server
|
|
179
158
|
const credentials = {
|
|
180
159
|
actor: actorString,
|
|
160
|
+
type: 'credentials',
|
|
181
161
|
context: 'xmpp',
|
|
182
162
|
object: config
|
|
183
163
|
};
|
|
184
164
|
debug('sending credentials: ', credentials);
|
|
185
|
-
sc.socket.emit('credentials', credentials)
|
|
165
|
+
sc.socket.emit('credentials', credentials, (err) => {
|
|
166
|
+
if (err) {
|
|
167
|
+
console.error('failed to create credentials: ', err);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
186
170
|
|
|
187
171
|
const msg = {
|
|
188
|
-
|
|
172
|
+
type: 'connect',
|
|
189
173
|
context: 'xmpp',
|
|
190
174
|
actor: actorString
|
|
191
175
|
};
|
|
192
176
|
|
|
193
177
|
debug('sending message: ', msg);
|
|
194
|
-
sc.socket.emit('message', msg);
|
|
178
|
+
sc.socket.emit('message', msg, handleMessage);
|
|
179
|
+
msg.type = 'join';
|
|
180
|
+
msg.target = {
|
|
181
|
+
type: 'room',
|
|
182
|
+
id: 'kosmos-random@kosmos.chat'
|
|
183
|
+
};
|
|
184
|
+
debug('sending message: ', msg);
|
|
185
|
+
sc.socket.emit('message', msg, handleMessage);
|
|
195
186
|
}, 100);
|
|
196
187
|
return false;
|
|
197
188
|
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
entry: './dist/sockethub-client.js',
|
|
5
|
+
mode: "production",
|
|
6
|
+
optimization: {
|
|
7
|
+
minimize: true
|
|
8
|
+
},
|
|
9
|
+
output: {
|
|
10
|
+
filename: './dist/sockethub-client.min.js',
|
|
11
|
+
path: path.resolve(__dirname, './'),
|
|
12
|
+
libraryTarget: 'umd'
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
entry: './dist/sockethub-client.js',
|
|
5
|
+
mode: "production",
|
|
6
|
+
optimization: {
|
|
7
|
+
minimize: false
|
|
8
|
+
},
|
|
9
|
+
output: {
|
|
10
|
+
filename: './dist/sockethub-client.js',
|
|
11
|
+
path: path.resolve(__dirname, './'),
|
|
12
|
+
libraryTarget: 'umd'
|
|
13
|
+
}
|
|
14
|
+
};
|