Added client-related models
This commit is contained in:
parent
677adf9b5f
commit
b89acbdd11
4 changed files with 58 additions and 0 deletions
11
src/models/client/commands.rs
Normal file
11
src/models/client/commands.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
pub enum Commands {
|
||||||
|
SetActivity
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Commands {
|
||||||
|
pub fn as_string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Commands::SetActivity => "SET_ACTIVITY".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/models/client/event.rs
Normal file
22
src/models/client/event.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::models::activity::Activity;
|
||||||
|
|
||||||
|
#[derive(Serialize, Debug)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum EventData {
|
||||||
|
Activity(Activity)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum EventName {
|
||||||
|
Activity
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl EventName {
|
||||||
|
pub fn as_string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
EventName::Activity => "activity".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
src/models/client/mod.rs
Normal file
3
src/models/client/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
pub mod payload;
|
||||||
|
pub mod event;
|
||||||
|
pub mod commands;
|
||||||
22
src/models/client/payload.rs
Normal file
22
src/models/client/payload.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
use serde::Serialize;
|
||||||
|
use crate::models::client::event::{EventData, EventName};
|
||||||
|
|
||||||
|
pub enum OpCode {
|
||||||
|
HANDSHAKE,
|
||||||
|
MESSAGE,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Debug)]
|
||||||
|
pub struct Payload {
|
||||||
|
pub event_name: String,
|
||||||
|
pub event_data: EventData,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Payload {
|
||||||
|
pub fn new(event_name: EventName, event_data: EventData) -> Self {
|
||||||
|
Self {
|
||||||
|
event_name: event_name.as_string(),
|
||||||
|
event_data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue