sockethub 4.0.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/README.md +3 -3
- package/bin/sockethub +23 -19
- package/coverage/tmp/coverage-15699-1646422276150-0.json +1 -0
- package/dist/bootstrap/init.js +14 -4
- package/dist/bootstrap/init.js.map +1 -1
- package/dist/bootstrap/platforms.js +81 -69
- package/dist/common.js +10 -12
- package/dist/common.js.map +1 -1
- package/dist/config.js +4 -22
- package/dist/config.js.map +1 -1
- package/dist/crypto.js +7 -8
- package/dist/crypto.js.map +1 -1
- package/dist/janitor.js +14 -9
- package/dist/janitor.js.map +1 -1
- package/dist/middleware/create-activity-object.js +19 -0
- package/dist/middleware/create-activity-object.js.map +1 -0
- 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 +19 -0
- package/dist/middleware/store-credentials.js.map +1 -0
- package/dist/middleware/validate.js +77 -0
- package/dist/middleware/validate.js.map +1 -0
- package/dist/middleware/validate.test.data.js +321 -0
- package/dist/middleware/validate.test.data.js.map +1 -0
- package/dist/middleware.js +47 -49
- package/dist/middleware.js.map +1 -1
- package/dist/platform-instance.js +84 -66
- package/dist/platform-instance.js.map +1 -1
- package/dist/platform.js +50 -25
- package/dist/platform.js.map +1 -1
- package/dist/process-manager.js +7 -4
- package/dist/process-manager.js.map +1 -1
- package/dist/routes.js +9 -7
- package/dist/routes.js.map +1 -1
- package/dist/serve.js +3 -3
- package/dist/serve.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 +75 -58
- package/dist/sockethub.js.map +1 -1
- package/dist/store.js +17 -0
- package/dist/store.js.map +1 -0
- package/package.json +48 -44
- package/src/bootstrap/init.ts +16 -2
- package/src/bootstrap/platforms.js +14 -18
- package/src/common.test.ts +44 -33
- package/src/common.ts +9 -17
- package/src/config.test.ts +16 -38
- package/src/config.ts +1 -23
- package/src/crypto.test.ts +15 -17
- package/src/crypto.ts +4 -5
- package/src/janitor.ts +19 -12
- package/src/middleware/create-activity-object.test.ts +10 -0
- package/src/middleware/create-activity-object.ts +13 -0
- 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 +72 -0
- package/src/middleware/store-credentials.ts +16 -0
- package/src/{validate.d.ts → middleware/validate.d.ts} +0 -0
- package/src/middleware/validate.test.data.ts +320 -0
- package/src/middleware/validate.test.ts +47 -0
- package/src/middleware/validate.ts +49 -0
- package/src/middleware.test.ts +148 -0
- package/src/middleware.ts +46 -51
- package/src/platform-instance.test.ts +224 -196
- package/src/platform-instance.ts +74 -58
- package/src/platform.ts +44 -24
- package/src/process-manager.ts +7 -4
- package/src/routes.test.ts +32 -17
- package/src/routes.ts +8 -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 +96 -93
- package/src/store.test.ts +26 -0
- package/src/store.ts +17 -0
- package/tsconfig.json +8 -8
- package/views/examples/dummy.ejs +7 -7
- package/views/examples/feeds.ejs +10 -10
- package/views/examples/irc.ejs +65 -59
- package/views/examples/shared.js +31 -29
- package/views/examples/xmpp.ejs +49 -58
- package/webpack.minified.config.js +14 -0
- package/webpack.normal.config.js +14 -0
- package/coverage/clover.xml +0 -190
- package/coverage/coverage-final.json +0 -6
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/common.ts.html +0 -143
- package/coverage/lcov-report/config.ts.html +0 -359
- package/coverage/lcov-report/crypto.ts.html +0 -203
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -171
- package/coverage/lcov-report/platform-instance.ts.html +0 -740
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/routes.ts.html +0 -353
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov-report/src/common.ts.html +0 -143
- package/coverage/lcov-report/src/config.ts.html +0 -359
- package/coverage/lcov-report/src/crypto.ts.html +0 -182
- package/coverage/lcov-report/src/index.html +0 -156
- package/coverage/lcov-report/src/platform-instance.ts.html +0 -740
- package/coverage/lcov-report/src/routes/base.ts.html +0 -359
- package/coverage/lcov-report/src/routes/examples.ts.html +0 -311
- package/coverage/lcov-report/src/routes/index.html +0 -111
- package/coverage/lcov-report/src/services/http.ts.html +0 -239
- package/coverage/lcov-report/src/services/index.html +0 -111
- package/coverage/lcov-report/src/services/redis.ts.html +0 -140
- package/coverage/lcov-report/src/shared-resources.ts.html +0 -104
- package/coverage/lcov.info +0 -336
- package/coverage/tmp/coverage-70996-1620314182345-0.json +0 -1
- package/dist/bootstrap/platforms.js.map +0 -1
- package/dist/js/client.js +0 -177
- package/dist/js/client.js.map +0 -1
- package/dist/resource-manager.js +0 -66
- package/dist/resource-manager.js.map +0 -1
- package/dist/routes/base.js +0 -92
- package/dist/routes/base.js.map +0 -1
- package/dist/routes/examples.js +0 -93
- package/dist/routes/examples.js.map +0 -1
- package/dist/services/http.js +0 -68
- package/dist/services/http.js.map +0 -1
- package/dist/services/redis.js +0 -1
- package/dist/services/redis.js.map +0 -1
- package/dist/shared-resources.js +0 -11
- package/dist/shared-resources.js.map +0 -1
- package/dist/validate.js +0 -157
- package/dist/validate.js.map +0 -1
- package/jest.config.js +0 -18
- package/src/js/client.js +0 -190
- package/src/validate.ts +0 -147
- package/test/middleware-suite.js +0 -101
- package/test/validate-suite.js +0 -338
package/tsconfig.json
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
"module": "commonjs",
|
|
8
8
|
/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
|
9
9
|
"lib": ["esnext"], /* Specify library files to be included in the compilation. */
|
|
10
|
-
"allowJs":
|
|
10
|
+
"allowJs": false,
|
|
11
11
|
/* Allow javascript files to be compiled. */
|
|
12
|
-
//
|
|
12
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
13
13
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
14
14
|
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
15
15
|
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
// "removeComments": true, /* Do not emit comments to output. */
|
|
25
25
|
// "noEmit": true, /* Do not emit outputs. */
|
|
26
26
|
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
27
|
-
|
|
27
|
+
"downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
28
28
|
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
29
29
|
|
|
30
30
|
/* Strict Type-Checking Options */
|
|
31
|
-
//
|
|
31
|
+
// "strict": true, /* Enable all strict type-checking options. */
|
|
32
32
|
"noImplicitAny": false,
|
|
33
33
|
/* Raise error on expressions and declarations with an implied 'any' type. */
|
|
34
34
|
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
/* Module Resolution Options */
|
|
49
49
|
"moduleResolution": "node",
|
|
50
50
|
/* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
51
|
-
|
|
51
|
+
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
52
52
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
53
53
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
54
54
|
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
55
|
-
|
|
55
|
+
"types": ["mocha", "node"], /* Type declaration files to be included in compilation. */
|
|
56
56
|
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
57
57
|
"esModuleInterop": true,
|
|
58
58
|
/* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
61
61
|
|
|
62
62
|
/* Source Map Options */
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
"sourceRoot": "/", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
64
|
+
"mapRoot": "/", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
65
65
|
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
66
66
|
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
67
67
|
|
package/views/examples/dummy.ejs
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
</form>
|
|
21
21
|
|
|
22
22
|
<script src="<%= address %>jquery.js"></script>
|
|
23
|
-
<script src="<%= address %>
|
|
23
|
+
<script src="<%= address %>socket.io.js"></script>
|
|
24
24
|
<script src="<%= address %>activity-streams.min.js"></script>
|
|
25
25
|
<script src="<%= address %>sockethub-client.js"></script>
|
|
26
26
|
<script>
|
|
@@ -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
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
</form>
|
|
21
21
|
|
|
22
22
|
<script src="<%= address %>jquery.js"></script>
|
|
23
|
-
<script src="<%= address %>
|
|
23
|
+
<script src="<%= address %>socket.io.js"></script>
|
|
24
24
|
<script src="<%= address %>activity-streams.min.js"></script>
|
|
25
25
|
<script src="<%= address %>sockethub-client.js"></script>
|
|
26
26
|
<script>
|
|
@@ -55,35 +55,35 @@
|
|
|
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
|
|
|
76
76
|
console.log('sending message: ', msg);
|
|
77
|
-
sc.socket.emit('message', msg);
|
|
77
|
+
sc.socket.emit('message', msg, (data) => { console.log('CALLBACK', data); });
|
|
78
78
|
$('#m').val('');
|
|
79
79
|
return false;
|
|
80
80
|
});
|
|
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
|
@@ -50,14 +50,13 @@
|
|
|
50
50
|
</form>
|
|
51
51
|
|
|
52
52
|
<script src="<%= address %>jquery.js"></script>
|
|
53
|
-
<script src="<%= address %>
|
|
54
|
-
<script src="<%= address %>activity-streams.min.js"></script>
|
|
53
|
+
<script src="<%= address %>socket.io.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 {
|