Skip to content

Commit

Permalink
test:dynamic websocket url generation
Browse files Browse the repository at this point in the history
  • Loading branch information
romansavych committed Jun 15, 2021
1 parent dd1ef56 commit 2f17734
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions frontend/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,17 @@ export default new Vuex.Store({
}
}
},

//@ts-ignore
setupConnection({ commit }, { id, type, onOpen }) {
const connection = new WebSocket(`${process.env.VUE_APP_WEBSOCKET_URL}/${id}/`);
let connection;
if (process.env.VUE_APP_WEBSOCKET_URL.includes('ws:/') || process.env.VUE_APP_WEBSOCKET_URL.includes('wss:/')) {
connection = new WebSocket(`${process.env.VUE_APP_WEBSOCKET_URL}/${id}/`);
} else {
let protocol = window.location.protocol;
let socketProtocol = protocol.includes('http') ? 'ws' : 'wss';
let socketPath = `${socketProtocol}://${window.location.host}/api/ws/${id}/`;
connection = new WebSocket(socketPath);
}

connection.onmessage = (event) => {
const data = JSON.parse(event.data);
Expand Down

0 comments on commit 2f17734

Please sign in to comment.