How to send query_string when connecting to websocket

Viewed 19

I would like to send a query_string when I connect to a websocket. Not sure how I would go about doing this. Here is the method I am currently using to connect to the websocket:

connect() {
const path = 'ws://127.0.0.1:8000/connect/testing/';
this.socketRef = new WebSocket(path);
this.socketRef['query_string'] = 27
 this.socketRef.onopen = (data) => {
      console.log('WebSocket open');
      }
    this.socketRef.onerror = e => {
      console.log(e.message);
    };
    this.socketRef.onclose = () => {
      console.log("WebSocket closed let's reopen");
      this.connect();
    };
  }

UPDATE

I have tried appending the query string to the path:

connect(args) {
const queryString = args.access
console.log('queryString', queryString)
const path = `ws://127.0.0.1:8000/connect/testing/?${this.args}`;
this.socketRef = new WebSocket(path);
this.socketRef.onopen = (data) => {
    console.log('WebSocket open');
  }

However, when I print the scope in the websocket, I get undefined for the query_string

0 Answers
Related