question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebSocketClient is not a constructor

See original GitHub issue

I am using browserify to run lgtv in the browser, and lgtv uses websocket.client for communication with TV.

However, when I use the bundled .js that was given to me by browserify, I got this error: Uncaught TypeError: WebSocketClient is not a constructor

Here is some code from the bundled .js file:

var WebSocketClient = require('websocket').client; // for communication with TV
var client = new WebSocketClient();

The problematic line is this: var client = new WebSocketClient();

Can anyone help?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:14

github_iconTop GitHub Comments

21reactions
ibccommented, Feb 11, 2019

Guys, in browser you cannot use WebSocketClient class as it’s just for Node (it uses Node stuff not available in the browser).

In the browser you should just use the native WebSocket class. And, just if you are developing an app that must run in browser and Node and must behave as a WebSocket client, then use:

var W3CWebSocket = require(‘websocket’).w3cwebsocket;

In fact, when in the browser, such a W3CWebSocket class is just an alias to the native browser WebSocket class. And in Node it’s just a wrapper over Node-WebSocket.WebSocketClient that offers an API similar to the W3 WebSocket class in the browser.

3reactions
isurugajasinghecommented, Mar 29, 2018

Still have a same issue. Pls check and let me know pls

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: WebSocketClient is not a constructor
I have exported websocket using browserify , browserify -r websocket > bundle.js. Then I try to run following code in my browser
Read more >
WebSocket is not a constructor - Bugzilla@Mozilla
Calling `new WebSocket()` results in a TypeError: "WebSocket is not a constructor".
Read more >
Uncaught TypeError: WebSocketClient is not a constructor
Anyone else getting this? My code is as follows... const wsUri = "ws://localhost:8080/prices/websocket"; const client = Stomp.overWS(wsUri);.
Read more >
RSocketWebsocketClient - rsocket-js
The RSocketWebsocketClient implements the RScocket protocol using the WebSocket network transport protocol, and is suitable for Server to Server, and Client ...
Read more >
Class WebSocketClient - Terra.js
An object repesenting a connection to a Terra node's WebSocket RPC endpoint. ... 0 for not to attempt reconnect, -1 for infinite, >...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found