EventEmitter: add VoIP event support (m.call.* event types)
Signed-off-by: Alex Black <blacka101@gmail.com>
This commit is contained in:
parent
d9e5a17ab0
commit
d4327d4cfc
5 changed files with 194 additions and 1 deletions
|
@ -1498,6 +1498,18 @@ impl BaseClient {
|
|||
.on_custom_event(room, &CustomEvent::Message(e))
|
||||
.await
|
||||
}
|
||||
AnySyncMessageEvent::CallInvite(e) => {
|
||||
event_emitter.on_room_call_invite(room, e).await
|
||||
}
|
||||
AnySyncMessageEvent::CallAnswer(e) => {
|
||||
event_emitter.on_room_call_answer(room, e).await
|
||||
}
|
||||
AnySyncMessageEvent::CallCandidates(e) => {
|
||||
event_emitter.on_room_call_candidates(room, e).await
|
||||
}
|
||||
AnySyncMessageEvent::CallHangup(e) => {
|
||||
event_emitter.on_room_call_hangup(room, e).await
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
AnySyncRoomEvent::RedactedState(_event) => {}
|
||||
|
|
|
@ -19,6 +19,10 @@ use serde_json::value::RawValue as RawJsonValue;
|
|||
|
||||
use crate::{
|
||||
events::{
|
||||
call::{
|
||||
answer::AnswerEventContent, candidates::CandidatesEventContent,
|
||||
hangup::HangupEventContent, invite::InviteEventContent,
|
||||
},
|
||||
custom::CustomEventContent,
|
||||
fully_read::FullyReadEventContent,
|
||||
ignored_user_list::IgnoredUserListEventContent,
|
||||
|
@ -135,6 +139,19 @@ pub trait EventEmitter: Send + Sync {
|
|||
_: &SyncMessageEvent<FeedbackEventContent>,
|
||||
) {
|
||||
}
|
||||
/// Fires when `Client` receives a `RoomEvent::CallInvite` event
|
||||
async fn on_room_call_invite(&self, _: SyncRoom, _: &SyncMessageEvent<InviteEventContent>) {}
|
||||
/// Fires when `Client` receives a `RoomEvent::CallAnswer` event
|
||||
async fn on_room_call_answer(&self, _: SyncRoom, _: &SyncMessageEvent<AnswerEventContent>) {}
|
||||
/// Fires when `Client` receives a `RoomEvent::CallCandidates` event
|
||||
async fn on_room_call_candidates(
|
||||
&self,
|
||||
_: SyncRoom,
|
||||
_: &SyncMessageEvent<CandidatesEventContent>,
|
||||
) {
|
||||
}
|
||||
/// Fires when `Client` receives a `RoomEvent::CallHangup` event
|
||||
async fn on_room_call_hangup(&self, _: SyncRoom, _: &SyncMessageEvent<HangupEventContent>) {}
|
||||
/// Fires when `Client` receives a `RoomEvent::RoomRedaction` event.
|
||||
async fn on_room_redaction(&self, _: SyncRoom, _: &SyncRedactionEvent) {}
|
||||
/// Fires when `Client` receives a `RoomEvent::RoomPowerLevels` event.
|
||||
|
@ -317,6 +334,22 @@ mod test {
|
|||
) {
|
||||
self.0.lock().await.push("feedback".to_string())
|
||||
}
|
||||
async fn on_room_call_invite(&self, _: SyncRoom, _: &SyncMessageEvent<InviteEventContent>) {
|
||||
self.0.lock().await.push("call invite".to_string())
|
||||
}
|
||||
async fn on_room_call_answer(&self, _: SyncRoom, _: &SyncMessageEvent<AnswerEventContent>) {
|
||||
self.0.lock().await.push("call answer".to_string())
|
||||
}
|
||||
async fn on_room_call_candidates(
|
||||
&self,
|
||||
_: SyncRoom,
|
||||
_: &SyncMessageEvent<CandidatesEventContent>,
|
||||
) {
|
||||
self.0.lock().await.push("call candidates".to_string())
|
||||
}
|
||||
async fn on_room_call_hangup(&self, _: SyncRoom, _: &SyncMessageEvent<HangupEventContent>) {
|
||||
self.0.lock().await.push("call hangup".to_string())
|
||||
}
|
||||
async fn on_room_redaction(&self, _: SyncRoom, _: &SyncRedactionEvent) {
|
||||
self.0.lock().await.push("redaction".to_string())
|
||||
}
|
||||
|
@ -601,4 +634,28 @@ mod test {
|
|||
],
|
||||
)
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn event_emitter_voip() {
|
||||
let vec = Arc::new(Mutex::new(Vec::new()));
|
||||
let test_vec = Arc::clone(&vec);
|
||||
let emitter = Box::new(EvEmitterTest(vec));
|
||||
|
||||
let client = get_client().await;
|
||||
client.add_event_emitter(emitter).await;
|
||||
|
||||
let mut response = sync_response(SyncResponseFile::Voip);
|
||||
client.receive_sync_response(&mut response).await.unwrap();
|
||||
|
||||
let v = test_vec.lock().await;
|
||||
assert_eq!(
|
||||
v.as_slice(),
|
||||
[
|
||||
"call invite",
|
||||
"call answer",
|
||||
"call candidates",
|
||||
"call hangup",
|
||||
],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -355,6 +355,7 @@ pub enum SyncResponseFile {
|
|||
DefaultWithSummary,
|
||||
Invite,
|
||||
Leave,
|
||||
Voip,
|
||||
}
|
||||
|
||||
/// Get specific API responses for testing
|
||||
|
@ -365,6 +366,7 @@ pub fn sync_response(kind: SyncResponseFile) -> SyncResponse {
|
|||
SyncResponseFile::DefaultWithSummary => &test_json::DEFAULT_SYNC_SUMMARY,
|
||||
SyncResponseFile::Invite => &test_json::INVITE_SYNC,
|
||||
SyncResponseFile::Leave => &test_json::LEAVE_SYNC,
|
||||
SyncResponseFile::Voip => &test_json::VOIP_SYNC,
|
||||
};
|
||||
|
||||
let response = Response::builder()
|
||||
|
|
|
@ -16,7 +16,9 @@ pub use events::{
|
|||
REACTION, REDACTED, REDACTED_INVALID, REDACTED_STATE, REDACTION, REGISTRATION_RESPONSE_ERR,
|
||||
ROOM_ID, ROOM_MESSAGES, TYPING,
|
||||
};
|
||||
pub use sync::{DEFAULT_SYNC_SUMMARY, INVITE_SYNC, LEAVE_SYNC, LEAVE_SYNC_EVENT, MORE_SYNC, SYNC};
|
||||
pub use sync::{
|
||||
DEFAULT_SYNC_SUMMARY, INVITE_SYNC, LEAVE_SYNC, LEAVE_SYNC_EVENT, MORE_SYNC, SYNC, VOIP_SYNC,
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref DEVICES: JsonValue = json!({
|
||||
|
|
|
@ -1101,3 +1101,123 @@ lazy_static! {
|
|||
"next_batch": "s1380317562_757269739_1655566_503953763_334052043_1209862_55290918_65705002_101146"
|
||||
});
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref VOIP_SYNC: JsonValue = json!({
|
||||
"device_one_time_keys_count": {},
|
||||
"next_batch": "s526_47314_0_7_1_1_1_11444_1",
|
||||
"device_lists": {
|
||||
"changed": [
|
||||
"@example:example.org"
|
||||
],
|
||||
"left": []
|
||||
},
|
||||
"rooms": {
|
||||
"invite": {},
|
||||
"join": {
|
||||
"!SVkFJHzfwvuaIEawgC:localhost": {
|
||||
"summary": {},
|
||||
"account_data": {
|
||||
"events": []
|
||||
},
|
||||
"ephemeral": {
|
||||
"events": [ ]
|
||||
},
|
||||
"state": {
|
||||
"events": []
|
||||
},
|
||||
"timeline": {
|
||||
"events": [
|
||||
{
|
||||
"content": {
|
||||
"call_id": "12345",
|
||||
"lifetime": 60000,
|
||||
"offer": {
|
||||
"sdp": "v=0\r\no=- 6584580628695956864 2 IN IP4 127.0.0.1[...]",
|
||||
"type": "offer"
|
||||
},
|
||||
"version": 0
|
||||
},
|
||||
"event_id": "$143273582443PhrSn:example.org",
|
||||
"origin_server_ts": 143273582,
|
||||
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
|
||||
"sender": "@example:example.org",
|
||||
"type": "m.call.invite",
|
||||
"unsigned": {
|
||||
"age": 1234
|
||||
}
|
||||
},
|
||||
{
|
||||
"content": {
|
||||
"answer": {
|
||||
"sdp": "v=0\r\no=- 6584580628695956864 2 IN IP4 127.0.0.1[...]",
|
||||
"type": "answer"
|
||||
},
|
||||
"call_id": "12345",
|
||||
"lifetime": 60000,
|
||||
"version": 0
|
||||
},
|
||||
"event_id": "$143273582443PhrSn:example.org",
|
||||
"origin_server_ts": 143273582,
|
||||
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
|
||||
"sender": "@example:example.org",
|
||||
"type": "m.call.answer",
|
||||
"unsigned": {
|
||||
"age": 1234
|
||||
}
|
||||
},
|
||||
{
|
||||
"content": {
|
||||
"call_id": "12345",
|
||||
"candidates": [
|
||||
{
|
||||
"candidate": "candidate:863018703 1 udp 2122260223 10.9.64.156 43670 typ host generation 0",
|
||||
"sdpMLineIndex": 0,
|
||||
"sdpMid": "audio"
|
||||
}
|
||||
],
|
||||
"version": 0
|
||||
},
|
||||
"event_id": "$143273582443PhrSn:example.org",
|
||||
"origin_server_ts": 143273582,
|
||||
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
|
||||
"sender": "@example:example.org",
|
||||
"type": "m.call.candidates",
|
||||
"unsigned": {
|
||||
"age": 1234
|
||||
}
|
||||
},
|
||||
{
|
||||
"content": {
|
||||
"call_id": "12345",
|
||||
"version": 0
|
||||
},
|
||||
"event_id": "$143273582443PhrSn:example.org",
|
||||
"origin_server_ts": 143273582,
|
||||
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
|
||||
"sender": "@example:example.org",
|
||||
"type": "m.call.hangup",
|
||||
"unsigned": {
|
||||
"age": 1234
|
||||
}
|
||||
}
|
||||
],
|
||||
"limited": true,
|
||||
"prev_batch": "t392-516_47314_0_7_1_1_1_11444_1"
|
||||
},
|
||||
"unread_notifications": {
|
||||
"highlight_count": 0,
|
||||
"notification_count": 11
|
||||
}
|
||||
}
|
||||
},
|
||||
"leave": {}
|
||||
},
|
||||
"to_device": {
|
||||
"events": []
|
||||
},
|
||||
"presence": {
|
||||
"events": []
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue