AGPU6SD7V5FQNI6W54HDRJQCVHWYCZIHDHL6IL5LVVMJ7SVJL7UAC
33MVG7KI2MNVI3JW2Q4EDMMDMTWVCNNP3UGONX5C7347CI2WIZYAC
7MWGEO4D53CRQYELJQJ3PMI3BZJNAJJRX7AESNZ4NMF23XGBFEGAC
B2X5NJ7QAQTOZXHDAGANNGNYHTPN6LWKTJTL5IM6VBP4NETHHS5AC
SMM42WXFAYFMOMUR7DCVCZCK7QMXIE5KUH4GUOIZPVFDDYB4ZMZAC
M2FGQSGQITI7FYU3RWY3IGIA4ZLS6JAZMHIO64WNHKS4JIL53OWQC
SO2VFZUJI2CLGDHNDLJIEPCQKFDP4TOH6WREPVJYPEVJ66EITDMQC
7VYQARQVDMISCO5566F55TG5FIDSOO3JQEIKVOUKEFEU4X5HZNEAC
KWR2TS2D7YN4LCGMQZ35V4WBLQDHAVSZJV3SZAIR5HQRSJAWLWCQC
LKAUS67VU5SLG5O5MTSO6N4VVT5OB2X4VNR6HYLIJ3ZOAXRQ4Q2QC
LSQ7OPL7Z5WJDO7ZZS3D4UPMEEWUUF2LNQ3FZUWWFUVZEXA7CIOAC
6WLPW4L4PN6ANYYW3I6AOCN3SXQP37RQTUOM52IVXL3SRZD7UHAAC
YYUB6HZYSVQSCO7DGF6ETPAXTMG6SG2RQQXLP73NKPLDMZEC3PGAC
K3I54HXNNCTEA7L6UGWIVBFB5TPZVZZXDBRSR2YZDIKREXQVWRIQC
LBG7DYYI7WCROF4GRYVXDXIV2465E5KPGQVZTFUPTZQBNZZ3LNYAC
6PSALZKWII5BVJZG7DOPH2SNY2Q4CJR6QSMROXCTVSJ6UPX2RIUAC
OQDFFOFENHOGPMR6DWAIEYUKRKBVQHJNVTDVWFUTZTVMOJECWKSQC
"aster 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"quasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quasi_macros 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"aster 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quasi 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quasi_macros 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_codegen 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_codegen 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sha1"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-bidi"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-normalization"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "url"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
name = "ws"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"httparse 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"sha1 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
use io::*;
use mio;
use ws::*;
use serde_json;
pub struct ConfigServer {
client: Sender,
server: mio::Sender<(NetEvent, Sender)>,
}
impl ConfigServer {
pub fn new(client: Sender, server: mio::Sender<(NetEvent, Sender)>) -> Self {
ConfigServer { client: client, server: server }
}
}
impl Handler for ConfigServer {
fn on_open(&mut self, _: Handshake) -> Result<()> {
self.server.send((NetEvent::RequestCluster, self.client.clone())).unwrap();
Ok(())
}
fn on_message(&mut self, msg: Message) -> Result<()> {
let msg = msg.as_text().unwrap();
let event = serde_json::from_str(msg).unwrap();
self.server.send((event, self.client.clone())).unwrap();
Ok(())
}
}
// Initialize net interface
let net = try!(IpInterface::open(config));
try!(event_loop.register(&net,
NET_EVENT,
EventSet::readable() |
EventSet::writable(),
PollOpt::oneshot()));
}
pub fn run(&mut self) -> io::Result<()> {
let mut event_loop = try!(EventLoop::new());
try!(event_loop.register(&self.host,
HOST_EVENT,
EventSet::readable(),
PollOpt::level()));
try!(event_loop.register(&self.net,
NET_EVENT,
EventSet::readable() |
EventSet::writable(),
PollOpt::oneshot()));
let channel = event_loop.channel();
let socket = WebSocket::new(move |out| {
ConfigServer::new(out, channel.clone())
}).unwrap();
self.clients = Some(socket.broadcaster());
thread::spawn(move || {
socket.listen("127.0.0.1:3012").unwrap();
warn!("Configuration server has shutdown");
});
try!(event_loop.run(self));
// TODO: Should probably kill spawned threads
Ok(())
}
}
fn send_net_event(&self, event: &NetEvent, sender: &WsSender) {
let msg = serde_json::to_string(&event).unwrap();
sender.send(msg).unwrap();
}
fn broadcast_net_event(&self, event: &NetEvent) {
match self.clients {
Some(ref clients) => self.send_net_event(event, clients),
_ => unreachable!("Cannot broadcast without clients"),
fn notify(&mut self, _: &mut EventLoop<Self>, msg: Self::Message) {
match msg.0 {
NetEvent::RequestCluster => {
self.send_net_event(&NetEvent::Cluster(self.cluster.clone()), &msg.1);
},
NetEvent::Screens(screens) => {
self.cluster.set_screens(screens);
self.net.send_to_all(&NetEvent::Cluster(self.cluster.clone())).unwrap();
},
event => warn!("Unexpected config event: {:?}", event),
}
}
fn send_to(&self, event: NetEvent, addr: &SocketAddr) -> io::Result<Option<()>>;
fn send_to_all(&self, event: NetEvent) -> io::Result<Option<()>>;
fn send_to(&self, event: &NetEvent, addr: &SocketAddr) -> io::Result<Option<()>>;
fn send_to_all(&self, event: &NetEvent) -> io::Result<Option<()>>;
fn send_to(&self, event: NetEvent, addr: &SocketAddr) -> io::Result<Option<()>> {
let packet = bincode_serde::serialize(&event, SizeLimit::Bounded(1024)).unwrap();
fn send_to(&self, event: &NetEvent, addr: &SocketAddr) -> io::Result<Option<()>> {
let packet = bincode_serde::serialize(event, SizeLimit::Bounded(1024)).unwrap();
let mut event_loop = EventLoop::new().unwrap();
let mut elemeld = Elemeld::new(&mut event_loop, &config).unwrap();
info!("Starting event loop");
event_loop.run(&mut elemeld).unwrap();
let mut elemeld = Elemeld::new(&config).unwrap();
elemeld.run().unwrap();
new Canvas(document.querySelector('.canvas'));
var ws = new WebSocket("ws://127.0.0.1:3012");
ws.onopen = function(e) {
new Canvas(document.querySelector('.canvas'));
};
ws.onmessage = function(e) {
var obj = JSON.parse(e.data);
var type = Object.keys(obj)[0];
var event = obj[type];
switch(type) {
case "Screens":
console.log(event);
break;
}
};