-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
65 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use bevy::prelude::{Deref, DerefMut, Event}; | ||
|
||
/// A wrapper around rumqttc::Event | ||
#[derive(Debug, Clone, PartialEq, Eq, Deref, DerefMut, Event)] | ||
pub struct MqttEvent(pub rumqttc::Event); | ||
|
||
|
||
/// A wrapper around rumqttc::ConnectionError | ||
#[derive(Debug, Deref, DerefMut, Event)] | ||
pub struct MqttError(pub rumqttc::ConnectionError); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
pub use rumqttc; | ||
|
||
|
||
pub mod events; | ||
pub mod client; | ||
pub mod plugin; | ||
pub mod prelude; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#[doc(hidden)] | ||
pub use crate::{client::*, plugin::*}; | ||
pub use crate::{client::*, events::*, plugin::*}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
use std::time::Duration; | ||
|
||
use bevy::prelude::NonSendMut; | ||
use bevy::log::trace; | ||
use bevy::prelude::{ EventWriter, NonSendMut}; | ||
use rumqttc::{ConnectionError, Event}; | ||
|
||
use crate::client::MqttConnection; | ||
use crate::events::{MqttError, MqttEvent}; | ||
|
||
pub(crate) fn recv_connection(mut connection: NonSendMut<MqttConnection>) { | ||
pub(crate) fn recv_connection(mut connection: NonSendMut<MqttConnection>, mut mqtt_events: EventWriter<MqttEvent>, mut error_events: EventWriter<MqttError>) { | ||
while let Ok(notification) = connection.recv_timeout(Duration::from_millis(1)) { | ||
println!("Received: {:?}", notification); | ||
trace!("Received: {:?}", notification); | ||
match notification { | ||
Ok(event) => { | ||
mqtt_events.send(MqttEvent(event)); | ||
} | ||
Err(err) => { | ||
error_events.send(MqttError(err)); | ||
} | ||
} | ||
} | ||
} |