actionhero-socket-server
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -9,4 +9,4 @@ import * as uuid from "uuid"; | ||
const sleep = zzz => { | ||
return new Promise(resolve => { | ||
const sleep = (zzz) => { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, zzz); | ||
@@ -29,4 +29,4 @@ }); | ||
let response; | ||
return new Promise(resolve => { | ||
const onData = d => { | ||
return new Promise((resolve) => { | ||
const onData = (d) => { | ||
data += d; | ||
@@ -52,3 +52,3 @@ const lines = data.split(delimiter); | ||
const buildClient = (): any => { | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
const conn = net.connect(config.servers.socket.port); | ||
@@ -133,4 +133,4 @@ // conn.data = ""; | ||
uuid.v4() + | ||
uuid.v4() | ||
} | ||
uuid.v4(), | ||
}, | ||
}; | ||
@@ -247,3 +247,3 @@ | ||
action: "randomNumber", | ||
params: { messageId: "abc123" } | ||
params: { messageId: "abc123" }, | ||
}) | ||
@@ -263,3 +263,3 @@ ); | ||
await new Promise(resolve => { | ||
await new Promise((resolve) => { | ||
newClient.on("close", () => { | ||
@@ -284,3 +284,3 @@ return resolve(); | ||
action: "sleepTest", | ||
sleepDuration: 100 | ||
sleepDuration: 100, | ||
})} \r\n`; | ||
@@ -290,5 +290,5 @@ i++; | ||
await new Promise(resolve => { | ||
const checkResponses = data => { | ||
data.split("\n").forEach(line => { | ||
await new Promise((resolve) => { | ||
const checkResponses = (data) => { | ||
data.split("\n").forEach((line) => { | ||
if (line.length > 0 && line.indexOf("welcome") < 0) { | ||
@@ -332,4 +332,4 @@ responses.push(JSON.parse(line)); | ||
key: uuid.v4(), | ||
value: longMessage | ||
} | ||
value: longMessage, | ||
}, | ||
}; | ||
@@ -435,3 +435,3 @@ | ||
); | ||
} | ||
}, | ||
}); | ||
@@ -447,3 +447,3 @@ | ||
); | ||
} | ||
}, | ||
}); | ||
@@ -526,7 +526,7 @@ }); | ||
//@ts-ignore | ||
chatRoom.sanitizeMemberDetails = connection => { | ||
chatRoom.sanitizeMemberDetails = (connection) => { | ||
return { | ||
id: connection.id, | ||
joinedAt: connection.joinedAt, | ||
type: connection.type | ||
type: connection.type, | ||
}; | ||
@@ -536,7 +536,7 @@ }; | ||
//@ts-ignore | ||
chatRoom.generateMemberDetails = connection => { | ||
chatRoom.generateMemberDetails = (connection) => { | ||
return { | ||
id: connection.id, | ||
joinedAt: new Date().getTime(), | ||
type: connection.type | ||
type: connection.type, | ||
}; | ||
@@ -590,3 +590,3 @@ }; | ||
await new Promise(resolve => { | ||
await new Promise((resolve) => { | ||
client.on("close", () => { | ||
@@ -593,0 +593,0 @@ return resolve(); |
@@ -5,3 +5,3 @@ { | ||
"description": "A TCP and JSON server for actionhero", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"homepage": "http://www.actionherojs.com", | ||
@@ -37,10 +37,10 @@ "license": "Apache-2.0", | ||
"devDependencies": { | ||
"@types/node": "latest", | ||
"@types/jest": "latest", | ||
"actionhero": "^22.0.2", | ||
"jest": "^25.1.0", | ||
"prettier": "latest", | ||
"ts-jest": "latest", | ||
"ts-node-dev": "latest", | ||
"typescript": "latest" | ||
"@types/node": "^14.6.4", | ||
"@types/jest": "^26.0.13", | ||
"actionhero": "^23.0.10", | ||
"jest": "^26.4.2", | ||
"prettier": "^2.1.1", | ||
"ts-jest": "^26.3.0", | ||
"ts-node-dev": "^1.0.0-pre.62", | ||
"typescript": "^4.0.2" | ||
}, | ||
@@ -50,3 +50,3 @@ "scripts": { | ||
"pretest": "npm run lint && npm run build", | ||
"lint": "prettier --check src/*.ts __tests__/*.ts", | ||
"lint": "prettier --check src __tests__", | ||
"dev": "ts-node-dev --no-deps --transpile-only ./src/server.ts", | ||
@@ -53,0 +53,0 @@ "build": "./node_modules/.bin/tsc --declaration && rm -rf dist/actions", |
@@ -23,28 +23,39 @@ # Actionhero Socket Server | ||
1. Add the package to your actionhero project: `npm install actionhero-socket-server --save` | ||
2. Copy the config file into your project `cp ./node_modules/actionhero-socket-server/src/config/servers/socket.js src/config/servers/socket.js` | ||
2. Copy the config file into your project `cp ./node_modules/actionhero-socket-server/src/config/servers/socket.ts src/config/servers/socket.ts` | ||
3. Enable the plugin: | ||
```js | ||
```ts | ||
// in config/plugins.ts | ||
import * as path from "path"; | ||
export const DEFAULT = { | ||
plugins: config => { | ||
plugins: () => { | ||
return { | ||
"actionhero-socket-server": { | ||
path: __dirname + "/../node_modules/actionhero-socket-server" | ||
} | ||
path: path.join( | ||
__dirname, | ||
"..", | ||
"..", | ||
"node_modules", | ||
"actionhero-socket-server" | ||
), | ||
}, | ||
}; | ||
} | ||
}, | ||
}; | ||
``` | ||
4. Add a searilazer for errors: | ||
4. Add a serializer for errors: | ||
```ts | ||
// in config/errors.ts | ||
// you are adding config.errors.serializers.socket | ||
socket: error => { | ||
if (error.message) { | ||
return String(error.message); | ||
} else { | ||
return error; | ||
} | ||
}, | ||
if (error.message) { | ||
return String(error.message); | ||
} else { | ||
return error; | ||
} | ||
}, | ||
``` | ||
@@ -59,3 +70,3 @@ | ||
servers: { | ||
socket: config => { | ||
socket: (config) => { | ||
return { | ||
@@ -76,7 +87,7 @@ enabled: true, | ||
// Maximum incoming message string length in Bytes (use 0 for Infinite) | ||
maxDataLength: 0 | ||
maxDataLength: 0, | ||
}; | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
``` |
@@ -12,3 +12,3 @@ import { cache, Action } from "actionhero"; | ||
formatter: this.stringFormatter, | ||
validator: this.stringValidator | ||
validator: this.stringValidator, | ||
}, | ||
@@ -19,4 +19,4 @@ | ||
formatter: this.stringFormatter, | ||
validator: this.stringValidator | ||
} | ||
validator: this.stringValidator, | ||
}, | ||
}; | ||
@@ -32,6 +32,6 @@ this.outputExample = { | ||
createdAt: 1420953269716, | ||
readAt: null | ||
readAt: null, | ||
}, | ||
deleteResp: true | ||
} | ||
deleteResp: true, | ||
}, | ||
}; | ||
@@ -60,5 +60,5 @@ } | ||
loadResp: await cache.load(key), | ||
deleteResp: await cache.destroy(key) | ||
deleteResp: await cache.destroy(key), | ||
}; | ||
} | ||
} |
import { api, Action } from "actionhero"; | ||
function sleep(time: number): Promise<void> { | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, time); | ||
@@ -17,3 +17,3 @@ }); | ||
required: true, | ||
formatter: n => { | ||
formatter: (n) => { | ||
return parseInt(n); | ||
@@ -23,4 +23,4 @@ }, | ||
return 1000; | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
@@ -31,3 +31,3 @@ this.outputExample = { | ||
sleepDelta: 1005, | ||
sleepDuration: 1000 | ||
sleepDuration: 1000, | ||
}; | ||
@@ -34,0 +34,0 @@ } |
@@ -20,3 +20,3 @@ import { api, id, task, Action, actionheroVersion } from "actionhero"; | ||
actionheroVersion: "9.4.1", | ||
uptime: 10469 | ||
uptime: 10469, | ||
}; | ||
@@ -34,3 +34,3 @@ } | ||
"Using more than {{maxMemoryAlloted}} MB of RAM/HEAP", | ||
{ maxMemoryAlloted: maxMemoryAlloted } | ||
{ maxMemoryAlloted: maxMemoryAlloted }, | ||
]) | ||
@@ -44,3 +44,3 @@ ); | ||
let length = 0; | ||
Object.keys(details.queues).forEach(q => { | ||
Object.keys(details.queues).forEach((q) => { | ||
length += details.queues[q].length; | ||
@@ -56,3 +56,3 @@ }); | ||
"Resque Queues over {{maxResqueQueueLength}} jobs", | ||
{ maxResqueQueueLength: maxResqueQueueLength } | ||
{ maxResqueQueueLength: maxResqueQueueLength }, | ||
]) | ||
@@ -59,0 +59,0 @@ ); |
const path = require("path"); | ||
export const DEFAULT = { | ||
general: config => { | ||
general: (config) => { | ||
const packageJSON = require("./../../package.json"); | ||
@@ -55,3 +55,3 @@ | ||
src: path.join(process.cwd(), "src"), | ||
dist: path.join(process.cwd(), "dist") | ||
dist: path.join(process.cwd(), "dist"), | ||
}, | ||
@@ -63,9 +63,9 @@ | ||
// 'secureRoom': {authorized: true}, | ||
} | ||
}, | ||
}; | ||
} | ||
}, | ||
}; | ||
export const test = { | ||
general: config => { | ||
general: (config) => { | ||
return { | ||
@@ -75,18 +75,18 @@ serverToken: `serverToken-${process.env.JEST_WORKER_ID || 0}`, | ||
defaultRoom: {}, | ||
otherRoom: {} | ||
otherRoom: {}, | ||
}, | ||
paths: { | ||
locale: [path.join(process.cwd(), "locales")] | ||
locale: [path.join(process.cwd(), "locales")], | ||
}, | ||
rpcTimeout: 3000 | ||
rpcTimeout: 3000, | ||
}; | ||
} | ||
}, | ||
}; | ||
export const production = { | ||
general: config => { | ||
general: (config) => { | ||
return { | ||
fileRequestLogLevel: "debug" | ||
fileRequestLogLevel: "debug", | ||
}; | ||
} | ||
}, | ||
}; |
export const DEFAULT = { | ||
errors: config => { | ||
errors: (config) => { | ||
return { | ||
@@ -12,3 +12,3 @@ _toExpand: false, | ||
servers: { | ||
web: error => { | ||
web: (error) => { | ||
if (error.message) { | ||
@@ -20,3 +20,3 @@ return String(error.message); | ||
}, | ||
websocket: error => { | ||
websocket: (error) => { | ||
if (error.message) { | ||
@@ -28,3 +28,3 @@ return String(error.message); | ||
}, | ||
socket: error => { | ||
socket: (error) => { | ||
if (error.message) { | ||
@@ -36,3 +36,3 @@ return String(error.message); | ||
}, | ||
specHelper: error => { | ||
specHelper: (error) => { | ||
if (error.message) { | ||
@@ -43,4 +43,4 @@ return "Error: " + String(error.message); | ||
} | ||
} | ||
} | ||
}, | ||
}, | ||
}, | ||
@@ -64,3 +64,3 @@ | ||
"actionhero.errors.missingParams", | ||
{ param: missingParams[0] } | ||
{ param: missingParams[0] }, | ||
]); | ||
@@ -70,3 +70,3 @@ }, | ||
// user requested an unknown action | ||
unknownAction: data => { | ||
unknownAction: (data) => { | ||
return data.connection.localize("actionhero.errors.unknownAction"); | ||
@@ -76,6 +76,6 @@ }, | ||
// action not useable by this client/server type | ||
unsupportedServerType: data => { | ||
unsupportedServerType: (data) => { | ||
return data.connection.localize([ | ||
"actionhero.errors.unsupportedServerType", | ||
{ type: data.connection.type } | ||
{ type: data.connection.type }, | ||
]); | ||
@@ -85,3 +85,3 @@ }, | ||
// action failed because server is mid-shutdown | ||
serverShuttingDown: data => { | ||
serverShuttingDown: (data) => { | ||
return data.connection.localize("actionhero.errors.serverShuttingDown"); | ||
@@ -92,3 +92,3 @@ }, | ||
// limit defined in api.config.general.simultaneousActions | ||
tooManyPendingActions: data => { | ||
tooManyPendingActions: (data) => { | ||
return data.connection.localize( | ||
@@ -112,3 +112,3 @@ "actionhero.errors.tooManyPendingActions" | ||
// You may want to load in the content of 404.html or similar | ||
fileNotFound: connection => { | ||
fileNotFound: (connection) => { | ||
return connection.localize(["actionhero.errors.fileNotFound"]); | ||
@@ -118,3 +118,3 @@ }, | ||
// user didn't request a file | ||
fileNotProvided: connection => { | ||
fileNotProvided: (connection) => { | ||
return connection.localize("actionhero.errors.fileNotProvided"); | ||
@@ -127,3 +127,3 @@ }, | ||
"actionhero.errors.fileReadError", | ||
{ error: String(error) } | ||
{ error: String(error) }, | ||
]); | ||
@@ -139,3 +139,3 @@ }, | ||
"actionhero.errors.verbNotFound", | ||
{ verb: verb } | ||
{ verb: verb }, | ||
]); | ||
@@ -147,7 +147,7 @@ }, | ||
"actionhero.errors.verbNotAllowed", | ||
{ verb: verb } | ||
{ verb: verb }, | ||
]); | ||
}, | ||
connectionRoomAndMessage: connection => { | ||
connectionRoomAndMessage: (connection) => { | ||
return connection.localize( | ||
@@ -161,3 +161,3 @@ "actionhero.errors.connectionRoomAndMessage" | ||
"actionhero.errors.connectionNotInRoom", | ||
{ room: room } | ||
{ room: room }, | ||
]); | ||
@@ -169,23 +169,23 @@ }, | ||
"actionhero.errors.connectionAlreadyInRoom", | ||
{ room: room } | ||
{ room: room }, | ||
]); | ||
}, | ||
connectionRoomHasBeenDeleted: room => { | ||
connectionRoomHasBeenDeleted: (room) => { | ||
return "this room has been deleted"; | ||
}, | ||
connectionRoomNotExist: room => { | ||
connectionRoomNotExist: (room) => { | ||
return "room does not exist"; | ||
}, | ||
connectionRoomExists: room => { | ||
connectionRoomExists: (room) => { | ||
return "room exists"; | ||
}, | ||
connectionRoomRequired: room => { | ||
connectionRoomRequired: (room) => { | ||
return "a room is required"; | ||
} | ||
}, | ||
}; | ||
} | ||
}, | ||
}; |
export const DEFAULT = { | ||
servers: { | ||
socket: config => { | ||
socket: (config) => { | ||
return { | ||
@@ -19,6 +19,6 @@ enabled: true, | ||
// Maximum incoming message string length in Bytes (use 0 for Infinite) | ||
maxDataLength: 0 | ||
maxDataLength: 0, | ||
}; | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
@@ -28,3 +28,3 @@ | ||
servers: { | ||
socket: config => { | ||
socket: (config) => { | ||
return { | ||
@@ -38,6 +38,6 @@ enabled: true, | ||
secure: false, | ||
maxDataLength: 999 | ||
maxDataLength: 999, | ||
}; | ||
} | ||
} | ||
}, | ||
}, | ||
}; |
export const DEFAULT = { | ||
servers: { | ||
web: config => { | ||
web: (config) => { | ||
return { | ||
enabled: false | ||
enabled: false, | ||
}; | ||
} | ||
} | ||
}, | ||
}, | ||
}; |
export const DEFAULT = { | ||
servers: { | ||
websocket: config => { | ||
websocket: (config) => { | ||
return { | ||
enabled: false | ||
enabled: false, | ||
}; | ||
} | ||
} | ||
}, | ||
}, | ||
}; |
@@ -30,4 +30,4 @@ import * as net from "net"; | ||
"detailsView", | ||
"say" | ||
] | ||
"say", | ||
], | ||
}; | ||
@@ -44,3 +44,3 @@ } | ||
this.config.serverOptions, | ||
rawConnection => { | ||
(rawConnection) => { | ||
this.handleConnection(rawConnection); | ||
@@ -52,3 +52,3 @@ } | ||
this.config.serverOptions, | ||
rawConnection => { | ||
(rawConnection) => { | ||
this.handleConnection(rawConnection); | ||
@@ -59,3 +59,3 @@ } | ||
this.server.on("error", error => { | ||
this.server.on("error", (error) => { | ||
throw new Error( | ||
@@ -66,11 +66,11 @@ `Cannot start socket server @ ${this.config.bindIP}:${this.config.port} => ${error.message}` | ||
await new Promise(resolve => { | ||
await new Promise((resolve) => { | ||
this.server.listen(this.config.port, this.config.bindIP, resolve); | ||
}); | ||
this.on("connection", async connection => { | ||
this.on("connection", async (connection) => { | ||
await this.onConnection(connection); | ||
}); | ||
this.on("actionComplete", data => { | ||
this.on("actionComplete", (data) => { | ||
if (data.toRender === true) { | ||
@@ -115,3 +115,3 @@ data.response.context = "response"; | ||
status: connection.localize("actionhero.goodbyeMessage"), | ||
context: "api" | ||
context: "api", | ||
}) + "\r\n" | ||
@@ -143,3 +143,3 @@ ); | ||
remoteAddress: rawConnection.remoteAddress, | ||
remotePort: rawConnection.remotePort | ||
remotePort: rawConnection.remotePort, | ||
}); | ||
@@ -151,3 +151,3 @@ } | ||
connection.rawConnection.on("data", async chunk => { | ||
connection.rawConnection.on("data", async (chunk) => { | ||
if (this.checkBreakChars(chunk)) { | ||
@@ -187,3 +187,3 @@ connection.destroy(); | ||
connection.rawConnection.on("error", e => { | ||
connection.rawConnection.on("error", (e) => { | ||
if (connection.destroyed !== true) { | ||
@@ -210,3 +210,3 @@ this.log("socket error: " + e, "error"); | ||
error: error, | ||
context: "response" | ||
context: "response", | ||
}, | ||
@@ -294,3 +294,3 @@ null | ||
let pendingConnections = 0; | ||
this.connections().forEach(connection => { | ||
this.connections().forEach((connection) => { | ||
if (connection.pendingActions === 0) { | ||
@@ -314,3 +314,3 @@ connection.destroy(); | ||
); | ||
await new Promise(resolve => { | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, 1000); | ||
@@ -317,0 +317,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
![](documentation.svg) | ||
# actionhero-socket-server | ||
@@ -45,13 +45,13 @@ ## Overview | ||
* `quit` disconnect from the session | ||
* `paramAdd` - save a singe variable to your connection. IE: ‘addParam screenName=evan' | ||
* `paramView` - returns the details of a single param. IE: ‘viewParam screenName' | ||
* `paramDelete` - deletes a single param. IE: `deleteParam screenName` | ||
* `paramsView` - returns a JSON object of all the params set to this connection | ||
* `paramsDelete` - deletes all params set to this session | ||
* `roomAdd` - connect to a room. | ||
* `roomLeave` - (room) leave the `room` you are connected to. | ||
* `roomView` - (room) show you the room you are connected to, and information about the members currently in that room. | ||
* `detailsView` - show you details about your connection, including your public ID. | ||
* `say` (room,) message | ||
- `quit` disconnect from the session | ||
- `paramAdd` - save a singe variable to your connection. IE: ‘addParam screenName=evan' | ||
- `paramView` - returns the details of a single param. IE: ‘viewParam screenName' | ||
- `paramDelete` - deletes a single param. IE: `deleteParam screenName` | ||
- `paramsView` - returns a JSON object of all the params set to this connection | ||
- `paramsDelete` - deletes all params set to this session | ||
- `roomAdd` - connect to a room. | ||
- `roomLeave` - (room) leave the `room` you are connected to. | ||
- `roomView` - (room) show you the room you are connected to, and information about the members currently in that room. | ||
- `detailsView` - show you details about your connection, including your public ID. | ||
- `say` (room,) message | ||
@@ -62,3 +62,3 @@ Please note that any verbs set using the above method will be sticky to the connection and sent for all subsequent requests. Be sure to delete or update your params before your next request. | ||
Every message returned also contains a `messageId`, starting from 1, which increments to count a response to each client request. `say` messages do not increment `messageId`, which allows this count to be used by the client to map responses to queries. | ||
Every message returned also contains a `messageId`, starting from 1, which increments to count a response to each client request. `say` messages do not increment `messageId`, which allows this count to be used by the client to map responses to queries. | ||
@@ -70,7 +70,7 @@ `connection.type` for a TCP/Socket client is "socket" | ||
```js | ||
exports['default'] = { | ||
exports["default"] = { | ||
servers: { | ||
socket: function (api) { | ||
return { | ||
enabled: (process.env.ENABLE_TCP_SERVER !== undefined), | ||
enabled: process.env.ENABLE_TCP_SERVER !== undefined, | ||
// TCP or TLS? | ||
@@ -83,13 +83,13 @@ secure: false, | ||
// Which IP to listen on (use 0.0.0.0 for all) | ||
bindIP: '0.0.0.0', | ||
bindIP: "0.0.0.0", | ||
// Enable TCP KeepAlive pings on each connection? | ||
setKeepAlive: false, | ||
// Delimiter string for incoming messages | ||
delimiter: '\n', | ||
delimiter: "\n", | ||
// Maximum incoming message string length in Bytes (use 0 for Infinite) | ||
maxDataLength: 0 | ||
} | ||
} | ||
} | ||
} | ||
maxDataLength: 0, | ||
}; | ||
}, | ||
}, | ||
}; | ||
``` | ||
@@ -109,5 +109,5 @@ | ||
serverOptions: { | ||
key: fs.readFileSync('certs/server-key.pem'), | ||
cert: fs.readFileSync('certs/server-cert.pem') | ||
} | ||
key: fs.readFileSync("certs/server-key.pem"), | ||
cert: fs.readFileSync("certs/server-cert.pem"), | ||
}, | ||
}; | ||
@@ -122,21 +122,24 @@ ``` | ||
// Connecting over TLS from another node process | ||
const tls = require('tls'); | ||
const fs = require('fs'); | ||
const tls = require("tls"); | ||
const fs = require("fs"); | ||
const options = { | ||
key: fs.readFileSync('certs/server-key.pem'), | ||
cert: fs.readFileSync('certs/server-cert.pem') | ||
key: fs.readFileSync("certs/server-key.pem"), | ||
cert: fs.readFileSync("certs/server-cert.pem"), | ||
}; | ||
const cleartextStream = tls.connect(5000, options, () => { | ||
console.log('client connected', cleartextStream.authorized ? 'authorized' : 'unauthorized'); | ||
console.log( | ||
"client connected", | ||
cleartextStream.authorized ? "authorized" : "unauthorized" | ||
); | ||
process.stdin.pipe(cleartextStream); | ||
process.stdin.resume(); | ||
}) | ||
}); | ||
cleartextStream.setEncoding('utf8') | ||
cleartextStream.setEncoding("utf8"); | ||
cleartextStream.on('data', function(data) { | ||
console.log(data) | ||
}) | ||
cleartextStream.on("data", function (data) { | ||
console.log(data); | ||
}); | ||
``` | ||
@@ -148,4 +151,4 @@ | ||
* Errors are returned in the normal way `{error: someError}` when they exist. | ||
* A successful file transfer will return the raw file data in a single send(). There will be no headers set, nor will the content be JSON. Plan accordingly! | ||
- Errors are returned in the normal way `{error: someError}` when they exist. | ||
- A successful file transfer will return the raw file data in a single send(). There will be no headers set, nor will the content be JSON. Plan accordingly! | ||
@@ -168,3 +171,3 @@ ``` | ||
* `{"action": "myAction", "params": {"key": "value"}}` is also a valid request over TCP | ||
- `{"action": "myAction", "params": {"key": "value"}}` is also a valid request over TCP | ||
@@ -180,51 +183,56 @@ ## Client Suggestions | ||
```js | ||
const path = require('path') | ||
const ActionheroNodeClient = require(path.join(__dirname, 'lib', 'client.js')) | ||
const path = require("path"); | ||
const ActionheroNodeClient = require(path.join(__dirname, "lib", "client.js")); | ||
async function main () { | ||
const client = new ActionheroNodeClient() | ||
async function main() { | ||
const client = new ActionheroNodeClient(); | ||
client.on('say', (message) => { | ||
console.log(' > SAY: ' + message.message + ' | from: ' + message.from) | ||
}) | ||
client.on("say", (message) => { | ||
console.log(" > SAY: " + message.message + " | from: " + message.from); | ||
}); | ||
client.on('welcome', (welcome) => { | ||
console.log('WELCOME: ' + welcome) | ||
}) | ||
client.on("welcome", (welcome) => { | ||
console.log("WELCOME: " + welcome); | ||
}); | ||
client.on('error', (error) => { | ||
console.log('ERROR: ' + error) | ||
}) | ||
client.on("error", (error) => { | ||
console.log("ERROR: " + error); | ||
}); | ||
client.on('end', () => { | ||
console.log('Connection Ended') | ||
}) | ||
client.on("end", () => { | ||
console.log("Connection Ended"); | ||
}); | ||
client.on('timeout', (request, caller) => { | ||
console.log(request + ' timed out') | ||
}) | ||
client.on("timeout", (request, caller) => { | ||
console.log(request + " timed out"); | ||
}); | ||
await client.connect({host: '127.0.0.1', port: '5000'}) | ||
await client.connect({ host: "127.0.0.1", port: "5000" }); | ||
// get details about myself | ||
console.log('My Details: ', client.details) | ||
console.log("My Details: ", client.details); | ||
// try an action | ||
const params = { key: 'mykey', value: 'myValue' } | ||
let {error, data, delta} = await client.actionWithParams('cacheTest', params) | ||
if (error) { throw error } | ||
console.log('cacheTest action response: ', data) | ||
console.log(' ~ request duration: ', delta) | ||
const params = { key: "mykey", value: "myValue" }; | ||
let { error, data, delta } = await client.actionWithParams( | ||
"cacheTest", | ||
params | ||
); | ||
if (error) { | ||
throw error; | ||
} | ||
console.log("cacheTest action response: ", data); | ||
console.log(" ~ request duration: ", delta); | ||
// join a chat room and talk | ||
await client.roomAdd('defaultRoom') | ||
await client.say('defaultRoom', 'Hello from the actionheroClient') | ||
await client.roomLeave('defaultRoom') | ||
await client.roomAdd("defaultRoom"); | ||
await client.say("defaultRoom", "Hello from the actionheroClient"); | ||
await client.roomLeave("defaultRoom"); | ||
// leave | ||
await client.disconnect() | ||
console.log('all done!') | ||
await client.disconnect(); | ||
console.log("all done!"); | ||
} | ||
main() | ||
main(); | ||
``` |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
91
0
0
58844
20
1307