Skip to content

Commit

Permalink
use ipc router to handle ws dom-action messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gterzian committed Oct 9, 2019
1 parent ec408e9 commit c1573cc
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions components/net/websocket_loader.rs
Expand Up @@ -12,6 +12,7 @@ use headers::Host;
use http::header::{self, HeaderMap, HeaderName, HeaderValue};
use http::uri::Authority;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use net_traits::request::{RequestBuilder, RequestMode};
use net_traits::{CookieSource, MessageData};
use net_traits::{WebSocketDomAction, WebSocketNetworkEvent};
Expand Down Expand Up @@ -242,8 +243,10 @@ pub fn init(
let ws_sender = ws.broadcaster();
let initiated_close = Arc::new(AtomicBool::new(false));

thread::spawn(move || {
while let Ok(dom_action) = dom_action_receiver.recv() {
ROUTER.add_route(
dom_action_receiver.to_opaque(),
Box::new(move |message| {
let dom_action = message.to().expect("Ws dom_action message to deserialize");
match dom_action {
WebSocketDomAction::SendMessage(MessageData::Text(data)) => {
ws_sender.send(Message::text(data)).unwrap();
Expand All @@ -265,8 +268,8 @@ pub fn init(
}
},
}
}
});
}),
);

if let Err(e) = ws.run() {
debug!("Failed to run WebSocket: {:?}", e);
Expand Down

0 comments on commit c1573cc

Please sign in to comment.