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.
Files changed (140) hide show
  1. package/README.md +3 -3
  2. package/bin/sockethub +23 -19
  3. package/coverage/tmp/coverage-15699-1646422276150-0.json +1 -0
  4. package/dist/bootstrap/init.js +14 -4
  5. package/dist/bootstrap/init.js.map +1 -1
  6. package/dist/bootstrap/platforms.js +81 -69
  7. package/dist/common.js +10 -12
  8. package/dist/common.js.map +1 -1
  9. package/dist/config.js +4 -22
  10. package/dist/config.js.map +1 -1
  11. package/dist/crypto.js +7 -8
  12. package/dist/crypto.js.map +1 -1
  13. package/dist/janitor.js +14 -9
  14. package/dist/janitor.js.map +1 -1
  15. package/dist/middleware/create-activity-object.js +19 -0
  16. package/dist/middleware/create-activity-object.js.map +1 -0
  17. package/dist/middleware/expand-activity-stream.js +33 -0
  18. package/dist/middleware/expand-activity-stream.js.map +1 -0
  19. package/dist/middleware/expand-activity-stream.test.data.js +360 -0
  20. package/dist/middleware/expand-activity-stream.test.data.js.map +1 -0
  21. package/dist/middleware/store-credentials.js +19 -0
  22. package/dist/middleware/store-credentials.js.map +1 -0
  23. package/dist/middleware/validate.js +77 -0
  24. package/dist/middleware/validate.js.map +1 -0
  25. package/dist/middleware/validate.test.data.js +321 -0
  26. package/dist/middleware/validate.test.data.js.map +1 -0
  27. package/dist/middleware.js +47 -49
  28. package/dist/middleware.js.map +1 -1
  29. package/dist/platform-instance.js +84 -66
  30. package/dist/platform-instance.js.map +1 -1
  31. package/dist/platform.js +50 -25
  32. package/dist/platform.js.map +1 -1
  33. package/dist/process-manager.js +7 -4
  34. package/dist/process-manager.js.map +1 -1
  35. package/dist/routes.js +9 -7
  36. package/dist/routes.js.map +1 -1
  37. package/dist/serve.js +3 -3
  38. package/dist/serve.js.map +1 -1
  39. package/dist/sockethub-client.js +2604 -0
  40. package/dist/sockethub-client.js.map +1 -0
  41. package/dist/sockethub-client.min.js +2 -0
  42. package/dist/sockethub-client.min.js.LICENSE.txt +24 -0
  43. package/dist/sockethub.js +75 -58
  44. package/dist/sockethub.js.map +1 -1
  45. package/dist/store.js +17 -0
  46. package/dist/store.js.map +1 -0
  47. package/package.json +48 -44
  48. package/src/bootstrap/init.ts +16 -2
  49. package/src/bootstrap/platforms.js +14 -18
  50. package/src/common.test.ts +44 -33
  51. package/src/common.ts +9 -17
  52. package/src/config.test.ts +16 -38
  53. package/src/config.ts +1 -23
  54. package/src/crypto.test.ts +15 -17
  55. package/src/crypto.ts +4 -5
  56. package/src/janitor.ts +19 -12
  57. package/src/middleware/create-activity-object.test.ts +10 -0
  58. package/src/middleware/create-activity-object.ts +13 -0
  59. package/src/middleware/expand-activity-stream.test.data.ts +365 -0
  60. package/src/middleware/expand-activity-stream.test.ts +78 -0
  61. package/src/middleware/expand-activity-stream.ts +27 -0
  62. package/src/middleware/store-credentials.test.ts +72 -0
  63. package/src/middleware/store-credentials.ts +16 -0
  64. package/src/{validate.d.ts → middleware/validate.d.ts} +0 -0
  65. package/src/middleware/validate.test.data.ts +320 -0
  66. package/src/middleware/validate.test.ts +47 -0
  67. package/src/middleware/validate.ts +49 -0
  68. package/src/middleware.test.ts +148 -0
  69. package/src/middleware.ts +46 -51
  70. package/src/platform-instance.test.ts +224 -196
  71. package/src/platform-instance.ts +74 -58
  72. package/src/platform.ts +44 -24
  73. package/src/process-manager.ts +7 -4
  74. package/src/routes.test.ts +32 -17
  75. package/src/routes.ts +8 -6
  76. package/src/serve.ts +1 -1
  77. package/src/sockethub-client.test.ts +235 -0
  78. package/src/sockethub-client.ts +164 -0
  79. package/src/sockethub.ts +96 -93
  80. package/src/store.test.ts +26 -0
  81. package/src/store.ts +17 -0
  82. package/tsconfig.json +8 -8
  83. package/views/examples/dummy.ejs +7 -7
  84. package/views/examples/feeds.ejs +10 -10
  85. package/views/examples/irc.ejs +65 -59
  86. package/views/examples/shared.js +31 -29
  87. package/views/examples/xmpp.ejs +49 -58
  88. package/webpack.minified.config.js +14 -0
  89. package/webpack.normal.config.js +14 -0
  90. package/coverage/clover.xml +0 -190
  91. package/coverage/coverage-final.json +0 -6
  92. package/coverage/lcov-report/base.css +0 -224
  93. package/coverage/lcov-report/block-navigation.js +0 -79
  94. package/coverage/lcov-report/common.ts.html +0 -143
  95. package/coverage/lcov-report/config.ts.html +0 -359
  96. package/coverage/lcov-report/crypto.ts.html +0 -203
  97. package/coverage/lcov-report/favicon.png +0 -0
  98. package/coverage/lcov-report/index.html +0 -171
  99. package/coverage/lcov-report/platform-instance.ts.html +0 -740
  100. package/coverage/lcov-report/prettify.css +0 -1
  101. package/coverage/lcov-report/prettify.js +0 -2
  102. package/coverage/lcov-report/routes.ts.html +0 -353
  103. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  104. package/coverage/lcov-report/sorter.js +0 -170
  105. package/coverage/lcov-report/src/common.ts.html +0 -143
  106. package/coverage/lcov-report/src/config.ts.html +0 -359
  107. package/coverage/lcov-report/src/crypto.ts.html +0 -182
  108. package/coverage/lcov-report/src/index.html +0 -156
  109. package/coverage/lcov-report/src/platform-instance.ts.html +0 -740
  110. package/coverage/lcov-report/src/routes/base.ts.html +0 -359
  111. package/coverage/lcov-report/src/routes/examples.ts.html +0 -311
  112. package/coverage/lcov-report/src/routes/index.html +0 -111
  113. package/coverage/lcov-report/src/services/http.ts.html +0 -239
  114. package/coverage/lcov-report/src/services/index.html +0 -111
  115. package/coverage/lcov-report/src/services/redis.ts.html +0 -140
  116. package/coverage/lcov-report/src/shared-resources.ts.html +0 -104
  117. package/coverage/lcov.info +0 -336
  118. package/coverage/tmp/coverage-70996-1620314182345-0.json +0 -1
  119. package/dist/bootstrap/platforms.js.map +0 -1
  120. package/dist/js/client.js +0 -177
  121. package/dist/js/client.js.map +0 -1
  122. package/dist/resource-manager.js +0 -66
  123. package/dist/resource-manager.js.map +0 -1
  124. package/dist/routes/base.js +0 -92
  125. package/dist/routes/base.js.map +0 -1
  126. package/dist/routes/examples.js +0 -93
  127. package/dist/routes/examples.js.map +0 -1
  128. package/dist/services/http.js +0 -68
  129. package/dist/services/http.js.map +0 -1
  130. package/dist/services/redis.js +0 -1
  131. package/dist/services/redis.js.map +0 -1
  132. package/dist/shared-resources.js +0 -11
  133. package/dist/shared-resources.js.map +0 -1
  134. package/dist/validate.js +0 -157
  135. package/dist/validate.js.map +0 -1
  136. package/jest.config.js +0 -18
  137. package/src/js/client.js +0 -190
  138. package/src/validate.ts +0 -147
  139. package/test/middleware-suite.js +0 -101
  140. 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": true,
10
+ "allowJs": false,
11
11
  /* Allow javascript files to be compiled. */
12
- // "checkJs": true, /* Report errors in .js files. */
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
- "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
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
- // "strict": true, /* Enable all strict type-checking options. */
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
- "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
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
- "types": ["jest", "node"], /* Type declaration files to be included in compilation. */
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
- // "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. */
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
 
@@ -20,7 +20,7 @@
20
20
  </form>
21
21
 
22
22
  <script src="<%= address %>jquery.js"></script>
23
- <script src="<%= address %>sockethub/socket.io.js"></script>
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
- '@id': 'https://sockethub.org/examples/dummyUser',
34
- '@type': "person",
35
- displayName: "Sockethub Examples - Dummy User"
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.displayName + ': ' + msg.object.title));
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
- '@type': type,
78
+ 'type': type,
79
79
  actor: 'https://sockethub.org/examples/dummyUser',
80
80
  object: {
81
- '@type': 'message',
81
+ 'type': 'message',
82
82
  content: text
83
83
  }
84
84
  };
@@ -20,7 +20,7 @@
20
20
  </form>
21
21
 
22
22
  <script src="<%= address %>jquery.js"></script>
23
- <script src="<%= address %>sockethub/socket.io.js"></script>
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.displayName}</b>: ${msg.object.html}`));
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
- '@type': 'fetch',
65
+ 'type': 'fetch',
66
66
  actor: 'https://sockethub.org/examples/feeds',
67
67
  object: {
68
- '@type': 'parameters'
68
+ 'type': 'parameters'
69
69
  },
70
70
  target: {
71
- '@type': 'feed',
72
- '@id': $('#m').val()
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
- '@id': 'https://sockethub.org/examples/feeds',
85
- '@type': "website",
86
- displayName: "Sockethub Examples - Feeds"
84
+ 'id': 'https://sockethub.org/examples/feeds',
85
+ 'type': "website",
86
+ name: "Sockethub Examples - Feeds"
87
87
  });
88
88
  </script>
89
89
  </body>
@@ -50,14 +50,13 @@
50
50
  </form>
51
51
 
52
52
  <script src="<%= address %>jquery.js"></script>
53
- <script src="<%= address %>sockethub/socket.io.js"></script>
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.freenode.net';
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
- '@id': ircServer + '/' + target,
77
- '@type': "room",
78
- displayName: target
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
- '@id': target + '@' + ircServer,
84
- '@type': "person",
85
- displayName: target
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['@type'] = 'me';
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['@type'] = 'address';
100
- msg['@type'] = 'update';
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['@type'] = 'notice';
105
+ msg.object['type'] = 'notice';
107
106
  __normalizeTargetFromContent('/notice');
108
- msg.object.content = msg.object.content.substr(8 + object.target.displayName.length + 1);
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
- '@id': nick + '@' + ircServer,
122
- '@type': "person",
123
- displayName: nick,
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 + '@' + ircServer,
136
+ actor: nick,
140
137
  context: 'irc',
138
+ type: 'credentials',
141
139
  object: {
142
- '@type': 'credentials',
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
- // errors
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 ((typeof msg.object === 'object') &&
164
- (typeof msg.object.content === 'string')) {
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['@type'] === 'update') &&
167
- (msg.object['@type'] === 'address') &&
168
- (msg.actor.displayName === nick)) {
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.displayName);
168
+ __updateActor(msg.target.name);
171
169
  examplesShared.processIncomingMessage(msg);
172
- } else if (msg['@type'] === 'join') {
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 completed message ', msg)
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', (msg) => {
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
- '@type': 'send',
186
+ type: 'send',
192
187
  context: 'irc',
193
- actor: nick + '@' + ircServer,
188
+ actor: nick,
194
189
  object: {
195
- '@type': 'message',
190
+ type: 'message',
196
191
  content: $('#m').val()
197
192
  },
198
- target: ircServer + '/' + channel
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
- '@id': ircServer + '/' + channel.replace('#', ''),
215
- '@type': "room",
216
- displayName: channel
210
+ id: channel,
211
+ type: "room",
212
+ name: channel
217
213
  });
218
214
  debug('socket id: ', sc.socket.id);
219
215
 
220
- const msg = {
221
- '@type': 'join',
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 + '@' + ircServer,
224
- target: ircServer + '/' + channel.replace('#', '')
225
+ actor: nick,
226
+ target: channel
225
227
  };
226
228
 
227
- debug('sending message: ', msg);
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>
@@ -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['@id'];
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['@id']));
10
- actor.title = msg.actor['@id'];
11
- actor.href = msg.actor['@id'];
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['@id'] + '>' + msg.actor['@id'] + '</a>';
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['@id'] + ' is ' + msg.object.presence + ']' + status));
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.displayName || msg.actor['@id'] : msg['@type'];
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['@type'] === 'observe') {
34
- $('#messages').append($('<li>').text(` users in ${msg.actor.displayName}`))
35
- .append($('<li>').text(` [ ${msg.object.members.join(', ')} ]`));
36
- } else if ((msg['@type'] === 'pong') || (msg['@type'] === 'ping')) {
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['@type']} received from ${msg.actor['@id']} at ${msg.published}`));
39
- } else if ((msg['@type'] === 'update') && (msg.object['@type'] === 'address')) {
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.displayName} is now known as ${msg.target.displayName}`));
42
- } else if ((msg['@type'] === 'update') && (msg.object['@type'] === 'presence')) {
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['@type'] === 'add' || msg['@type'] === 'remove') &&
45
- (msg.object['@type'] === 'relationship')) {
46
- const action = msg['@type'] === 'add' ? 'set' : 'removed';
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.displayName} ${action} ${msg.object.relationship} of
50
+ `${msg.actor.name} ${action} ${msg.object.relationship} of
49
51
  ${msg.object.subject.role}`));
50
- } else if (msg['@type'] === 'join') {
52
+ } else if (msg.type === 'join') {
51
53
  $('#messages').append($('<li>').text(
52
- `${msg.actor.displayName} has joined ${msg.target.displayName}`));
53
- } else if ((msg['@type'] === 'announce') && (msg.actor['@type'] === 'service')) {
54
- $('#messages').append($('<li>').text(`connected to ${msg.actor['@id']}`));
55
- } else if (msg['@type'] === 'error') {
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['@type'] === 'close') {
59
+ } else if (msg.type === 'close') {
58
60
  console.log('close event received... offline.');
59
- } else if (msg.object && msg.object['@type'] === 'me') {
61
+ } else if (msg.object && msg.object.type === 'me') {
60
62
  $('#messages').append($('<li>').text(
61
- `* ${msg.actor.displayName} ${msg.object.content}`));
62
- } else if (msg.object && msg.object['@type'] === 'notice') {
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.displayName}: ${msg.object.content}`));
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 {