web: connect to the correct ws endpoint in production
This commit is contained in:
parent
7bb2f405da
commit
aca6bce1ff
@ -62,7 +62,7 @@ pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
|||||||
},
|
},
|
||||||
catchup: None,
|
catchup: None,
|
||||||
last_url: Url::current(),
|
last_url: Url::current(),
|
||||||
websocket: websocket::init(&mut orders.proxy(Msg::WebSocket)),
|
websocket: websocket::init("/api/ws", &mut orders.proxy(Msg::WebSocket)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -78,13 +78,14 @@ pub struct ClientMessage {
|
|||||||
|
|
||||||
//const WS_URL: &str = "wss://9000.z.xinu.tv/api/ws";
|
//const WS_URL: &str = "wss://9000.z.xinu.tv/api/ws";
|
||||||
//const WS_URL: &str = "wss://9345.z.xinu.tv/api/graphql/ws";
|
//const WS_URL: &str = "wss://9345.z.xinu.tv/api/graphql/ws";
|
||||||
const WS_URL: &str = "wss://6758.z.xinu.tv/api/ws";
|
//const WS_URL: &str = "wss://6758.z.xinu.tv/api/ws";
|
||||||
|
|
||||||
// ------ ------
|
// ------ ------
|
||||||
// Model
|
// Model
|
||||||
// ------ ------
|
// ------ ------
|
||||||
|
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
|
ws_url: String,
|
||||||
web_socket: EventClient,
|
web_socket: EventClient,
|
||||||
web_socket_reconnector: Option<StreamHandle>,
|
web_socket_reconnector: Option<StreamHandle>,
|
||||||
pub updates: VecDeque<WebsocketMessage>,
|
pub updates: VecDeque<WebsocketMessage>,
|
||||||
@ -94,9 +95,10 @@ pub struct Model {
|
|||||||
// Init
|
// Init
|
||||||
// ------ ------
|
// ------ ------
|
||||||
|
|
||||||
pub fn init(orders: &mut impl Orders<Msg>) -> Model {
|
pub fn init(ws_url: &str, orders: &mut impl Orders<Msg>) -> Model {
|
||||||
Model {
|
Model {
|
||||||
web_socket: create_websocket(orders).unwrap(),
|
ws_url: ws_url.to_string(),
|
||||||
|
web_socket: create_websocket(ws_url, orders).unwrap(),
|
||||||
web_socket_reconnector: None,
|
web_socket_reconnector: None,
|
||||||
updates: VecDeque::new(),
|
updates: VecDeque::new(),
|
||||||
}
|
}
|
||||||
@ -155,7 +157,7 @@ Reason: {2}
|
|||||||
}
|
}
|
||||||
Msg::ReconnectWebSocket(retries) => {
|
Msg::ReconnectWebSocket(retries) => {
|
||||||
info!("Reconnect attempt: {}", retries);
|
info!("Reconnect attempt: {}", retries);
|
||||||
model.web_socket = create_websocket(orders).unwrap();
|
model.web_socket = create_websocket(&model.ws_url, orders).unwrap();
|
||||||
}
|
}
|
||||||
Msg::SendMessage(msg) => {
|
Msg::SendMessage(msg) => {
|
||||||
let txt = serde_json::to_string(&msg).unwrap();
|
let txt = serde_json::to_string(&msg).unwrap();
|
||||||
@ -164,10 +166,10 @@ Reason: {2}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_websocket(orders: &impl Orders<Msg>) -> Result<EventClient, WebSocketError> {
|
fn create_websocket(url: &str, orders: &impl Orders<Msg>) -> Result<EventClient, WebSocketError> {
|
||||||
let msg_sender = orders.msg_sender();
|
let msg_sender = orders.msg_sender();
|
||||||
|
|
||||||
let mut client = EventClient::new(WS_URL)?;
|
let mut client = EventClient::new(url)?;
|
||||||
|
|
||||||
client.set_on_error(Some(Box::new(|error| {
|
client.set_on_error(Some(Box::new(|error| {
|
||||||
gloo_console::error!("WS: ", error);
|
gloo_console::error!("WS: ", error);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user