Compare commits
3 Commits
cadaca90a1
...
badf3e9d47
Author | SHA1 | Date |
---|---|---|
kozabrada123 | badf3e9d47 | |
kozabrada123 | f7a2285dd5 | |
kozabrada123 | 6f9ed86a4c |
|
@ -12,12 +12,12 @@ use serde::{Deserialize, Serialize};
|
||||||
/// Examples of the event:
|
/// Examples of the event:
|
||||||
///
|
///
|
||||||
/// When receiving:
|
/// When receiving:
|
||||||
/// ```
|
/// ```json
|
||||||
/// {"op":12,"d":{"video_ssrc":0,"user_id":"463640391196082177","streams":[{"ssrc":26595,"rtx_ssrc":26596,"rid":"100","quality":100,"max_resolution":{"width":1280,"type":"fixed","height":720},"max_framerate":30,"active":false}],"audio_ssrc":26597}}{"op":12,"d":{"video_ssrc":0,"user_id":"463640391196082177","streams":[{"ssrc":26595,"rtx_ssrc":26596,"rid":"100","quality":100,"max_resolution":{"width":1280,"type":"fixed","height":720},"max_framerate":30,"active":false}],"audio_ssrc":26597}}
|
/// {"op":12,"d":{"video_ssrc":0,"user_id":"463640391196082177","streams":[{"ssrc":26595,"rtx_ssrc":26596,"rid":"100","quality":100,"max_resolution":{"width":1280,"type":"fixed","height":720},"max_framerate":30,"active":false}],"audio_ssrc":26597}}{"op":12,"d":{"video_ssrc":0,"user_id":"463640391196082177","streams":[{"ssrc":26595,"rtx_ssrc":26596,"rid":"100","quality":100,"max_resolution":{"width":1280,"type":"fixed","height":720},"max_framerate":30,"active":false}],"audio_ssrc":26597}}
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// When sending:
|
/// When sending:
|
||||||
/// ```
|
/// ```json
|
||||||
/// {"op":12,"d":{"audio_ssrc":2307250864,"video_ssrc":0,"rtx_ssrc":0,"streams":[{"type":"video","rid":"100","ssrc":26595,"active":false,"quality":100,"rtx_ssrc":26596,"max_bitrate":2500000,"max_framerate":30,"max_resolution":{"type":"fixed","width":1280,"height":720}}]}}
|
/// {"op":12,"d":{"audio_ssrc":2307250864,"video_ssrc":0,"rtx_ssrc":0,"streams":[{"type":"video","rid":"100","ssrc":26595,"active":false,"quality":100,"rtx_ssrc":26596,"max_bitrate":2500000,"max_framerate":30,"max_resolution":{"type":"fixed","width":1280,"height":720}}]}}
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq)]
|
#[derive(Debug, Deserialize, Serialize, Default, Clone, PartialEq, Eq)]
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use async_trait::async_trait;
|
||||||
use chorus::errors::GatewayError;
|
use chorus::errors::GatewayError;
|
||||||
use chorus::gateway::*;
|
use chorus::gateway::*;
|
||||||
use chorus::types::{self, ChannelModifySchema, RoleCreateModifySchema, RoleObject};
|
use chorus::types::{self, ChannelModifySchema, GatewayReady, RoleCreateModifySchema, RoleObject};
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use wasm_bindgen_test::*;
|
use wasm_bindgen_test::*;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
@ -20,6 +22,18 @@ async fn test_gateway_establish() {
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct GatewayReadyObserver {
|
||||||
|
channel: tokio::sync::mpsc::Sender<()>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Observer<GatewayReady> for GatewayReadyObserver {
|
||||||
|
async fn update(&self, _data: &GatewayReady) {
|
||||||
|
self.channel.send(()).await.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
||||||
/// Tests establishing a connection and authenticating
|
/// Tests establishing a connection and authenticating
|
||||||
|
@ -28,10 +42,37 @@ async fn test_gateway_authenticate() {
|
||||||
|
|
||||||
let gateway: GatewayHandle = Gateway::spawn(bundle.urls.wss.clone()).await.unwrap();
|
let gateway: GatewayHandle = Gateway::spawn(bundle.urls.wss.clone()).await.unwrap();
|
||||||
|
|
||||||
|
let (ready_send, mut ready_receive) = tokio::sync::mpsc::channel(1);
|
||||||
|
|
||||||
|
let observer = Arc::new(GatewayReadyObserver {
|
||||||
|
channel: ready_send,
|
||||||
|
});
|
||||||
|
|
||||||
|
gateway
|
||||||
|
.events
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.session
|
||||||
|
.ready
|
||||||
|
.subscribe(observer);
|
||||||
|
|
||||||
let mut identify = types::GatewayIdentifyPayload::common();
|
let mut identify = types::GatewayIdentifyPayload::common();
|
||||||
identify.token = bundle.user.token.clone();
|
identify.token = bundle.user.token.clone();
|
||||||
|
|
||||||
gateway.send_identify(identify).await;
|
gateway.send_identify(identify).await;
|
||||||
|
|
||||||
|
let current_time = std::time::Instant::now();
|
||||||
|
|
||||||
|
tokio::select! {
|
||||||
|
// Fail, we timed out waiting for it
|
||||||
|
() = safina_timer::sleep_until(current_time + Duration::from_secs(20)) => {
|
||||||
|
println!("Timed out waiting for event, failing..");
|
||||||
|
assert!(false);
|
||||||
|
}
|
||||||
|
// Sucess, we have received it
|
||||||
|
Some(_) = ready_receive.recv() => {}
|
||||||
|
};
|
||||||
|
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue