@sockethub/server 5.0.0-alpha.3 → 5.0.0-alpha.6

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 (127) hide show
  1. package/README.md +54 -60
  2. package/bin/sockethub +4 -3
  3. package/package.json +42 -60
  4. package/res/socket.io.js +4908 -0
  5. package/res/sockethub-client.js +602 -0
  6. package/res/sockethub-client.min.js +19 -0
  7. package/sockethub.config.example.json +2 -3
  8. package/src/bootstrap/init.d.ts +20 -7
  9. package/src/bootstrap/init.test.ts +211 -0
  10. package/src/bootstrap/init.ts +152 -75
  11. package/src/bootstrap/load-platforms.ts +151 -0
  12. package/src/config.test.ts +27 -22
  13. package/src/config.ts +82 -78
  14. package/src/defaults.json +24 -16
  15. package/src/index.ts +67 -27
  16. package/src/janitor.test.ts +211 -0
  17. package/src/janitor.ts +145 -77
  18. package/src/listener.ts +151 -57
  19. package/src/middleware/create-activity-object.test.ts +28 -8
  20. package/src/middleware/create-activity-object.ts +17 -8
  21. package/src/middleware/expand-activity-stream.test.data.ts +332 -346
  22. package/src/middleware/expand-activity-stream.test.ts +65 -66
  23. package/src/middleware/expand-activity-stream.ts +29 -19
  24. package/src/middleware/store-credentials.test.ts +74 -62
  25. package/src/middleware/store-credentials.ts +15 -15
  26. package/src/middleware/validate.test.data.ts +240 -242
  27. package/src/middleware/validate.test.ts +39 -78
  28. package/src/middleware/validate.ts +63 -39
  29. package/src/middleware.test.ts +168 -138
  30. package/src/middleware.ts +62 -43
  31. package/src/platform-instance.test.ts +507 -213
  32. package/src/platform-instance.ts +337 -219
  33. package/src/platform.test.ts +375 -0
  34. package/src/platform.ts +306 -139
  35. package/src/process-manager.ts +75 -51
  36. package/src/routes.test.ts +43 -89
  37. package/src/routes.ts +40 -77
  38. package/src/sentry.test.ts +106 -0
  39. package/src/sentry.ts +19 -0
  40. package/src/sockethub.ts +186 -153
  41. package/src/util.ts +5 -0
  42. package/coverage/tmp/coverage-93126-1649152190997-0.json +0 -1
  43. package/dist/bootstrap/init.d.ts +0 -18
  44. package/dist/bootstrap/init.js +0 -63
  45. package/dist/bootstrap/init.js.map +0 -1
  46. package/dist/bootstrap/platforms.js +0 -75
  47. package/dist/common.d.ts +0 -3
  48. package/dist/common.js +0 -20
  49. package/dist/common.js.map +0 -1
  50. package/dist/config.d.ts +0 -6
  51. package/dist/config.js +0 -102
  52. package/dist/config.js.map +0 -1
  53. package/dist/crypto.d.ts +0 -10
  54. package/dist/crypto.js +0 -38
  55. package/dist/crypto.js.map +0 -1
  56. package/dist/defaults.json +0 -28
  57. package/dist/index.d.ts +0 -2
  58. package/dist/index.js +0 -25
  59. package/dist/index.js.map +0 -1
  60. package/dist/janitor.d.ts +0 -15
  61. package/dist/janitor.js +0 -89
  62. package/dist/janitor.js.map +0 -1
  63. package/dist/listener.d.ts +0 -28
  64. package/dist/listener.js +0 -91
  65. package/dist/listener.js.map +0 -1
  66. package/dist/middleware/create-activity-object.d.ts +0 -6
  67. package/dist/middleware/create-activity-object.js +0 -19
  68. package/dist/middleware/create-activity-object.js.map +0 -1
  69. package/dist/middleware/expand-activity-stream.d.ts +0 -2
  70. package/dist/middleware/expand-activity-stream.js +0 -33
  71. package/dist/middleware/expand-activity-stream.js.map +0 -1
  72. package/dist/middleware/expand-activity-stream.test.data.d.ts +0 -480
  73. package/dist/middleware/expand-activity-stream.test.data.js +0 -360
  74. package/dist/middleware/expand-activity-stream.test.data.js.map +0 -1
  75. package/dist/middleware/store-credentials.d.ts +0 -3
  76. package/dist/middleware/store-credentials.js +0 -19
  77. package/dist/middleware/store-credentials.js.map +0 -1
  78. package/dist/middleware/validate.d.ts +0 -2
  79. package/dist/middleware/validate.js +0 -58
  80. package/dist/middleware/validate.js.map +0 -1
  81. package/dist/middleware/validate.test.data.d.ts +0 -532
  82. package/dist/middleware/validate.test.data.js +0 -263
  83. package/dist/middleware/validate.test.data.js.map +0 -1
  84. package/dist/middleware.d.ts +0 -10
  85. package/dist/middleware.js +0 -54
  86. package/dist/middleware.js.map +0 -1
  87. package/dist/platform-instance.d.ts +0 -77
  88. package/dist/platform-instance.js +0 -211
  89. package/dist/platform-instance.js.map +0 -1
  90. package/dist/platform.d.ts +0 -6
  91. package/dist/platform.js +0 -187
  92. package/dist/platform.js.map +0 -1
  93. package/dist/process-manager.d.ts +0 -11
  94. package/dist/process-manager.js +0 -78
  95. package/dist/process-manager.js.map +0 -1
  96. package/dist/routes.d.ts +0 -13
  97. package/dist/routes.js +0 -83
  98. package/dist/routes.js.map +0 -1
  99. package/dist/sockethub.d.ts +0 -39
  100. package/dist/sockethub.js +0 -119
  101. package/dist/sockethub.js.map +0 -1
  102. package/dist/store.d.ts +0 -5
  103. package/dist/store.js +0 -17
  104. package/dist/store.js.map +0 -1
  105. package/src/bootstrap/platforms.js +0 -75
  106. package/src/common.test.ts +0 -54
  107. package/src/common.ts +0 -14
  108. package/src/config.d.ts +0 -2
  109. package/src/crypto.d.ts +0 -5
  110. package/src/crypto.test.ts +0 -41
  111. package/src/crypto.ts +0 -41
  112. package/src/janitor.d.ts +0 -8
  113. package/src/middleware/validate.d.ts +0 -1
  114. package/src/middleware.d.ts +0 -21
  115. package/src/sockethub.d.ts +0 -1
  116. package/src/store.test.ts +0 -28
  117. package/src/store.ts +0 -17
  118. package/test/init-suite.js +0 -41
  119. package/test/queue.functional.test.js +0 -0
  120. package/test/sockethub-suite.js +0 -25
  121. package/tsconfig.json +0 -18
  122. package/views/examples/dummy.ejs +0 -93
  123. package/views/examples/feeds.ejs +0 -90
  124. package/views/examples/irc.ejs +0 -239
  125. package/views/examples/shared.js +0 -72
  126. package/views/examples/xmpp.ejs +0 -191
  127. package/views/index.ejs +0 -17
@@ -1,75 +0,0 @@
1
- /**
2
- * bootstrap/platforms.js
3
- *
4
- * A Singleton responsible for finding and loading all valid Sockethub
5
- * platforms, and whitelisting or blacklisting (or neither) based on the
6
- * config.
7
- */
8
- const debug = require('debug'),
9
- schemas = require('@sockethub/schemas').default;
10
-
11
- const log = debug('sockethub:server:bootstrap:platforms');
12
-
13
- log('loading platforms');
14
-
15
- // if the platform schema lists valid types it implements (essentially methods/verbs for
16
- // Sockethub to call) then add it to the supported types list.
17
- function platformListsSupportedTypes(p) {
18
- return ((p.schema.messages.properties) && (p.schema.messages.properties.type) &&
19
- (p.schema.messages.properties.type.enum) &&
20
- (p.schema.messages.properties.type.enum.length > 0));
21
- }
22
-
23
- module.exports = function platformLoad(platformsList, requireModule) {
24
- if (!requireModule) {
25
- requireModule = require;
26
- }
27
- // load platforms from config.platforms
28
- const platforms = new Map();
29
-
30
- if (platformsList.length <= 0) {
31
- throw new Error('No platforms defined. Please check your sockethub.config.json');
32
- }
33
-
34
- for (let moduleName of platformsList) {
35
- log(`loading ${moduleName}`);
36
- // try to load platform
37
- // eslint-disable-next-line security-node/detect-non-literal-require-calls
38
- const P = requireModule(moduleName);
39
- const p = new P();
40
- let types = [];
41
-
42
- const err = schemas.validatePlatformSchema(p.schema);
43
- if (err) {
44
- throw new Error(`${moduleName} ${err}`);
45
- } else if (typeof p.config !== 'object') {
46
- throw new Error(
47
- `${moduleName} platform must have a config property that is an object.`);
48
- } else {
49
- if (p.schema.credentials) {
50
- // register the platforms credentials schema
51
- types.push('credentials');
52
- } else {
53
- p.config.noCredentials = true;
54
- }
55
- }
56
-
57
- if (platformListsSupportedTypes(p)) {
58
- types = [...types, ...p.schema.messages.properties.type.enum];
59
- }
60
-
61
- const platformName = p.schema.name;
62
- platforms.set(platformName, {
63
- id: platformName,
64
- moduleName: moduleName,
65
- config: p.config,
66
- schemas: {
67
- credentials: p.schema.credentials || {},
68
- messages: p.schema.messages || {}
69
- },
70
- version: p.schema.version,
71
- types: types
72
- });
73
- }
74
- return platforms;
75
- };
@@ -1,54 +0,0 @@
1
- import proxyquire from 'proxyquire';
2
- import { expect } from 'chai';
3
- import * as sinon from 'sinon';
4
-
5
- import { decryptJobData, getPlatformId } from './common';
6
- import crypto from './crypto';
7
-
8
- proxyquire.noPreserveCache();
9
- proxyquire.noCallThru();
10
-
11
- describe("getPlatformId", () => {
12
- let cryptoHashStub: any;
13
-
14
- beforeEach(() => {
15
- cryptoHashStub = sinon.stub(crypto, 'hash');
16
- cryptoHashStub.returnsArg(0);
17
- proxyquire('./common', { crypto: { hash: cryptoHashStub }});
18
- });
19
-
20
- afterEach(() => {
21
- cryptoHashStub.restore();
22
- });
23
-
24
- it('generates platform hash', () => {
25
- expect(getPlatformId('foo')).to.be.equal('foo');
26
- sinon.assert.calledOnce(cryptoHashStub);
27
- sinon.assert.calledWith(cryptoHashStub, 'foo');
28
- });
29
- it('generates platform + actor hash', () => {
30
- expect(getPlatformId('foo', 'bar')).to.be.equal('foobar');
31
- sinon.assert.calledOnce(cryptoHashStub);
32
- sinon.assert.calledWith(cryptoHashStub, 'foobar');
33
- });
34
- });
35
-
36
- describe("decryptJobData", () => {
37
- let cryptoDecryptStub: any;
38
-
39
- beforeEach(() => {
40
- cryptoDecryptStub = sinon.stub(crypto, 'decrypt');
41
- cryptoDecryptStub.returnsArg(0);
42
- proxyquire('./common', { crypto: { hash: cryptoDecryptStub }});
43
- });
44
-
45
- afterEach(() => {
46
- cryptoDecryptStub.restore();
47
- });
48
-
49
- it("decrypts and returns expected object", () => {
50
- const jobData = {data:{title:"foo", msg:'encryptedjobdata', sessionId:'foobar'}};
51
- const secret = 'secretstring';
52
- expect(decryptJobData(jobData, secret)).to.be.eql(jobData.data);
53
- });
54
- });
package/src/common.ts DELETED
@@ -1,14 +0,0 @@
1
- import crypto from "./crypto";
2
- import { JobDataDecrypted, JobEncrypted } from "./sockethub";
3
-
4
- export function getPlatformId(platform: string, actor?: string): string {
5
- return actor ? crypto.hash(platform + actor) : crypto.hash(platform);
6
- }
7
-
8
- export function decryptJobData(job: JobEncrypted, secret: string): JobDataDecrypted {
9
- return {
10
- title: job.data.title,
11
- msg: crypto.decrypt(job.data.msg, secret),
12
- sessionId: job.data.sessionId
13
- };
14
- }
package/src/config.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare let config: any;
2
- export default config;
package/src/crypto.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare const crypto: {
2
- encrypt: (json: any, secret: any) => string;
3
- decrypt: (string: any, secret: any) => any;
4
- };
5
- export default crypto;
@@ -1,41 +0,0 @@
1
- import { expect } from 'chai';
2
- import proxyquire from 'proxyquire';
3
-
4
- const crypto = proxyquire('./crypto', {
5
- 'crypto': {
6
- randomBytes: () => Buffer.alloc(16)
7
- }
8
- }).default;
9
-
10
- const secret = 'a test secret.. that is 16 x 2..';
11
- const data = {'foo': 'bar'};
12
- const encryptedData = "00000000000000000000000000000000:0543ec94d863fbf4b7a19b48e69d9317";
13
-
14
- describe('crypto', () => {
15
- it('encrypts', () => {
16
- expect(crypto.encrypt(data, secret)).to.be.equal(encryptedData);
17
- });
18
- it('decrypts', () => {
19
- expect(crypto.decrypt(encryptedData, secret)).to.eql(data);
20
- });
21
- it('hashes', () => {
22
- expect(crypto.hash('foobar')).to.be.equal('8843d7f');
23
- });
24
- it('randTokens 8', () => {
25
- const token = crypto.randToken(8);
26
- expect(token.length).to.be.equal(8);
27
- });
28
- it('randTokens 16', () => {
29
- const token = crypto.randToken(16);
30
- expect(token.length).to.be.equal(16);
31
- });
32
- it('randTokens 32', () => {
33
- const token = crypto.randToken(32);
34
- expect(token.length).to.be.equal(32);
35
- });
36
- it('randTokens 33+ will fail', () => {
37
- expect(() => {
38
- crypto.randToken(33);
39
- }).to.throw();
40
- });
41
- });
package/src/crypto.ts DELETED
@@ -1,41 +0,0 @@
1
- import { randomBytes, createCipheriv, createDecipheriv, createHash } from 'crypto';
2
- import { IActivityStream } from "@sockethub/schemas";
3
-
4
- const ALGORITHM = 'aes-256-cbc',
5
- IV_LENGTH = 16; // For AES, this is always 16
6
-
7
- class Crypto {
8
- constructor() {}
9
- encrypt(json: IActivityStream, secret: string): string {
10
- const iv = randomBytes(IV_LENGTH);
11
- const cipher = createCipheriv(ALGORITHM, Buffer.from(secret), iv);
12
- let encrypted = cipher.update(JSON.stringify(json));
13
-
14
- encrypted = Buffer.concat([encrypted, cipher.final()]);
15
- return iv.toString('hex') + ':' + encrypted.toString('hex');
16
- }
17
- decrypt(text: string, secret: string): IActivityStream {
18
- let parts = text.split(':');
19
- const iv = Buffer.from(parts.shift(), 'hex');
20
- const encryptedText = Buffer.from(parts.join(':'), 'hex');
21
- const decipher = createDecipheriv(ALGORITHM, Buffer.from(secret), iv);
22
- let decrypted = decipher.update(encryptedText);
23
- decrypted = Buffer.concat([decrypted, decipher.final()]);
24
- return JSON.parse(decrypted.toString());
25
- }
26
- hash(text: string): string {
27
- const shasum = createHash('sha1');
28
- shasum.update(text);
29
- return shasum.digest('hex').substring(0, 7);
30
- }
31
- randToken(len: number): string {
32
- if (len > 32) {
33
- throw new Error(`crypto.randToken supports a length param of up to 32, ${len} given`);
34
- }
35
- const buf = randomBytes(len);
36
- return buf.toString('hex').substring(0, len);
37
- }
38
- }
39
-
40
- const crypto = new Crypto();
41
- export default crypto;
package/src/janitor.d.ts DELETED
@@ -1,8 +0,0 @@
1
- declare function janitorCycle(): void;
2
- declare const janitor: {
3
- start: typeof janitorCycle;
4
- alreadyCalled: boolean;
5
- cycleCount: number;
6
- reportCount: number;
7
- };
8
- export default janitor;
@@ -1 +0,0 @@
1
- export default function validate(type: any): (next: any, msg: any) => void;
@@ -1,21 +0,0 @@
1
- /**
2
- * a very simple middleware handler
3
- *
4
- * When initialized, provide a function which will be called if there were any failures during
5
- * the execution of functions along the chain.
6
- *
7
- * Use middleware.chain, passing in a list of functions to call in order. It then returns
8
- * a function which accepts the message from the input. That function then will
9
- * call each of the originally passed in functions, in order, with a `next` callback as
10
- * the first parameter, and any number of originating parameters.
11
- *
12
- * As one middleware function is done, they call `next` with the first argument `true`
13
- * (succeeded, continue) any parameters to pass along.
14
- *
15
- * If any of the middleware function calls the `next` handler with `false` as the first param, the
16
- * execution of the function chain is halted, and the failure callback is called. Again, any
17
- * number of params passed after the `false` will be passed to the failure callback.
18
- *
19
- */
20
- declare function Middleware(errorHandler: any): void;
21
- export default Middleware;
@@ -1 +0,0 @@
1
- export {};
package/src/store.test.ts DELETED
@@ -1,28 +0,0 @@
1
- import proxyquire from 'proxyquire';
2
- import { expect } from 'chai';
3
- import * as sinon from 'sinon';
4
-
5
- proxyquire.noPreserveCache();
6
- proxyquire.noCallThru();
7
-
8
- const MockSecureStore = sinon.fake();
9
-
10
- const StoreMod = proxyquire('./store', {
11
- 'secure-store-redis': MockSecureStore
12
- });
13
-
14
- const getSessionStore = StoreMod.getSessionStore;
15
-
16
- describe('getSessionStore', () => {
17
- it('returns a valid Store object', () => {
18
- const store = getSessionStore('a parent id', 'a parent secret',
19
- 'a session id', 'a session secret');
20
- sinon.assert.calledOnce(MockSecureStore);
21
- sinon.assert.calledWith(MockSecureStore, {
22
- namespace: 'sockethub:a parent id:session:a session id:store',
23
- secret: 'a parent secreta session secret',
24
- redis: { host: '127.0.0.1', port: 6379 }
25
- });
26
- expect(typeof store).to.equal('object');
27
- });
28
- });
package/src/store.ts DELETED
@@ -1,17 +0,0 @@
1
- import SecureStore from 'secure-store-redis';
2
-
3
- import config from "./config";
4
-
5
- export interface ISecureStoreInstance {
6
- save(id: string, obj: any, cb: Function);
7
- get(id: string, cb: Function);
8
- }
9
-
10
- export function getSessionStore(parentId: string, parentSecret: string,
11
- sessionId: string, sessionSecret: string): ISecureStoreInstance {
12
- return new SecureStore({
13
- namespace: 'sockethub:' + parentId + ':session:' + sessionId + ':store',
14
- secret: parentSecret + sessionSecret,
15
- redis: config.get('redis')
16
- });
17
- }
@@ -1,41 +0,0 @@
1
- if (typeof define !== 'function') {
2
- let define = require('amdefine')(module);
3
- }
4
- define(['require'], function (require) {
5
- return [
6
- {
7
- desc: 'dist/bootstrap/init',
8
- abortOnFail: true,
9
- setup: function (env, test) {
10
- env.init = require('../dist/bootstrap/init').default;
11
- test.assertType(env.init, 'object');
12
- },
13
- tests: [
14
- {
15
- desc: 'platforms',
16
- run: function (env, test) {
17
- test.assertTypeAnd(env.init.platforms, 'object');
18
- test.assert(env.init.platforms.has('irc'), true);
19
- }
20
- }
21
- ]
22
- },
23
- {
24
- desc: 'nconf should have defaults set',
25
- setup: function (env, test) {
26
- env.nconf = require('nconf');
27
- test.assertType(env.nconf.get, 'function');
28
- },
29
- tests: [
30
- {
31
- desc: 'whitelist and blacklist',
32
- run: function (env, test) {
33
- console.log('whitelist: ', typeof require('nconf').get('platforms:whitelist'));
34
- test.assertTypeAnd(require('nconf').get('platforms:whitelist'), 'array');
35
- test.assertType(require('nconf').get('platforms:blacklist'), 'array');
36
- }
37
- }
38
- ]
39
- }
40
- ];
41
- });
File without changes
@@ -1,25 +0,0 @@
1
- if (typeof define !== 'function') {
2
- let define = require('amdefine')(module);
3
- }
4
- define(['require', './.'], function (require, Sockethub) {
5
- return [
6
- {
7
- desc: 'src/sockethub',
8
- abortOnFail: true,
9
- beforeEach: function () {
10
- this.env.sockethub = new Sockethub.default();
11
- this.done();
12
- },
13
- tests: [
14
- {
15
- desc: 'boot',
16
- run: function () {
17
- this.env.sockethub.boot();
18
- this.assertTypeAnd(this.env.sockethub.platforms, 'object');
19
- this.assertType(this.env.sockethub.platforms.size, 'number');
20
- }
21
- }
22
- ]
23
- }
24
- ];
25
- });
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "allowJs": false,
5
- "outDir": "dist",
6
- "rootDir": "src",
7
- "baseUrl": "/",
8
- "sourceMap": true,
9
- "sourceRoot": "/",
10
- "mapRoot": "/",
11
- },
12
- "include": [
13
- "src"
14
- ],
15
- "exclude": [
16
- "**/*.test.ts"
17
- ]
18
- }
@@ -1,93 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>Sockethub Example Dummy</title>
5
- <style>
6
- * { margin: 0; padding: 0; box-sizing: border-box; }
7
- body { font: 13px Helvetica, Arial; }
8
- form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
9
- form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
10
- form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
11
- #messages { list-style-type: none; margin: 0; padding: 0; }
12
- #messages li { padding: 5px 10px; }
13
- #messages li:nth-child(odd) { background: #eee; }
14
- </style>
15
- </head>
16
- <body>
17
- <ul id="messages"></ul>
18
- <form action="">
19
- <input id="m" autocomplete="off" /><button>Send</button>
20
- </form>
21
-
22
- <script src="<%= address %>jquery.js"></script>
23
- <script src="<%= address %>socket.io.js"></script>
24
- <script src="<%= address %>activity-streams.min.js"></script>
25
- <script src="<%= address %>sockethub-client.js"></script>
26
- <script>
27
- bdebug = function (msg, obj) { console.log(msg, obj); };
28
- localStorage.debug = '<%= debug_scope %>';
29
- var sc = new SockethubClient(io('<%= address %>', { path: '/sockethub' }));
30
-
31
- // our user info
32
- sc.ActivityStreams.Object.create({
33
- 'id': 'https://sockethub.org/examples/dummyUser',
34
- 'type': "person",
35
- name: "Sockethub Examples - Dummy User"
36
- });
37
-
38
- // errors
39
- sc.socket.on('failure', function (msg) {
40
- bdebug('received failure: ', msg);
41
- });
42
-
43
- function displayMessage(msg) {
44
- msg.actor = sc.ActivityStreams.Object.get(msg.actor);
45
- bdebug('displaying message: ', msg);
46
- $('#messages').append($('<li>').text(msg.actor.name + ': ' + msg.object.title));
47
- }
48
-
49
- sc.socket.on('completed', function (msg) {
50
- bdebug('received completed event for: ', msg);
51
- });
52
-
53
- // handle incoming messages from the Socekthub server
54
- sc.socket.on('message', function (msg) {
55
- bdebug('received message: ', msg);
56
- if (Array.isArray(msg)) {
57
- bdebug('is array len:' + msg.length);
58
- for (var i = 0, len = msg.length; i < len; i++) {
59
- bdebug('looping '+i+' ', msg[i]);
60
- displayMessage(msg[i]);
61
- }
62
- } else {
63
- displayMessage(msg);
64
- }
65
- });
66
-
67
- // handler for user input, emit messages to Sockethub server
68
- $('form').submit(function () {
69
- let text = $('#m').val();
70
- const parts = text.split('fail:');
71
- let type = 'echo';
72
- text = parts[parts.length-1];
73
- if (parts.length > 1) {
74
- type = 'fail';
75
- }
76
- const msg = {
77
- context: 'dummy',
78
- 'type': type,
79
- actor: 'https://sockethub.org/examples/dummyUser',
80
- object: {
81
- 'type': 'message',
82
- content: text
83
- }
84
- };
85
- bdebug('sending message: ', msg);
86
- sc.socket.emit('message', msg);
87
-
88
- $('#m').val('');
89
- return false;
90
- });
91
- </script>
92
- </body>
93
- </html>
@@ -1,90 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>Sockethub Example Feed Reader</title>
5
- <style>
6
- * { margin: 0; padding: 0; box-sizing: border-box; }
7
- body { font: 13px Helvetica, Arial; }
8
- form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
9
- form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
10
- form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
11
- #messages { list-style-type: none; margin: 0; padding: 0; }
12
- #messages li { padding: 5px 10px; }
13
- #messages li:nth-child(odd) { background: #eee; }
14
- </style>
15
- </head>
16
- <body>
17
- <ul id="messages"></ul>
18
- <form action="">
19
- <input id="m" autocomplete="off" /><button>Send</button>
20
- </form>
21
-
22
- <script src="<%= address %>jquery.js"></script>
23
- <script src="<%= address %>socket.io.js"></script>
24
- <script src="<%= address %>activity-streams.min.js"></script>
25
- <script src="<%= address %>sockethub-client.js"></script>
26
- <script>
27
- localStorage.debug = '<%= debug_scope %>';
28
- const sc = new SockethubClient(io('<%= address %>', { path: '/sockethub' }));
29
-
30
- // errors
31
- sc.socket.on('failure', function (msg) {
32
- console.log('received failure: ', msg);
33
- });
34
-
35
- sc.socket.on('completed', function (msg) {
36
- console.log('received completed event for: ', msg);
37
- displayMessages(msg.object.content || []);
38
- });
39
-
40
- // handle incoming messages from the Sockethub server
41
- sc.socket.on('message', function (msg) {
42
- console.log('received message: ', msg);
43
- displayMessages(msg);
44
- });
45
-
46
- function displayMessages(msgs) {
47
- if (Array.isArray(msgs)) {
48
- for (let i = 0, len = msgs.length; i < len; i++) {
49
- displayMessage(msgs[i]);
50
- }
51
- } else {
52
- displayMessage(msgs);
53
- }
54
- }
55
-
56
- function displayMessage(msg) {
57
- console.log('displaying message: ', msg);
58
- $('#messages').append($('<li>').html(`<b>${msg.object.name}</b>: ${msg.object.html}`));
59
- }
60
-
61
- // handler for user input, emit messages to Sockethub server
62
- $('form').submit(function () {
63
- const msg = {
64
- context: 'feeds',
65
- 'type': 'fetch',
66
- actor: 'https://sockethub.org/examples/feeds',
67
- object: {
68
- 'type': 'parameters'
69
- },
70
- target: {
71
- 'type': 'feed',
72
- 'id': $('#m').val()
73
- }
74
- };
75
-
76
- console.log('sending message: ', msg);
77
- sc.socket.emit('message', msg, (data) => { console.log('CALLBACK', data); });
78
- $('#m').val('');
79
- return false;
80
- });
81
-
82
- // our feed actor info
83
- sc.ActivityStreams.Object.create({
84
- 'id': 'https://sockethub.org/examples/feeds',
85
- 'type': "website",
86
- name: "Sockethub Examples - Feeds"
87
- });
88
- </script>
89
- </body>
90
- </html>