streamerbot / client Goto Github PK
View Code? Open in Web Editor NEWStreamer.bot WebSocket client
Home Page: https://streamerbot.github.io/client/
License: MIT License
Streamer.bot WebSocket client
Home Page: https://streamerbot.github.io/client/
License: MIT License
Hey,
Newer node versions have started notifying about suboptimal handling of event emitters.
This is Node 20.5.0
Instead of blindly increasing the limit, I've dug into the actual problem it's notifying about and it comes back to the request method the lib uses under the hood.
Basically every time a request is made, a new eventListener to the message is assigned without ever cleaning them up.
Normally with websockets, you only ever attach a single eventListener to the existing socket, and that listener does all the processing and dispatching of the work.
The current implementation feels like it's trying to mimic a traditional HTTP request roundtrip.
You could try removing the attached listener but that might actually be more work and error prone than refactoring it to behave more like a websocket implementation
It's me again! Thank you so much for your quick reply and addressing of my last issue #1. I am now running into another issue when trying to get WebSockets running on a Node app.
The issue seems to come down to the WebSocket connection closing too quickly before it can be used. Note the _readyState
of 2
(i.e. Closing) in the error below when using connect()
.
getActions()
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
^
Error: WebSocket is not open: readyState 0 (CONNECTING)
at WebSocket.send (E:\Projects\Software\streamerbot-tools\sb-client\node_modules\ws\lib\websocket.js:442:13)
at StreamerbotClient.send (file:///sb-client/node_modules/@streamerbot/client/dist/index.js:339:46)
at file:///sb-client/node_modules/@streamerbot/client/dist/index.js:388:16
at new Promise (<anonymous>)
at StreamerbotClient.<anonymous> (file:///sb-client/node_modules/@streamerbot/client/dist/index.js:358:9)
at Generator.next (<anonymous>)
at file:///sb-client/node_modules/@streamerbot/client/dist/index.js:37:61
at new Promise (<anonymous>)
at __async (file:///sb-client/node_modules/@streamerbot/client/dist/index.js:21:10)
at StreamerbotClient.request (file:///sb-client/node_modules/@streamerbot/client/dist/index.js:342:12)
connect()
WebSocket Error ErrorEvent {
[Symbol(kTarget)]: WebSocket {
_events: [Object: null prototype] {
open: [Function],
close: [Function],
error: [Function],
message: [Function]
},
_eventsCount: 4,
_maxListeners: undefined,
_binaryType: 'nodebuffer',
_closeCode: 1006,
_closeFrameReceived: false,
_closeFrameSent: false,
_closeMessage: <Buffer >,
_closeTimer: null,
_extensions: {},
_paused: false,
_protocol: '',
_readyState: 2,
_receiver: null,
_sender: null,
_socket: null,
_bufferedAmount: 0,
_isServer: false,
_redirects: 0,
_url: 'ws://127.0.0.1:8080/',
_req: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
outputData: [Array],
outputSize: 223,
writable: true,
destroyed: true,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: true,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: null,
_header: 'GET / HTTP/1.1\r\n' +
'Sec-WebSocket-Version: 13\r\n' +
'Sec-WebSocket-Key: GBuyJi1SQiZOQQq7y9ofmw==\r\n' +
'Connection: Upgrade\r\n' +
'Upgrade: websocket\r\n' +
'Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n' +
'Host: 127.0.0.1:8080\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: undefined,
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/',
_ended: false,
res: null,
aborted: true,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: '127.0.0.1',
protocol: 'http:',
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype],
[Symbol(kAborted)]: true,
[Symbol(kError)]: undefined
},
[Symbol(kCapture)]: false
},
[Symbol(kType)]: 'error',
[Symbol(kError)]: Error: WebSocket was closed before the connection was established
at WebSocket.close (E:\Projects\Software\streamerbot-tools\sb-client\node_modules\ws\lib\websocket.js:285:7)
at StreamerbotClient.disconnect (file:///sb-client/node_modules/@streamerbot/client/dist/index.js:237:17)
at StreamerbotClient.<anonymous> (file:///sb-client/node_modules/@streamerbot/client/dist/index.js:211:12)
at Generator.next (<anonymous>)
at file:///sb-client/node_modules/@streamerbot/client/dist/index.js:37:61
at new Promise (<anonymous>)
at __async (file:///sb-client/node_modules/@streamerbot/client/dist/index.js:21:10)
at StreamerbotClient.connect (file:///sb-client/node_modules/@streamerbot/client/dist/index.js:209:12)
at file:///sb-client/index.js:4:16
at ModuleJob.run (node:internal/modules/esm/module_job:185:25),
[Symbol(kMessage)]: 'WebSocket was closed before the connection was established'
}
Reconnecting... (attempt 0)
Reconnecting... (attempt 0)
As before, the code is pretty simple.
import * as streamerbotClient from '@streamerbot/client';
const sbClient = new streamerbotClient.StreamerbotClient();
await sbClient.connect();
// await sbClient.getActions();
I've validated my connection settings and that my Streamer.bot client websocket server is started. In fact if I stop it, or change the host or port on the StreamerbotClient()
, I get connection refused messages, or messages telling me the server is not started/does not exist.
Thank you again in advance!
I am running into ReferenceError errors when trying to use the @streamerbot/client
inside of a simple Node app. Specifically, WebSockets, and sometimes Crypto, can't be found. Hopefully I'm just missing something simple.
This is the entirety of the code I am trying.
import { StreamerbotClient } from '@streamerbot/client';
const sbClient = new StreamerbotClient();
const myActions = await sbClient.getActions();
When running it, I get the following error:
file:///sb-client/node_modules/@streamerbot/client/dist/index.js:154
return `sb:client:req:${Date.now()}-${crypto.getRandomValues(new Uint32Array(12))[0]}`;
^
ReferenceError: crypto is not defined
at generateRequestId (file:///sb-client/node_modules/←[4m@streamerbot←[24m/client/dist/index.js:154:41)
at StreamerbotClient.<anonymous> (file:///sb-client/node_modules/←[4m@streamerbot←[24m/client/dist/index.js:336:14)
at Generator.next (<anonymous>)
at file:///sb-client/node_modules/←[4m@streamerbot←[24m/client/dist/index.js:37:61
at new Promise (<anonymous>)
at __async (file:///sb-client/node_modules/←[4m@streamerbot←[24m/client/dist/index.js:21:10)
at StreamerbotClient.request (file:///sb-client/node_modules/←[4m@streamerbot←[24m/client/dist/index.js:334:12)
at StreamerbotClient.<anonymous> (file:///sb-client/node_modules/←[4m@streamerbot←[24m/client/dist/index.js:487:25)
at Generator.next (<anonymous>)
at file:///sb-client/node_modules/←[4m@streamerbot←[24m/client/dist/index.js:37:61
I also ran multiple iterations of npm install
to try and make sure things were installed
npm install
npm install @streamerbot/client
npm install crypto
npm install ws
Thank you in advance! Again, hopefully it's something simple I'm missing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.