mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-01-23 10:35:44 +00:00
Make it choose ws/wss protocol based on URL's protocol. (#196)
When you open the app with https: protocol it will chose wss secured socket connection instead of hardcoded addresses / domains.
This commit is contained in:
parent
42d7e166e8
commit
27f8fdc117
1 changed files with 4 additions and 9 deletions
13
web/js/network/socket.js
vendored
13
web/js/network/socket.js
vendored
|
|
@ -30,15 +30,10 @@ const socket = (() => {
|
|||
let curPacketId = '';
|
||||
|
||||
const init = (roomId, zone) => {
|
||||
const paramString = new URLSearchParams({room_id: roomId, zone: zone})
|
||||
|
||||
// if localhost, local LAN connection
|
||||
if (location.hostname === "localhost" || location.hostname === "127.0.0.1" || location.hostname.startsWith("192.168")) {
|
||||
scheme = "ws"
|
||||
} else {
|
||||
scheme = "wss"
|
||||
}
|
||||
conn = new WebSocket(`${scheme}://${location.host}/ws?${paramString.toString()}`);
|
||||
const params = new URLSearchParams({room_id: roomId, zone: zone}).toString()
|
||||
const address = `${location.protocol !== 'https:' ? 'ws' : 'wss'}://${location.host}/ws?${params}`;
|
||||
console.info(`[ws] connecting to ${address}`);
|
||||
conn = new WebSocket(address);
|
||||
|
||||
// Clear old roomID
|
||||
conn.onopen = () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue