mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
try to force the correct url (ws: or wss:) on the socket when it's created
This commit is contained in:
parent
46dae02d47
commit
8be2efbe48
1 changed files with 19 additions and 12 deletions
|
|
@ -21,11 +21,18 @@ class WebSocketService {
|
|||
private socket: Socket | null = null;
|
||||
|
||||
connect(backendUrl: string): Socket {
|
||||
// console.log(backendUrl);
|
||||
this.socket = io(`${backendUrl}`, {
|
||||
console.log(`WebSocketService.connect(${backendUrl})`);
|
||||
|
||||
// Ensure the URL uses wss: if the page is loaded over https:
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const url = backendUrl.replace(/^http:/, protocol);
|
||||
console.log(`WebSocketService.connect: changed url=${url}`);
|
||||
|
||||
this.socket = io(url, {
|
||||
transports: ['websocket'],
|
||||
reconnectionAttempts: 1
|
||||
});
|
||||
|
||||
return this.socket;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue