daemon: update monitor: implements ping/pong (required server changes)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use kordophone::api::event_socket::EventSocket;
|
||||
use kordophone::api::event_socket::{EventSocket, SocketEvent, SocketUpdate};
|
||||
use kordophone::api::http_client::Credentials;
|
||||
use kordophone::api::http_client::HTTPAPIClient;
|
||||
use kordophone::api::InMemoryAuthenticationStore;
|
||||
@@ -110,17 +110,24 @@ impl ClientCli {
|
||||
pub async fn print_events(&mut self) -> Result<()> {
|
||||
let socket = self.api.open_event_socket(None).await?;
|
||||
|
||||
let mut stream = socket.events().await;
|
||||
while let Some(Ok(event)) = stream.next().await {
|
||||
match event.data {
|
||||
EventData::ConversationChanged(conversation) => {
|
||||
println!("Conversation changed: {}", conversation.guid);
|
||||
let (mut stream, _) = socket.events().await;
|
||||
while let Some(Ok(socket_event)) = stream.next().await {
|
||||
match socket_event {
|
||||
SocketEvent::Update(event) => {
|
||||
match event.data {
|
||||
EventData::ConversationChanged(conversation) => {
|
||||
println!("Conversation changed: {}", conversation.guid);
|
||||
}
|
||||
EventData::MessageReceived(conversation, message) => {
|
||||
println!(
|
||||
"Message received: msg: {} conversation: {}",
|
||||
message.guid, conversation.guid
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
EventData::MessageReceived(conversation, message) => {
|
||||
println!(
|
||||
"Message received: msg: {} conversation: {}",
|
||||
message.guid, conversation.guid
|
||||
);
|
||||
SocketEvent::Pong => {
|
||||
println!("Pong");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,8 +139,17 @@ impl ClientCli {
|
||||
|
||||
println!("Listening for raw updates...");
|
||||
let mut stream = socket.raw_updates().await;
|
||||
while let Some(update) = stream.next().await {
|
||||
println!("Got update: {:?}", update);
|
||||
while let Some(Ok(update)) = stream.next().await {
|
||||
match update {
|
||||
SocketUpdate::Update(updates) => {
|
||||
for update in updates {
|
||||
println!("Got update: {:?}", update);
|
||||
}
|
||||
}
|
||||
SocketUpdate::Pong => {
|
||||
println!("Pong");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user