Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Cant run in Node #44

Open
1 of 4 tasks
fundon opened this issue May 14, 2018 · 18 comments
Open
1 of 4 tasks

Cant run in Node #44

fundon opened this issue May 14, 2018 · 18 comments
Assignees

Comments

@fundon
Copy link

fundon commented May 14, 2018

Submitting

  • Bug
  • Question
  • Suggetion
  • Other

Details

ReferenceError: window is not defined
    at Object.<anonymous> (node_modules/clusterws-client-js/index.js:86:14)
   at Module._compile (module.js:652:30)
@goriunov
Copy link
Member

goriunov commented May 15, 2018

Unfortunatly this client was designing only for browsers, there are plans to build node version but it would be as separate project.

@fundon
Copy link
Author

fundon commented May 15, 2018

Thanks, ASAP. :)

@fundon
Copy link
Author

fundon commented May 15, 2018

fundon@66deec3#diff-f41e9d04a45c83f3b6f6e630f10117fe

@goriunov
Copy link
Member

That looks pretty good :)

@goriunov goriunov self-assigned this Jun 16, 2018
@slidenerd
Copy link

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

@goriunov
Copy link
Member

goriunov commented Sep 3, 2018

@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.

@goriunov
Copy link
Member

Will be in version 4.0 (probable separate repository or different deploy build to do not ship useless deps and code with browser version)

@cryptiklemur
Copy link

btw, putting this before you require clusterws-client-js lets this work in node:

global.window = {WebSocket: require('ws')};

@goriunov
Copy link
Member

goriunov commented Dec 9, 2018

@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)

@cryptiklemur
Copy link

You should also be able to do global.window = {WebSocket: require('@clusterws/cws').WebSocket};, but i havent tested it

@goriunov
Copy link
Member

goriunov commented Dec 11, 2018

@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 :)

@goriunov
Copy link
Member

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}

@vladikus10
Copy link

vladikus10 commented Jan 11, 2019

@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)

@goriunov
Copy link
Member

@vladikus10 can you try updating clusterws-client-js to version 3.2.0, and if it works let me know :)

@vladikus10
Copy link

@goriunov Updated and the error is gone, thanks!

@fundon
Copy link
Author

fundon commented May 20, 2019

@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

@goriunov
Copy link
Member

@fundon thanks, i have not yet tested with Node, will have look soon :)

@goriunov
Copy link
Member

@fundon just released new version alpha 2 with that fix, thank you :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants