feat: use wss:// if https
This commit is contained in:
@@ -15,8 +15,15 @@ pub struct WebsocketService {
|
||||
|
||||
impl WebsocketService {
|
||||
pub fn connect() -> Self {
|
||||
let hostname = web_sys::window().unwrap().location().hostname().unwrap();
|
||||
let ws_addr = format!("ws://{hostname}:4000/ws");
|
||||
let window = web_sys::window().expect("no global `window` exists");
|
||||
let location = window.location();
|
||||
let hostname = location.hostname().expect("should have a hostname");
|
||||
let protocol = match location.protocol().expect("should have a protocol").as_str() {
|
||||
"https:" => "wss",
|
||||
_ => "ws",
|
||||
};
|
||||
|
||||
let ws_addr = format!("{protocol}://{hostname}:4000/ws");
|
||||
let ws = WebSocket::open(&ws_addr).unwrap();
|
||||
log::info!("Opened websocket connection to {ws_addr}");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user