oorja 1.11.4 → 2.0.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 +14 -52
- package/dist/commands/signout.d.ts +1 -1
- package/dist/commands/signout.js +4 -4
- package/dist/commands/teletype/index.d.ts +7 -6
- package/dist/commands/teletype/index.js +49 -47
- package/dist/lib/config.d.ts +7 -10
- package/dist/lib/config.js +29 -49
- package/dist/lib/{surya → connect}/index.d.ts +8 -8
- package/dist/lib/{surya → connect}/index.js +39 -36
- package/dist/lib/{surya → connect}/resources.js +2 -2
- package/dist/lib/{surya → connect}/types.d.ts +1 -3
- package/dist/lib/encryption.d.ts +2 -3
- package/dist/lib/encryption.js +6 -10
- package/dist/lib/oorja/client.d.ts +3 -0
- package/dist/lib/oorja/client.js +52 -0
- package/dist/lib/oorja/index.d.ts +7 -7
- package/dist/lib/oorja/index.js +40 -29
- package/dist/lib/oorja/preflight.d.ts +8 -8
- package/dist/lib/oorja/preflight.js +45 -41
- package/dist/lib/teletype/auxiliary.d.ts +2 -2
- package/dist/lib/teletype/auxiliary.js +5 -5
- package/dist/lib/teletype/index.d.ts +3 -4
- package/dist/lib/teletype/index.js +16 -16
- package/dist/lib/utils.js +5 -5
- package/oclif.manifest.json +11 -10
- package/package.json +22 -18
- package/dist/lib/surya/vendor/phoenix/ajax.d.ts +0 -8
- package/dist/lib/surya/vendor/phoenix/ajax.js +0 -82
- package/dist/lib/surya/vendor/phoenix/channel.d.ts +0 -154
- package/dist/lib/surya/vendor/phoenix/channel.js +0 -308
- package/dist/lib/surya/vendor/phoenix/constants.d.ts +0 -33
- package/dist/lib/surya/vendor/phoenix/constants.js +0 -29
- package/dist/lib/surya/vendor/phoenix/index.d.ts +0 -199
- package/dist/lib/surya/vendor/phoenix/index.js +0 -200
- package/dist/lib/surya/vendor/phoenix/longpoll.d.ts +0 -12
- package/dist/lib/surya/vendor/phoenix/longpoll.js +0 -126
- package/dist/lib/surya/vendor/phoenix/presence.d.ts +0 -44
- package/dist/lib/surya/vendor/phoenix/presence.js +0 -152
- package/dist/lib/surya/vendor/phoenix/push.d.ts +0 -57
- package/dist/lib/surya/vendor/phoenix/push.js +0 -122
- package/dist/lib/surya/vendor/phoenix/serializer.d.ts +0 -53
- package/dist/lib/surya/vendor/phoenix/serializer.js +0 -100
- package/dist/lib/surya/vendor/phoenix/socket.d.ts +0 -222
- package/dist/lib/surya/vendor/phoenix/socket.js +0 -541
- package/dist/lib/surya/vendor/phoenix/timer.d.ts +0 -25
- package/dist/lib/surya/vendor/phoenix/timer.js +0 -40
- package/dist/lib/surya/vendor/phoenix/utils.d.ts +0 -1
- package/dist/lib/surya/vendor/phoenix/utils.js +0 -11
- /package/dist/lib/{surya → connect}/errors.d.ts +0 -0
- /package/dist/lib/{surya → connect}/errors.js +0 -0
- /package/dist/lib/{surya → connect}/resources.d.ts +0 -0
- /package/dist/lib/{surya → connect}/types.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IPty } from
|
|
2
|
-
import { Hash } from
|
|
1
|
+
import { IPty } from 'node-pty';
|
|
2
|
+
import { Hash } from '../connect/types.js';
|
|
3
3
|
export declare const initScreen: (username: string, hostname: string, shell: string, multiplexed: boolean) => void;
|
|
4
4
|
export type dimensions = {
|
|
5
5
|
rows: number;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import chalk from
|
|
2
|
-
import termSize from
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import termSize from 'terminal-size';
|
|
3
3
|
export const initScreen = (username, hostname, shell, multiplexed) => {
|
|
4
|
-
console.log(chalk.bold(chalk.blueBright(
|
|
4
|
+
console.log(chalk.bold(chalk.blueBright('TeleType')));
|
|
5
5
|
if (multiplexed) {
|
|
6
|
-
console.log(chalk.yellowBright(
|
|
6
|
+
console.log(chalk.yellowBright('You have allowed room participants to write to your shell'));
|
|
7
7
|
}
|
|
8
8
|
console.log(chalk.blue(`${chalk.bold(`${username}@${hostname}`)} Spawning streaming shell: ${chalk.bold(`${shell}`)}`));
|
|
9
9
|
console.log(`Note: Your shell size may adjust for optimum viewing experience for all participants.\n
|
|
10
10
|
This session is end-to-end encrypted.
|
|
11
|
-
To terminate stream run ${chalk.yellowBright(
|
|
11
|
+
To terminate stream run ${chalk.yellowBright('exit')} or press ${chalk.yellowBright('ctrl-d')} \n`);
|
|
12
12
|
};
|
|
13
13
|
export const getDimensions = () => {
|
|
14
14
|
const { rows, columns } = termSize();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Channel } from "../surya/vendor/phoenix/index.js";
|
|
1
|
+
import { RoomKey } from '../connect/types.js';
|
|
2
|
+
import { JoinChannelOptions } from '../connect/index.js';
|
|
3
|
+
import { Channel } from 'phoenix';
|
|
5
4
|
export type TeletypeOptions = {
|
|
6
5
|
userId: string;
|
|
7
6
|
roomKey: RoomKey;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { spawn } from
|
|
2
|
-
import * as os from
|
|
3
|
-
import { getDimensions, initScreen, areDimensionEqual, resizeBestFit
|
|
4
|
-
import chalk from
|
|
5
|
-
import { Unauthorized } from
|
|
6
|
-
import { encrypt, decrypt } from
|
|
1
|
+
import { spawn } from 'node-pty';
|
|
2
|
+
import * as os from 'os';
|
|
3
|
+
import { getDimensions, initScreen, areDimensionEqual, resizeBestFit } from './auxiliary.js';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { Unauthorized } from '../connect/errors.js';
|
|
6
|
+
import { encrypt, decrypt } from '../encryption.js';
|
|
7
7
|
var MessageType;
|
|
8
8
|
(function (MessageType) {
|
|
9
9
|
MessageType["IN"] = "i";
|
|
10
10
|
MessageType["OUT"] = "o";
|
|
11
11
|
MessageType["DIMENSIONS"] = "d";
|
|
12
12
|
})(MessageType || (MessageType = {}));
|
|
13
|
-
const SELF =
|
|
13
|
+
const SELF = 'self';
|
|
14
14
|
export const teletypeApp = (options) => {
|
|
15
15
|
const username = os.userInfo().username;
|
|
16
16
|
const hostname = os.hostname();
|
|
@@ -40,7 +40,7 @@ export const teletypeApp = (options) => {
|
|
|
40
40
|
const stdout = options.process.stdout;
|
|
41
41
|
const dimensions = userDimensions[SELF];
|
|
42
42
|
term = spawn(options.shell, [], {
|
|
43
|
-
name:
|
|
43
|
+
name: 'xterm-256color',
|
|
44
44
|
cols: dimensions.cols,
|
|
45
45
|
rows: dimensions.rows,
|
|
46
46
|
cwd: options.process.cwd(),
|
|
@@ -53,22 +53,22 @@ export const teletypeApp = (options) => {
|
|
|
53
53
|
stdout.write(d);
|
|
54
54
|
// revisit: is it worth having one letter names, instead of something descriptive
|
|
55
55
|
// does it really save bytes?
|
|
56
|
-
channel.push(
|
|
56
|
+
channel.push('new_msg', {
|
|
57
57
|
t: MessageType.OUT,
|
|
58
58
|
b: true,
|
|
59
59
|
d: encrypt(d, options.roomKey),
|
|
60
60
|
});
|
|
61
61
|
});
|
|
62
62
|
term.onExit(() => {
|
|
63
|
-
console.log(chalk.blueBright(
|
|
63
|
+
console.log(chalk.blueBright('terminated shell stream to oorja. byee!'));
|
|
64
64
|
resolve(null);
|
|
65
65
|
});
|
|
66
|
-
stdin.setEncoding(
|
|
66
|
+
stdin.setEncoding('utf8');
|
|
67
67
|
stdin.setRawMode(true);
|
|
68
|
-
stdin.on(
|
|
68
|
+
stdin.on('data', (d) => term.write(d.toString('utf8')));
|
|
69
69
|
},
|
|
70
70
|
onClose: () => {
|
|
71
|
-
console.log(chalk.redBright(
|
|
71
|
+
console.log(chalk.redBright('connection closed, terminated stream.'));
|
|
72
72
|
process.exit(3);
|
|
73
73
|
},
|
|
74
74
|
onError: (err) => {
|
|
@@ -76,7 +76,7 @@ export const teletypeApp = (options) => {
|
|
|
76
76
|
console.log(chalk.redBright(err.message));
|
|
77
77
|
}
|
|
78
78
|
else {
|
|
79
|
-
console.log(chalk.redBright(
|
|
79
|
+
console.log(chalk.redBright('connection error, terminated stream.'));
|
|
80
80
|
}
|
|
81
81
|
process.exit(4);
|
|
82
82
|
},
|
|
@@ -88,7 +88,7 @@ export const teletypeApp = (options) => {
|
|
|
88
88
|
break;
|
|
89
89
|
case MessageType.IN:
|
|
90
90
|
const data = decrypt(d, options.roomKey);
|
|
91
|
-
const userId = session.split(
|
|
91
|
+
const userId = session.split(':')[0];
|
|
92
92
|
if (options.multiplex) {
|
|
93
93
|
term.write(data);
|
|
94
94
|
return;
|
|
@@ -104,7 +104,7 @@ export const teletypeApp = (options) => {
|
|
|
104
104
|
},
|
|
105
105
|
handleSessionJoin: (s) => { },
|
|
106
106
|
handleSessionLeave: (s) => {
|
|
107
|
-
delete userDimensions[s];
|
|
107
|
+
s && delete userDimensions[s];
|
|
108
108
|
resizeBestFit(term, userDimensions);
|
|
109
109
|
},
|
|
110
110
|
});
|
package/dist/lib/utils.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import inquirer from 'inquirer';
|
|
2
2
|
export const promptRoomLink = async () => {
|
|
3
|
-
const {
|
|
3
|
+
const { spaceLink } = await inquirer.prompt([
|
|
4
4
|
{
|
|
5
5
|
type: 'input',
|
|
6
|
-
name: '
|
|
7
|
-
message: 'Enter the
|
|
8
|
-
}
|
|
6
|
+
name: 'spaceLink',
|
|
7
|
+
message: 'Enter the space secret link (copy URL from address bar in your browser):',
|
|
8
|
+
},
|
|
9
9
|
]);
|
|
10
|
-
return
|
|
10
|
+
return spaceLink;
|
|
11
11
|
};
|
package/oclif.manifest.json
CHANGED
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"tty"
|
|
26
26
|
],
|
|
27
27
|
"args": {
|
|
28
|
-
"
|
|
29
|
-
"name": "
|
|
28
|
+
"space": {
|
|
29
|
+
"name": "space"
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"description": "Launch a terminal streaming session in oorja.",
|
|
33
33
|
"examples": [
|
|
34
|
-
"$ teletype\nWill prompt to choose streaming destination - existing
|
|
35
|
-
"$ teletype 'https://oorja.io/
|
|
36
|
-
"$ teletype -m\nWill also allow
|
|
34
|
+
"\u001b[94m$ teletype\u001b[39m\nWill prompt to choose streaming destination - existing space or create a new one.\n\n",
|
|
35
|
+
"\u001b[94m$ teletype 'https://oorja.io/spaces?id=foo#key'\u001b[39m\nWill stream to the space specified by secret link, you must have joined the space before streaming.\n\n",
|
|
36
|
+
"\u001b[94m$ teletype -m\u001b[39m\nWill also allow participants to write to your terminal!\n\n"
|
|
37
37
|
],
|
|
38
38
|
"flags": {
|
|
39
39
|
"help": {
|
|
@@ -54,15 +54,15 @@
|
|
|
54
54
|
},
|
|
55
55
|
"multiplex": {
|
|
56
56
|
"char": "m",
|
|
57
|
-
"description": "Allows
|
|
57
|
+
"description": "Allows users to WRITE TO YOUR SHELL i.e enables collaboration mode. Make sure you trust space participants. Off by default",
|
|
58
58
|
"name": "multiplex",
|
|
59
59
|
"allowNo": false,
|
|
60
60
|
"type": "boolean"
|
|
61
61
|
},
|
|
62
|
-
"
|
|
62
|
+
"new_space": {
|
|
63
63
|
"char": "n",
|
|
64
|
-
"description": "Create new
|
|
65
|
-
"name": "
|
|
64
|
+
"description": "Create new space",
|
|
65
|
+
"name": "new_space",
|
|
66
66
|
"allowNo": false,
|
|
67
67
|
"type": "boolean"
|
|
68
68
|
}
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"pluginType": "core",
|
|
76
76
|
"strict": true,
|
|
77
77
|
"enableJsonFlag": false,
|
|
78
|
+
"order": 1,
|
|
78
79
|
"isESM": true,
|
|
79
80
|
"relativePath": [
|
|
80
81
|
"dist",
|
|
@@ -84,5 +85,5 @@
|
|
|
84
85
|
]
|
|
85
86
|
}
|
|
86
87
|
},
|
|
87
|
-
"version": "
|
|
88
|
+
"version": "2.0.0"
|
|
88
89
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oorja",
|
|
3
3
|
"description": "stream terminals to the web and more.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"teletype",
|
|
7
7
|
"terminal",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"prepack": "yarn build && oclif manifest && oclif readme",
|
|
33
33
|
"postpack": "shx rm -f oclif.manifest.json",
|
|
34
34
|
"prepare": "yarn build",
|
|
35
|
-
"version": "oclif readme && git add README.md"
|
|
35
|
+
"version": "oclif readme && git add README.md",
|
|
36
|
+
"format": "prettier --write ."
|
|
36
37
|
},
|
|
37
38
|
"oclif": {
|
|
38
39
|
"bin": "oorja",
|
|
@@ -44,33 +45,36 @@
|
|
|
44
45
|
]
|
|
45
46
|
},
|
|
46
47
|
"dependencies": {
|
|
47
|
-
"@msgpack/msgpack": "^
|
|
48
|
-
"@oclif/core": "^
|
|
49
|
-
"@oclif/plugin-help": "^6.
|
|
50
|
-
"axios": "^1.
|
|
48
|
+
"@msgpack/msgpack": "^2.8.0",
|
|
49
|
+
"@oclif/core": "^4.2.0",
|
|
50
|
+
"@oclif/plugin-help": "^6.2.20",
|
|
51
|
+
"axios": "^1.7.9",
|
|
51
52
|
"camelcase-keys": "^9.1.3",
|
|
52
|
-
"chalk": "^5.
|
|
53
|
+
"chalk": "^5.4.1",
|
|
53
54
|
"conf-cli": "0.1.9",
|
|
54
|
-
"
|
|
55
|
+
"haversine-distance": "^1.2.3",
|
|
56
|
+
"inquirer": "^12.3.0",
|
|
55
57
|
"node-pty": "^1.0.0",
|
|
56
|
-
"ora": "^8.
|
|
57
|
-
"
|
|
58
|
-
"
|
|
58
|
+
"ora": "^8.1.1",
|
|
59
|
+
"phoenix": "1.7.18",
|
|
60
|
+
"terminal-size": "^4.0.0"
|
|
59
61
|
},
|
|
60
62
|
"devDependencies": {
|
|
61
63
|
"@oclif/prettier-config": "^0.2.1",
|
|
62
64
|
"@types/inquirer": "^9.0.7",
|
|
63
|
-
"@types/node": "^
|
|
64
|
-
"
|
|
65
|
-
"eslint
|
|
66
|
-
"eslint-config-oclif
|
|
65
|
+
"@types/node": "^22.10.2",
|
|
66
|
+
"@types/phoenix": "^1.6.6",
|
|
67
|
+
"eslint": "^9.17.0",
|
|
68
|
+
"eslint-config-oclif": "^5.2.2",
|
|
69
|
+
"eslint-config-oclif-typescript": "^3.1.13",
|
|
67
70
|
"eslint-config-prettier": "^9.1.0",
|
|
68
|
-
"oclif": "^4.
|
|
71
|
+
"oclif": "^4.17.4",
|
|
72
|
+
"prettier": "^3.4.2",
|
|
69
73
|
"shx": "^0.3.4",
|
|
70
74
|
"ts-node": "^10.9.2",
|
|
71
|
-
"typescript": "^5.
|
|
75
|
+
"typescript": "^5.7.2"
|
|
72
76
|
},
|
|
73
77
|
"engines": {
|
|
74
|
-
"node": ">=
|
|
78
|
+
"node": ">=22.10.0"
|
|
75
79
|
}
|
|
76
80
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export default class Ajax {
|
|
2
|
-
static request(method: any, endPoint: any, accept: any, body: any, timeout: any, ontimeout: any, callback: any): any;
|
|
3
|
-
static xdomainRequest(req: any, method: any, endPoint: any, body: any, timeout: any, ontimeout: any, callback: any): any;
|
|
4
|
-
static xhrRequest(req: any, method: any, endPoint: any, accept: any, body: any, timeout: any, ontimeout: any, callback: any): any;
|
|
5
|
-
static parseJSON(resp: any): any;
|
|
6
|
-
static serialize(obj: any, parentKey: any): any;
|
|
7
|
-
static appendParams(url: any, params: any): any;
|
|
8
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import { global, XHR_STATES } from "./constants.js";
|
|
3
|
-
export default class Ajax {
|
|
4
|
-
static request(method, endPoint, accept, body, timeout, ontimeout, callback) {
|
|
5
|
-
if (global.XDomainRequest) {
|
|
6
|
-
let req = new global.XDomainRequest(); // IE8, IE9
|
|
7
|
-
return this.xdomainRequest(req, method, endPoint, body, timeout, ontimeout, callback);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
let req = new global.XMLHttpRequest(); // IE7+, Firefox, Chrome, Opera, Safari
|
|
11
|
-
return this.xhrRequest(req, method, endPoint, accept, body, timeout, ontimeout, callback);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
static xdomainRequest(req, method, endPoint, body, timeout, ontimeout, callback) {
|
|
15
|
-
req.timeout = timeout;
|
|
16
|
-
req.open(method, endPoint);
|
|
17
|
-
req.onload = () => {
|
|
18
|
-
let response = this.parseJSON(req.responseText);
|
|
19
|
-
callback && callback(response);
|
|
20
|
-
};
|
|
21
|
-
if (ontimeout) {
|
|
22
|
-
req.ontimeout = ontimeout;
|
|
23
|
-
}
|
|
24
|
-
// Work around bug in IE9 that requires an attached onprogress handler
|
|
25
|
-
req.onprogress = () => { };
|
|
26
|
-
req.send(body);
|
|
27
|
-
return req;
|
|
28
|
-
}
|
|
29
|
-
static xhrRequest(req, method, endPoint, accept, body, timeout, ontimeout, callback) {
|
|
30
|
-
req.open(method, endPoint, true);
|
|
31
|
-
req.timeout = timeout;
|
|
32
|
-
req.setRequestHeader("Content-Type", accept);
|
|
33
|
-
req.onerror = () => callback && callback(null);
|
|
34
|
-
req.onreadystatechange = () => {
|
|
35
|
-
if (req.readyState === XHR_STATES.complete && callback) {
|
|
36
|
-
let response = this.parseJSON(req.responseText);
|
|
37
|
-
callback(response);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
if (ontimeout) {
|
|
41
|
-
req.ontimeout = ontimeout;
|
|
42
|
-
}
|
|
43
|
-
req.send(body);
|
|
44
|
-
return req;
|
|
45
|
-
}
|
|
46
|
-
static parseJSON(resp) {
|
|
47
|
-
if (!resp || resp === "") {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
return JSON.parse(resp);
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
console && console.log("failed to parse JSON response", resp);
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
static serialize(obj, parentKey) {
|
|
59
|
-
let queryStr = [];
|
|
60
|
-
for (var key in obj) {
|
|
61
|
-
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
let paramKey = parentKey ? `${parentKey}[${key}]` : key;
|
|
65
|
-
let paramVal = obj[key];
|
|
66
|
-
if (typeof paramVal === "object") {
|
|
67
|
-
queryStr.push(this.serialize(paramVal, paramKey));
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
queryStr.push(encodeURIComponent(paramKey) + "=" + encodeURIComponent(paramVal));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return queryStr.join("&");
|
|
74
|
-
}
|
|
75
|
-
static appendParams(url, params) {
|
|
76
|
-
if (Object.keys(params).length === 0) {
|
|
77
|
-
return url;
|
|
78
|
-
}
|
|
79
|
-
let prefix = url.match(/\?/) ? "&" : "?";
|
|
80
|
-
return `${url}${prefix}${this.serialize(params)}`;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import Push from "./push.js";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param {string} topic
|
|
5
|
-
* @param {(Object|function)} params
|
|
6
|
-
* @param {Socket} socket
|
|
7
|
-
*/
|
|
8
|
-
export default class Channel {
|
|
9
|
-
constructor(topic: any, params: any, socket: any);
|
|
10
|
-
/**
|
|
11
|
-
* Join the channel
|
|
12
|
-
* @param {integer} timeout
|
|
13
|
-
* @returns {Push}
|
|
14
|
-
*/
|
|
15
|
-
join(timeout?: any): any;
|
|
16
|
-
/**
|
|
17
|
-
* Hook into channel close
|
|
18
|
-
* @param {Function} callback
|
|
19
|
-
*/
|
|
20
|
-
onClose(callback: any): void;
|
|
21
|
-
/**
|
|
22
|
-
* Hook into channel errors
|
|
23
|
-
* @param {Function} callback
|
|
24
|
-
*/
|
|
25
|
-
onError(callback: any): number;
|
|
26
|
-
/**
|
|
27
|
-
* Subscribes on channel events
|
|
28
|
-
*
|
|
29
|
-
* Subscription returns a ref counter, which can be used later to
|
|
30
|
-
* unsubscribe the exact event listener
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* const ref1 = channel.on("event", do_stuff)
|
|
34
|
-
* const ref2 = channel.on("event", do_other_stuff)
|
|
35
|
-
* channel.off("event", ref1)
|
|
36
|
-
* // Since unsubscription, do_stuff won't fire,
|
|
37
|
-
* // while do_other_stuff will keep firing on the "event"
|
|
38
|
-
*
|
|
39
|
-
* @param {string} event
|
|
40
|
-
* @param {Function} callback
|
|
41
|
-
* @returns {integer} ref
|
|
42
|
-
*/
|
|
43
|
-
on(event: any, callback: any): number;
|
|
44
|
-
/**
|
|
45
|
-
* Unsubscribes off of channel events
|
|
46
|
-
*
|
|
47
|
-
* Use the ref returned from a channel.on() to unsubscribe one
|
|
48
|
-
* handler, or pass nothing for the ref to unsubscribe all
|
|
49
|
-
* handlers for the given event.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* // Unsubscribe the do_stuff handler
|
|
53
|
-
* const ref1 = channel.on("event", do_stuff)
|
|
54
|
-
* channel.off("event", ref1)
|
|
55
|
-
*
|
|
56
|
-
* // Unsubscribe all handlers from event
|
|
57
|
-
* channel.off("event")
|
|
58
|
-
*
|
|
59
|
-
* @param {string} event
|
|
60
|
-
* @param {integer} ref
|
|
61
|
-
*/
|
|
62
|
-
off(event: any, ref: any): void;
|
|
63
|
-
/**
|
|
64
|
-
* @private
|
|
65
|
-
*/
|
|
66
|
-
canPush(): any;
|
|
67
|
-
/**
|
|
68
|
-
* Sends a message `event` to phoenix with the payload `payload`.
|
|
69
|
-
* Phoenix receives this in the `handle_in(event, payload, socket)`
|
|
70
|
-
* function. if phoenix replies or it times out (default 10000ms),
|
|
71
|
-
* then optionally the reply can be received.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* channel.push("event")
|
|
75
|
-
* .receive("ok", payload => console.log("phoenix replied:", payload))
|
|
76
|
-
* .receive("error", err => console.log("phoenix errored", err))
|
|
77
|
-
* .receive("timeout", () => console.log("timed out pushing"))
|
|
78
|
-
* @param {string} event
|
|
79
|
-
* @param {Object} payload
|
|
80
|
-
* @param {number} [timeout]
|
|
81
|
-
* @returns {Push}
|
|
82
|
-
*/
|
|
83
|
-
push(event: any, payload: any, timeout?: any): Push;
|
|
84
|
-
/** Leaves the channel
|
|
85
|
-
*
|
|
86
|
-
* Unsubscribes from server events, and
|
|
87
|
-
* instructs channel to terminate on server
|
|
88
|
-
*
|
|
89
|
-
* Triggers onClose() hooks
|
|
90
|
-
*
|
|
91
|
-
* To receive leave acknowledgements, use the `receive`
|
|
92
|
-
* hook to bind to the server ack, ie:
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* channel.leave().receive("ok", () => alert("left!") )
|
|
96
|
-
*
|
|
97
|
-
* @param {integer} timeout
|
|
98
|
-
* @returns {Push}
|
|
99
|
-
*/
|
|
100
|
-
leave(timeout?: any): Push;
|
|
101
|
-
/**
|
|
102
|
-
* Overridable message hook
|
|
103
|
-
*
|
|
104
|
-
* Receives all events for specialized message handling
|
|
105
|
-
* before dispatching to the channel callbacks.
|
|
106
|
-
*
|
|
107
|
-
* Must return the payload, modified or unmodified
|
|
108
|
-
* @param {string} event
|
|
109
|
-
* @param {Object} payload
|
|
110
|
-
* @param {integer} ref
|
|
111
|
-
* @returns {Object}
|
|
112
|
-
*/
|
|
113
|
-
onMessage(_event: any, payload: any, _ref: any): any;
|
|
114
|
-
/**
|
|
115
|
-
* @private
|
|
116
|
-
*/
|
|
117
|
-
isMember(topic: any, event: any, payload: any, joinRef: any): boolean;
|
|
118
|
-
/**
|
|
119
|
-
* @private
|
|
120
|
-
*/
|
|
121
|
-
joinRef(): any;
|
|
122
|
-
/**
|
|
123
|
-
* @private
|
|
124
|
-
*/
|
|
125
|
-
rejoin(timeout?: any): void;
|
|
126
|
-
/**
|
|
127
|
-
* @private
|
|
128
|
-
*/
|
|
129
|
-
trigger(event: any, payload: any, ref: any, joinRef: any): void;
|
|
130
|
-
/**
|
|
131
|
-
* @private
|
|
132
|
-
*/
|
|
133
|
-
replyEventName(ref: any): string;
|
|
134
|
-
/**
|
|
135
|
-
* @private
|
|
136
|
-
*/
|
|
137
|
-
isClosed(): boolean;
|
|
138
|
-
/**
|
|
139
|
-
* @private
|
|
140
|
-
*/
|
|
141
|
-
isErrored(): boolean;
|
|
142
|
-
/**
|
|
143
|
-
* @private
|
|
144
|
-
*/
|
|
145
|
-
isJoined(): boolean;
|
|
146
|
-
/**
|
|
147
|
-
* @private
|
|
148
|
-
*/
|
|
149
|
-
isJoining(): boolean;
|
|
150
|
-
/**
|
|
151
|
-
* @private
|
|
152
|
-
*/
|
|
153
|
-
isLeaving(): boolean;
|
|
154
|
-
}
|