Open fundon opened 6 years ago
Unfortunatly this client was designing only for browsers, there are plans to build node version but it would be as separate project.
Thanks, ASAP. :)
That looks pretty good :)
So is this now a part of the release? because I still get this error
var Socket = window.MozWebSocket || window.WebSocket, ClusterWS = function() {
^
ReferenceError: window is not defined
@slidenerd not yet, i am planning to include that in next release for now you can use fork. Make sure u use uws version 10.148.1 without ^ at the front.
Will be in version 4.0 (probable separate repository or different deploy build to do not ship useless deps and code with browser version)
btw, putting this before you require clusterws-client-js lets this work in node:
global.window = {WebSocket: require('ws')};
@aequasi that is a good solutions :)ws
API should be the same as browsers ws
(i think that ws
supports it so it should work ok)
You should also be able to do global.window = {WebSocket: require('@clusterws/cws').WebSocket};
, but i havent tested it
@aequasi that one will not work out as cws
does not have browser interface (i will probably add it) cws
uses event based interface so instead of writing
ws.onopen = function() {
// some logic
}
you need to write:
ws.on("open", () => {
// some logic
})
i will probably write a simple wrapper for cws
to handle browser interface, thanks for the tip :)
I have release version 0.9.0 of @clusterws/cws
with browser interface support and from now @aequasi proposal should work correctly:
global.window = {WebSocket: require('@clusterws/cws').WebSocket}
@goriunov I'm not sure if this is related to this, but I'm using @clusterws/cws
version 0.10.0 and I get this error when I establish a connection to the server or receive any message:
SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at websocket.onmessage (/home/vlad/NodeJS/clusterws-test/node_modules/clusterws-client-js/index.js:145:32)
at WebSocket.emit (/home/vlad/NodeJS/clusterws-test/node_modules/@clusterws/cws/dist/index.js:19:14)
at native.client.group.onMessage (/home/vlad/NodeJS/clusterws-test/node_modules/@clusterws/cws/dist/index.js:40:7)
The server receives messages just fine, but if I send something back to the client I get that error, the message is always a JSON object.
I haven't tried the library in the browser, but I do want to use this to write some server-side tests.
If I use the standard ws
module, I don't get any errors, but obviously sending data does not work (only establishing the connection)
@vladikus10 can you try updating clusterws-client-js
to version 3.2.0
, and if it works let me know :)
@goriunov Updated and the error is gone, thanks!
@goriunov In Node.js, Blob
and FileReader
are missing. New v4 alpha version.
https://github.com/ClusterWS/ClusterWS-Client-JS/blob/next/src/index.ts#L221-L226
@fundon thanks, i have not yet tested with Node, will have look soon :)
@fundon just released new version alpha 2 with that fix, thank you :)
Submitting
Details