You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am running a React JS application to connect to a local Spring Boot service. When running .activate(), this error shows up:
Uncaught runtime errors:ERRORWebSocket is not a constructorTypeError: WebSocket is not a constructor at Client._createWebSocket (http://localhost:3000/static/js/bundle.js:185684:19) at Client._connect (http://localhost:3000/static/js/bundle.js:185618:28)
Code
I implemented a web socket handler class
import{Client}from'@stomp/stompjs';import{WebSocket}from'ws';Object.assign(global,{ WebSocket });
...
classWebSocketHelper{constructor(serverUrl='ws://localhost:8080/websocket'){this.serverUrl=serverUrl;this.cryptoHelper=newCryptoHelper(seed);this.users={};this.groups={};this.stompClient=newClient({brokerURL: serverUrl,onConnect: (frame)=>{console.log("connected to the server");this.stompClient.subscribe("/user/queue/listen",(packet)=>{packet=Array.from(packet._binaryBody);this.parse_packet(this.cryptoHelper.decrypt_packet(packet));});},onWebSocketError: (error)=>{console.error("Websocket error: ",error);},onStompError: (frame)=>{console.error("Stomp error: ",frame.headers.message);},});console.log("Connecting to the server");this.stompClient.activate();}
...
The error is triggered when calling the .activate() method
Error Description
I am running a React JS application to connect to a local Spring Boot service. When running
.activate()
, this error shows up:Code
I implemented a web socket handler class
The error is triggered when calling the
.activate()
methodDependency Versions
The text was updated successfully, but these errors were encountered: