From 49e7f56a66cb9e77989e67e4d7fecba7c5e2af89 Mon Sep 17 00:00:00 2001
From: David Li
Date: Wed, 28 Oct 2015 22:51:00 -0400
Subject: Move message parsing to PBClient
---
src/main.rs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'src')
diff --git a/src/main.rs b/src/main.rs
index ea58059..b12f5a6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,6 +15,7 @@ use websocket::Receiver;
use websocket::WebSocketStream;
use websocket::DataFrame;
use websocket::Client;
+
struct PBClient {
client: websocket::client::Client,
@@ -36,6 +37,28 @@ impl PBClient {
client: response.begin()
}
}
+
+ fn process_message(message: Result) -> Option {
+ let message = match message {
+ Ok(m) => m,
+ Err(e) => {
+ println!("Error: {:?}", e);
+ return None;
+ }
+ };
+
+ if let websocket::Message::Text(message) = message {
+ Message::parse(message.as_ref())
+ }
+ else {
+ None
+ }
+ }
+
+ fn messages<'a>(&'a mut self) -> Box + 'a> {
+ let mut receiver = self.client.get_mut_reciever(); // there is a typo in the API
+ Box::new(receiver.incoming_messages().filter_map(PBClient::process_message))
+ }
}
fn main() {
--
cgit v1.2.3