Skip to main content

zaun_community_protocol/event/
voice.rs

1//! Voice event bodies (specification §8.12, §9.2). All are live: pushed to connected members
2//! and never stored, because a voice channel's participants only exist while they are
3//! connected. `sync.snapshot` lists each voice channel's current participants.
4
5use serde::{Deserialize, Serialize};
6
7use crate::command::object::{Opaque, VoiceParticipant};
8use crate::ids::{ChannelId, MemberId, VoiceSessionId};
9
10/// `voice.joined`: a member entered a voice channel. Its `key_package` is present only for the
11/// channel's other participants.
12#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
13pub struct VoiceJoined {
14    /// The voice channel.
15    pub channel_id: ChannelId,
16    /// The new participant.
17    pub participant: VoiceParticipant,
18}
19
20/// `voice.updated`: a participant's mute, deafen or `can_speak` changed.
21#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
22pub struct VoiceUpdated {
23    /// The voice channel.
24    pub channel_id: ChannelId,
25    /// The participant, without its key package.
26    pub participant: VoiceParticipant,
27}
28
29/// Why a participant left a voice channel.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
31#[serde(rename_all = "snake_case")]
32pub enum VoiceLeftReason {
33    /// `voice.leave`, or a `voice.join` of another channel.
34    Left,
35    /// The member's connection closed or was replaced.
36    Disconnected,
37    /// A moderator disconnected the member.
38    Disconnect,
39    /// A moderator moved the member: `moved_to` names the channel to join.
40    Moved,
41    /// The member lost access: kicked, banned, suspended, timed out, lockdown, a lost
42    /// `VIEW_CHANNEL` or `CONNECT`, or the channel was deleted.
43    Access,
44}
45
46/// `voice.left`: a member left a voice channel. The member itself receives it too.
47#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
48pub struct VoiceLeft {
49    /// The voice channel.
50    pub channel_id: ChannelId,
51    /// Who left.
52    pub member_id: MemberId,
53    /// The stay that ended.
54    pub voice_session: VoiceSessionId,
55    /// Why.
56    pub reason: VoiceLeftReason,
57    /// `moved`: the channel the moderator moved the member to; its client joins it.
58    #[serde(default, skip_serializing_if = "Option::is_none")]
59    pub moved_to: Option<ChannelId>,
60}
61
62/// `voice.signal`: WebRTC signalling from another participant, to this one only.
63#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
64pub struct VoiceSignal {
65    /// The sender.
66    pub from: MemberId,
67    /// The sender's stay.
68    pub voice_session: VoiceSessionId,
69    /// SDP or ICE, opaque.
70    pub data: Opaque,
71}
72
73/// `voice.keys`: another participant's media key for `epoch`: its signed sender-keys message
74/// and the key wrapped for this participant only (never another's).
75#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
76pub struct VoiceKeys {
77    /// The sender.
78    pub from: MemberId,
79    /// The sender's stay.
80    pub voice_session: VoiceSessionId,
81    /// The sender's key epoch.
82    pub epoch: u64,
83    /// The sender's signed message for this epoch, opaque.
84    pub sender_keys: Opaque,
85    /// The key, wrapped for the recipient, opaque.
86    pub wrapped: Opaque,
87}