ruma-events
This commit is contained in:
commit
424c0f335d
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
Cargo.lock
|
||||
target
|
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "ruma-events"
|
||||
version = "0.1.0"
|
||||
authors = ["Jimmy Cuadra <jimmy@jimmycuadra.com>"]
|
||||
description = "Serializable types for the events in the Matrix specification."
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
keywords = ["matrix", "matrix.org", "chat", "messaging", "ruma"]
|
||||
repository = "https://github.com/ruma/ruma-events"
|
||||
homepage = "https://github.com/ruma/ruma-events"
|
||||
documentation = "http://ruma.github.io/ruma-events/ruma-events"
|
20
LICENSE
Normal file
20
LICENSE
Normal file
@ -0,0 +1,20 @@
|
||||
Copyright (c) 2015 Jimmy Cuadra
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
11
README.md
Normal file
11
README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# ruma-events
|
||||
|
||||
ruma-events contains serializable types for the events in the [Matrix](https://matrix.org/) specification that can be shared by client and server code.
|
||||
|
||||
## Status
|
||||
|
||||
This project is currently experimental and is very likely to change drastically.
|
||||
|
||||
## License
|
||||
|
||||
[MIT](http://opensource.org/licenses/MIT)
|
201
src/call.rs
Normal file
201
src/call.rs
Normal file
@ -0,0 +1,201 @@
|
||||
//! Events within the *m.call* namespace.
|
||||
|
||||
use core::{Event, RoomEvent};
|
||||
|
||||
/// This event is sent by the callee when they wish to answer the call.
|
||||
pub struct Answer<'a> {
|
||||
content: AnswerContent<'a>,
|
||||
event_id: String,
|
||||
room_id: String,
|
||||
user_id: String,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, AnswerContent<'a>> for Answer<'a> {
|
||||
fn content(&'a self) -> &'a AnswerContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.answer"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, AnswerContent<'a>> for Answer<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of an `Answer` event.
|
||||
pub struct AnswerContent<'a> {
|
||||
/// The VoIP session description.
|
||||
answer: SessionDescription<'a>,
|
||||
/// The ID of the call this event relates to.
|
||||
call_id: String,
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
||||
|
||||
/// A VoIP session description.
|
||||
pub struct SessionDescription<'a> {
|
||||
/// The type of session description.
|
||||
session_type: SessionDescriptionType,
|
||||
/// The SDP text of the session description.
|
||||
sdp: &'a str,
|
||||
}
|
||||
|
||||
/// The types of VoIP session descriptions.
|
||||
pub enum SessionDescriptionType {
|
||||
/// An answer.
|
||||
Answer,
|
||||
/// An offer.
|
||||
Offer,
|
||||
}
|
||||
|
||||
/// This event is sent by callers after sending an invite and by the callee after answering.
|
||||
/// Its purpose is to give the other party additional ICE candidates to try using to communicate.
|
||||
pub struct Candidates<'a> {
|
||||
content: CandidatesContent<'a>,
|
||||
event_id: &'a str,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, CandidatesContent<'a>> for Candidates<'a> {
|
||||
fn content(&'a self) -> &'a CandidatesContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.candidates"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, CandidatesContent<'a>> for Candidates<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `Candidates` event.
|
||||
pub struct CandidatesContent<'a> {
|
||||
/// The ID of the call this event relates to.
|
||||
call_id: &'a str,
|
||||
/// A list of candidates.
|
||||
candidates: &'a[Candidate<'a>],
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
||||
|
||||
/// An ICE (Interactive Connectivity Establishment) candidate.
|
||||
pub struct Candidate<'a> {
|
||||
/// The SDP "a" line of the candidate.
|
||||
candidate: &'a str,
|
||||
/// The SDP media type this candidate is intended for.
|
||||
sdp_mid: &'a str,
|
||||
/// The index of the SDP "m" line this candidate is intended for.
|
||||
sdp_m_line_index: u64,
|
||||
}
|
||||
|
||||
/// Sent by either party to signal their termination of the call. This can be sent either once the
|
||||
/// call has has been established or before to abort the call.
|
||||
pub struct Hangup<'a> {
|
||||
content: HangupContent<'a>,
|
||||
event_id: &'a str,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, HangupContent<'a>> for Hangup<'a> {
|
||||
fn content(&'a self) -> &'a HangupContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.hangup"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, HangupContent<'a>> for Hangup<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `Hangup` event.
|
||||
pub struct HangupContent<'a> {
|
||||
/// The ID of the call this event relates to.
|
||||
call_id: &'a str,
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
||||
|
||||
/// This event is sent by the caller when they wish to establish a call.
|
||||
pub struct Invite<'a> {
|
||||
content: InviteContent<'a>,
|
||||
event_id: &'a str,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, InviteContent<'a>> for Invite<'a> {
|
||||
fn content(&'a self) -> &'a InviteContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.invite"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, InviteContent<'a>> for Invite<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of an `Invite` event.
|
||||
pub struct InviteContent<'a> {
|
||||
/// A unique identifer for the call.
|
||||
call_id: &'a str,
|
||||
/// The time in milliseconds that the invite is valid for. Once the invite age exceeds this
|
||||
/// value, clients should discard it. They should also no longer show the call as awaiting an
|
||||
/// answer in the UI.
|
||||
lifetime: u64,
|
||||
/// The session description object.
|
||||
offer: SessionDescription<'a>,
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
27
src/core.rs
Normal file
27
src/core.rs
Normal file
@ -0,0 +1,27 @@
|
||||
//! Traits for types of events that share common fields.
|
||||
|
||||
/// The basic set of fields all events must have.
|
||||
pub trait Event<'a, T> {
|
||||
/// The primary event payload.
|
||||
fn content(&'a self) -> &'a T;
|
||||
/// The type of event, e.g. *com.example.subdomain.event.type*.
|
||||
fn event_type(&self) -> &'static str;
|
||||
}
|
||||
|
||||
/// An event emitted within the context of a room.
|
||||
pub trait RoomEvent<'a, T>: Event<'a, T> {
|
||||
/// The globally unique event identifier.
|
||||
fn event_id(&'a self) -> &'a str;
|
||||
/// The ID of the room associated with this event.
|
||||
fn room_id(&'a self) -> &'a str;
|
||||
/// The fully-qualified ID of the user who sent the event.
|
||||
fn user_id(&'a self) -> &'a str;
|
||||
}
|
||||
|
||||
/// An event that represents some aspect of a room's state.
|
||||
pub trait StateEvent<'a, T>: RoomEvent<'a, T> {
|
||||
/// Previous content for this aspect of room state.
|
||||
fn prev_content(&self) -> Option<&'a T>;
|
||||
/// A unique key which defines the overwriting semantics for this aspect of room state.
|
||||
fn state_key() -> &'a str;
|
||||
}
|
9
src/lib.rs
Normal file
9
src/lib.rs
Normal file
@ -0,0 +1,9 @@
|
||||
//! Crate ruma_events contains serializable types for the events in the [Matrix](https://matrix.org)
|
||||
//! specification that can be shared by client and server code.
|
||||
|
||||
pub mod call;
|
||||
pub mod core;
|
||||
pub mod presence;
|
||||
pub mod receipt;
|
||||
pub mod room;
|
||||
pub mod typing;
|
1
src/presence.rs
Normal file
1
src/presence.rs
Normal file
@ -0,0 +1 @@
|
||||
//! Events within the *m.presence* namespace.
|
1
src/receipt.rs
Normal file
1
src/receipt.rs
Normal file
@ -0,0 +1 @@
|
||||
//! Events within the *m.receipt* namespace.
|
1
src/room/message.rs
Normal file
1
src/room/message.rs
Normal file
@ -0,0 +1 @@
|
||||
//! Events within the *m.room.message* namespace.
|
3
src/room/mod.rs
Normal file
3
src/room/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
//! Events within the *m.room* namespace.
|
||||
|
||||
pub mod message;
|
27
src/typing.rs
Normal file
27
src/typing.rs
Normal file
@ -0,0 +1,27 @@
|
||||
//! Events within the *m.typing* namespace.
|
||||
|
||||
use core::Event;
|
||||
|
||||
/// Informs the client of the list of users currently typing.
|
||||
pub struct Typing<'a> {
|
||||
/// The payload.
|
||||
content: TypingContent<'a>,
|
||||
/// The ID of the room associated with this event.
|
||||
room_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, TypingContent<'a>> for Typing<'a> {
|
||||
fn content(&'a self) -> &'a TypingContent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.typing"
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `Typing` event.
|
||||
pub struct TypingContent<'a> {
|
||||
/// The list of user IDs typing in this room, if any.
|
||||
user_ids: &'a[&'a str],
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user