bashlund / pocket-sockets Goto Github PK
View Code? Open in Web Editor NEWSmall Websockets and TCP client/server sockets library written in TypeScript with support for TLS encryption. Runs in browser and NodeJS.
License: MIT License
Small Websockets and TCP client/server sockets library written in TypeScript with support for TLS encryption. Runs in browser and NodeJS.
License: MIT License
First added in 340abd2
Suppose WSClient::connect
successfully triggering socketHook
and throwing an error during execution inside the browser:
Firefox can’t establish a connection to the server at ws://<example_host>:<example_port>/.
The following error may occur:
Uncaught TypeError: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
Considering error
is defined as:
function error(error)
In cases where error.message
is undefined, an error will get thrown.
According to Mozilla Developer Network, that seems to be the default in browser:
Event type
A generic Event.
Link: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/error_event
https://github.com/bashlund/pocket-sockets/blob/main/src/WSClient.ts#L141
That should be changed to prevent calling Buffer.from
with bad input.
Possible fix:
this.socketError(Buffer.from(error.message ? error.message : ""));
Add a way to perform valid end-to-end/integration tests to verify web part of sockets is working as intended
First added in adce50a
Some of the code added in 782e9c0 is not covered by existing tests.
This is also true for public pair(pairedSocket: VirtualClient)
Considering server events start with onServer*
and the fact that the connect error is mapped to CLIENT_CONNECT_ERROR
, it would make sense to rename the event to something like onClientConnectError
instead.
There have been various issues with validation which may or may not be related to cache invalidation.
Possible alternatives:
How could a port be closed after a certain time has elapsed without receiving data. I am using the example server "example-tcp.ts"
Tests would be more complete if set up was done against locally available socket server instead of dummy serverOptions
(host.com
).
Apart from empty initialization, the only line which assigns data to serverClientSockets
is the following:
this.serverClientSockets = this.serverClientSockets.filter( (socket2: Client) => { ...
https://github.com/bashlund/pocket-sockets/blob/main/src/SocketFactory.ts#L331
A push to that array is likely 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.