From 08ae686a4ea7ed17d17bcd19e337527a507abfa1 Mon Sep 17 00:00:00 2001 From: Semen Evdokimov Date: Tue, 8 Oct 2019 14:39:42 +0300 Subject: [PATCH 1/8] Add CloseReason to client-api and medea --- proto/client-api/src/lib.rs | 21 ++++++++++++++++++++- src/api/client/rpc_connection.rs | 7 +++++-- src/api/client/session.rs | 15 ++++++++++++--- src/signalling/participants.rs | 16 +++++++++++++--- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/proto/client-api/src/lib.rs b/proto/client-api/src/lib.rs index 64cd50237..a2a56a25c 100644 --- a/proto/client-api/src/lib.rs +++ b/proto/client-api/src/lib.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; -use derive_more::Display; +use derive_more::{Constructor, Display}; use medea_macro::dispatchable; use serde::{de::Deserializer, ser::Serializer, Deserialize, Serialize}; @@ -99,6 +99,25 @@ pub enum Command { }, } +/// Reason of disconnecting client from the server. +#[derive(Debug, Deserialize, Serialize)] +pub enum RpcConnectionCloseReason { + /// Client session was finished on the server side. + Finished, + + /// Old connection was closed due to client reconnection. + NewConnection, +} + +/// Description which will be sent in [Close] WebSocket frame. +/// +/// [Close]: https://tools.ietf.org/html/rfc6455#section-5.5.1 +#[derive(Constructor, Debug, Deserialize, Serialize)] +pub struct CloseDescription { + /// Reason of why connection was closed. + pub reason: RpcConnectionCloseReason, +} + /// WebSocket message from Medea to Jason. #[allow(dead_code)] #[dispatchable] diff --git a/src/api/client/rpc_connection.rs b/src/api/client/rpc_connection.rs index 2b6d8a1c8..afa9d10fe 100644 --- a/src/api/client/rpc_connection.rs +++ b/src/api/client/rpc_connection.rs @@ -7,7 +7,7 @@ use std::fmt; use actix::Message; use derive_more::{From, Into}; use futures::Future; -use medea_client_api_proto::{Command, Event}; +use medea_client_api_proto::{CloseDescription, Command, Event}; use crate::api::control::MemberId; @@ -27,7 +27,10 @@ pub trait RpcConnection: fmt::Debug + Send { /// Closes [`RpcConnection`]. /// No [`RpcConnectionClosed`] signals should be emitted. /// Always returns success. - fn close(&mut self) -> Box>; + fn close( + &mut self, + close_description: CloseDescription, + ) -> Box>; /// Sends [`Event`] to remote [`Member`]. /// diff --git a/src/api/client/session.rs b/src/api/client/session.rs index faca856d5..aa62919b9 100644 --- a/src/api/client/session.rs +++ b/src/api/client/session.rs @@ -8,7 +8,7 @@ use actix::{ }; use actix_web_actors::ws::{self, CloseReason, WebsocketContext}; use futures::future::Future; -use medea_client_api_proto::{ClientMsg, ServerMsg}; +use medea_client_api_proto::{ClientMsg, CloseDescription, ServerMsg}; use crate::{ api::{ @@ -148,10 +148,19 @@ impl RpcConnection for Addr { /// Closes [`WsSession`] by sending itself "normal closure" close message. /// /// Never returns error. - fn close(&mut self) -> Box> { + fn close( + &mut self, + close_description: CloseDescription, + ) -> Box> { + let reason = CloseReason { + code: ws::CloseCode::Normal, + description: Some( + serde_json::to_string(&close_description).unwrap(), + ), + }; let fut = self .send(Close { - reason: Some(ws::CloseCode::Normal.into()), + reason: Some(reason), }) .or_else(|_| Ok(())); Box::new(fut) diff --git a/src/signalling/participants.rs b/src/signalling/participants.rs index 636989bd3..a98b66d27 100644 --- a/src/signalling/participants.rs +++ b/src/signalling/participants.rs @@ -24,7 +24,9 @@ use futures::{ Future, }; -use medea_client_api_proto::Event; +use medea_client_api_proto::{ + CloseDescription, Event, RpcConnectionCloseReason, +}; use crate::{ api::{ @@ -195,7 +197,13 @@ impl ParticipantService { { ctx.cancel_future(handler); } - Box::new(wrap_future(connection.close().then(move |_| Ok(member)))) + Box::new(wrap_future( + connection + .close(CloseDescription::new( + RpcConnectionCloseReason::NewConnection, + )) + .then(move |_| Ok(member)), + )) } else { Box::new( wrap_future(self.turn.create( @@ -299,7 +307,9 @@ impl ParticipantService { let mut close_fut = self.connections.drain().fold( vec![], |mut futures, (_, mut connection)| { - futures.push(connection.close()); + futures.push(connection.close(CloseDescription::new( + RpcConnectionCloseReason::Finished, + ))); futures }, ); From 6b6901c80b07835f83faad0b270099fb09fe356e Mon Sep 17 00:00:00 2001 From: Semen Evdokimov Date: Wed, 9 Oct 2019 12:17:51 +0300 Subject: [PATCH 2/8] Make close reason mandatory on WebSocket close by server --- src/api/client/session.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/api/client/session.rs b/src/api/client/session.rs index aa62919b9..624c699e3 100644 --- a/src/api/client/session.rs +++ b/src/api/client/session.rs @@ -64,9 +64,7 @@ impl WsSession { } fn close_normal(&self, ctx: &mut WebsocketContext) { - ctx.notify(Close { - reason: Some(ws::CloseCode::Normal.into()), - }); + ctx.notify(Close(ws::CloseCode::Normal.into())); } /// Start watchdog which will drop connection if now-last_activity > @@ -152,16 +150,13 @@ impl RpcConnection for Addr { &mut self, close_description: CloseDescription, ) -> Box> { - let reason = CloseReason { - code: ws::CloseCode::Normal, - description: Some( - serde_json::to_string(&close_description).unwrap(), - ), - }; let fut = self - .send(Close { - reason: Some(reason), - }) + .send(Close(CloseReason { + code: ws::CloseCode::Normal, + description: Some( + serde_json::to_string(&close_description).unwrap(), + ), + })) .or_else(|_| Ok(())); Box::new(fut) } @@ -182,9 +177,7 @@ impl RpcConnection for Addr { /// Message for closing [`WsSession`]. #[derive(Message)] -pub struct Close { - reason: Option, -} +pub struct Close(CloseReason); impl Handler for WsSession { type Result = (); @@ -193,7 +186,7 @@ impl Handler for WsSession { fn handle(&mut self, close: Close, ctx: &mut Self::Context) { debug!("Closing WsSession for member {}", self.member_id); self.closed_by_server = true; - ctx.close(close.reason); + ctx.close(Some(close.0)); ctx.stop(); } } From 263811b7df706eb10da1a127bd98342dd2541f5f Mon Sep 17 00:00:00 2001 From: Semen Evdokimov Date: Wed, 9 Oct 2019 12:29:21 +0300 Subject: [PATCH 3/8] Some additional docs --- src/api/client/rpc_connection.rs | 7 ++++++- src/api/client/session.rs | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/api/client/rpc_connection.rs b/src/api/client/rpc_connection.rs index afa9d10fe..2896be1d1 100644 --- a/src/api/client/rpc_connection.rs +++ b/src/api/client/rpc_connection.rs @@ -24,9 +24,14 @@ pub struct EventMessage(Event); /// /// [`Member`]: crate::signalling::elements::member::Member pub trait RpcConnection: fmt::Debug + Send { - /// Closes [`RpcConnection`]. + /// Closes [`RpcConnection`] and send [`CloseDescription`] to the client (in + /// WebSocket implementation description will be sent in [Close] frame). + /// /// No [`RpcConnectionClosed`] signals should be emitted. + /// /// Always returns success. + /// + /// [Close]: https://tools.ietf.org/html/rfc6455#section-5.5.1 fn close( &mut self, close_description: CloseDescription, diff --git a/src/api/client/session.rs b/src/api/client/session.rs index 624c699e3..59450f8e1 100644 --- a/src/api/client/session.rs +++ b/src/api/client/session.rs @@ -143,9 +143,12 @@ impl Actor for WsSession { } impl RpcConnection for Addr { - /// Closes [`WsSession`] by sending itself "normal closure" close message. + /// Closes [`WsSession`] by sending itself "normal closure" close message + /// with [`CloseDescription`] as description of [Close] frame. /// /// Never returns error. + /// + /// [Close]: https://tools.ietf.org/html/rfc6455#section-5.5.1 fn close( &mut self, close_description: CloseDescription, @@ -176,6 +179,10 @@ impl RpcConnection for Addr { } /// Message for closing [`WsSession`]. +/// +/// [`CloseReason`] will be sent in WebSocket [Close] frame's description. +/// +/// [Close]: https://tools.ietf.org/html/rfc6455#section-5.5.1 #[derive(Message)] pub struct Close(CloseReason); From 46e254654a8e35e329f96dcdf296085e2fe94863 Mon Sep 17 00:00:00 2001 From: Semen Evdokimov Date: Wed, 9 Oct 2019 12:58:21 +0300 Subject: [PATCH 4/8] Add some additional close reasons --- proto/client-api/src/lib.rs | 15 ++++++++++ src/api/client/rpc_connection.rs | 5 ++-- src/api/client/session.rs | 51 +++++++++++++++++++------------- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/proto/client-api/src/lib.rs b/proto/client-api/src/lib.rs index a2a56a25c..7b706a8cc 100644 --- a/proto/client-api/src/lib.rs +++ b/proto/client-api/src/lib.rs @@ -107,6 +107,21 @@ pub enum RpcConnectionCloseReason { /// Old connection was closed due to client reconnection. NewConnection, + + /// Connection for a while was inactive and server considers that + /// connection is idle. + Idle, + + /// Establishing of connection with server was rejected on server side. + /// + /// Most likely because wrong `Member` credentials. + ConnectionRejected, + + /// Some server error was occurred while connecting. + /// + /// This close reason is similar to 500 HTTP code. That is, the client is + /// not to blame for this error. + ServerError, } /// Description which will be sent in [Close] WebSocket frame. diff --git a/src/api/client/rpc_connection.rs b/src/api/client/rpc_connection.rs index 2896be1d1..abfbd5924 100644 --- a/src/api/client/rpc_connection.rs +++ b/src/api/client/rpc_connection.rs @@ -24,8 +24,9 @@ pub struct EventMessage(Event); /// /// [`Member`]: crate::signalling::elements::member::Member pub trait RpcConnection: fmt::Debug + Send { - /// Closes [`RpcConnection`] and send [`CloseDescription`] to the client (in - /// WebSocket implementation description will be sent in [Close] frame). + /// Closes [`RpcConnection`] and sends [`CloseDescription`] to the client + /// (in WebSocket implementation description will be sent in [Close] + /// frame). /// /// No [`RpcConnectionClosed`] signals should be emitted. /// diff --git a/src/api/client/session.rs b/src/api/client/session.rs index 59450f8e1..2fec7aedf 100644 --- a/src/api/client/session.rs +++ b/src/api/client/session.rs @@ -6,9 +6,11 @@ use actix::{ fut::wrap_future, Actor, ActorContext, ActorFuture, Addr, AsyncContext, Handler, Message, StreamHandler, }; -use actix_web_actors::ws::{self, CloseReason, WebsocketContext}; +use actix_web_actors::ws::{self, CloseReason}; use futures::future::Future; -use medea_client_api_proto::{ClientMsg, CloseDescription, ServerMsg}; +use medea_client_api_proto::{ + ClientMsg, CloseDescription, RpcConnectionCloseReason, ServerMsg, +}; use crate::{ api::{ @@ -63,11 +65,7 @@ impl WsSession { } } - fn close_normal(&self, ctx: &mut WebsocketContext) { - ctx.notify(Close(ws::CloseCode::Normal.into())); - } - - /// Start watchdog which will drop connection if now-last_activity > + /// Starts watchdog which will drop connection if now-last_activity > /// idle_timeout. fn start_watchdog(&mut self, ctx: &mut ::Context) { ctx.run_interval(Duration::new(1, 0), |session, ctx| { @@ -85,7 +83,9 @@ impl WsSession { session.member_id, err, ) } - session.close_normal(ctx); + ctx.notify(Close::with_normal_code(&CloseDescription::new( + RpcConnectionCloseReason::Idle, + ))) } }); } @@ -118,7 +118,11 @@ impl Actor for WsSession { {:?}", session.member_id, e ); - session.close_normal(ctx); + ctx.notify(Close::with_normal_code( + &CloseDescription::new( + RpcConnectionCloseReason::ConnectionRejected, + ), + )); } }, ) @@ -131,7 +135,11 @@ impl Actor for WsSession { {:?}", session.member_id, send_err, ); - session.close_normal(ctx); + ctx.notify(Close::with_normal_code( + &CloseDescription::new( + RpcConnectionCloseReason::ServerError, + ), + )); }, ), ); @@ -154,13 +162,9 @@ impl RpcConnection for Addr { close_description: CloseDescription, ) -> Box> { let fut = self - .send(Close(CloseReason { - code: ws::CloseCode::Normal, - description: Some( - serde_json::to_string(&close_description).unwrap(), - ), - })) + .send(Close::with_normal_code(&close_description)) .or_else(|_| Ok(())); + Box::new(fut) } @@ -179,13 +183,20 @@ impl RpcConnection for Addr { } /// Message for closing [`WsSession`]. -/// -/// [`CloseReason`] will be sent in WebSocket [Close] frame's description. -/// -/// [Close]: https://tools.ietf.org/html/rfc6455#section-5.5.1 #[derive(Message)] pub struct Close(CloseReason); +impl Close { + /// Creates [`Close`] message with [`ws::CloseCode::Normal`] and provided + /// [`CloseDescription`] as serialized description. + fn with_normal_code(description: &CloseDescription) -> Self { + Self(CloseReason { + code: ws::CloseCode::Normal, + description: Some(serde_json::to_string(&description).unwrap()), + }) + } +} + impl Handler for WsSession { type Result = (); From 0ce7b9e1ed288c2db642aa4ecc56313c05eb106b Mon Sep 17 00:00:00 2001 From: Semen Evdokimov Date: Wed, 9 Oct 2019 13:16:44 +0300 Subject: [PATCH 5/8] Update CHANGELOGs --- CHANGELOG.md | 6 +++++- proto/client-api/CHANGELOG.md | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ce14619e..cb621dc35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,11 +18,15 @@ All user visible changes to this project will be documented in this file. This p - Signalling: - Dynamic `Peer`s creation when client connects ([#28]); - Auto-removing `Peer`s when `Member` disconnects ([#28]); - - Filter `SetIceCandidate` messages without `candidate` ([#50](/../../pull/50)). + - Filter `SetIceCandidate` messages without `candidate` ([#50](/../../pull/50)); + - Send reason of closing WebSocket as [Close](https://tools.ietf.org/html/rfc4566#section-5.14) + frame's description ([#58]). - Testing: - E2E tests for signalling ([#28]). [#28]: /../../pull/28 +[#58]: /../../pull/58 + diff --git a/proto/client-api/CHANGELOG.md b/proto/client-api/CHANGELOG.md index 32c8174e6..aeec4ebea 100644 --- a/proto/client-api/CHANGELOG.md +++ b/proto/client-api/CHANGELOG.md @@ -12,9 +12,17 @@ All user visible changes to this project will be documented in this file. This p ### Added - `TrackId` and `PeerId` types ([#28]); -- `Incrementable` trait ([#28]). +- `Incrementable` trait ([#28]); +- `RpcConnectionCloseReason` and `CloseDescription` types ([#58]); +- `RpcConnectionCloseReason` variants: + - `Finished` ([#58]); + - `NewConnection` ([#58]); + - `Idle` ([#58]); + - `ConnectionRejected` ([#58]); + - `ServerError` ([#58]). [#28]: /../../pull/28 +[#58]: /../../pull/58 From 0b54045ceccc8144b61abd4e414c22338c721fc4 Mon Sep 17 00:00:00 2001 From: Semen Evdokimov Date: Wed, 9 Oct 2019 16:45:43 +0300 Subject: [PATCH 6/8] Fix test [run ci] --- src/api/client/server.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/api/client/server.rs b/src/api/client/server.rs index d9cd8df00..d638b2d10 100644 --- a/src/api/client/server.rs +++ b/src/api/client/server.rs @@ -145,6 +145,7 @@ mod test { use actix_http::{ws::Message, HttpService}; use actix_http_test::{TestServer, TestServerRuntime}; + use actix_web_actors::ws::CloseReason; use futures::{future::IntoFuture as _, sink::Sink as _, Stream as _}; use crate::{ @@ -153,6 +154,8 @@ mod test { }; use super::*; + use crate::api::client::session::Close; + use medea_client_api_proto::{CloseDescription, RpcConnectionCloseReason}; /// Creates [`RoomsRepository`] for tests filled with a single [`Room`]. fn room(conf: Rpc) -> RoomRepository { @@ -230,9 +233,22 @@ mod test { read.into_future() .map_err(|(e, _)| panic!("{:?}", e)) .map(|(item, _)| { + let description = CloseDescription::new( + RpcConnectionCloseReason::Idle, + ); + let close_reason = CloseReason { + code: ws::CloseCode::Normal, + description: Some( + serde_json::to_string( + &description, + ) + .unwrap(), + ), + }; + assert_eq!( Some(ws::Frame::Close(Some( - ws::CloseCode::Normal.into() + close_reason ))), item ); From 7a614ad78265e001857d065bbb7037f436bb5b32 Mon Sep 17 00:00:00 2001 From: Semen Evdokimov Date: Wed, 9 Oct 2019 18:25:26 +0300 Subject: [PATCH 7/8] Small fix formatting --- src/api/client/server.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/api/client/server.rs b/src/api/client/server.rs index d638b2d10..9ec00bd5e 100644 --- a/src/api/client/server.rs +++ b/src/api/client/server.rs @@ -147,6 +147,7 @@ mod test { use actix_http_test::{TestServer, TestServerRuntime}; use actix_web_actors::ws::CloseReason; use futures::{future::IntoFuture as _, sink::Sink as _, Stream as _}; + use medea_client_api_proto::{CloseDescription, RpcConnectionCloseReason}; use crate::{ api::control, conf::Conf, signalling::Room, @@ -154,8 +155,6 @@ mod test { }; use super::*; - use crate::api::client::session::Close; - use medea_client_api_proto::{CloseDescription, RpcConnectionCloseReason}; /// Creates [`RoomsRepository`] for tests filled with a single [`Room`]. fn room(conf: Rpc) -> RoomRepository { From 2b069e6328f44cfc6769f1527362a73e287b04ca Mon Sep 17 00:00:00 2001 From: tyranron Date: Thu, 10 Oct 2019 09:38:48 +0200 Subject: [PATCH 8/8] Corrections --- CHANGELOG.md | 5 +---- proto/client-api/CHANGELOG.md | 9 +------- proto/client-api/src/lib.rs | 38 ++++++++++++++++---------------- src/api/client/rpc_connection.rs | 4 ++-- src/api/client/server.rs | 7 +++--- src/api/client/session.rs | 18 ++++++--------- src/signalling/participants.rs | 15 +++++-------- 7 files changed, 39 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb621dc35..d08fd6095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,14 +19,11 @@ All user visible changes to this project will be documented in this file. This p - Dynamic `Peer`s creation when client connects ([#28]); - Auto-removing `Peer`s when `Member` disconnects ([#28]); - Filter `SetIceCandidate` messages without `candidate` ([#50](/../../pull/50)); - - Send reason of closing WebSocket as [Close](https://tools.ietf.org/html/rfc4566#section-5.14) - frame's description ([#58]). + - Send reason of closing WebSocket connection as [Close](https://tools.ietf.org/html/rfc4566#section-5.14) frame's description ([#58](/../../pull/58)). - Testing: - E2E tests for signalling ([#28]). [#28]: /../../pull/28 -[#58]: /../../pull/58 - diff --git a/proto/client-api/CHANGELOG.md b/proto/client-api/CHANGELOG.md index aeec4ebea..6c00a9def 100644 --- a/proto/client-api/CHANGELOG.md +++ b/proto/client-api/CHANGELOG.md @@ -13,16 +13,9 @@ All user visible changes to this project will be documented in this file. This p - `TrackId` and `PeerId` types ([#28]); - `Incrementable` trait ([#28]); -- `RpcConnectionCloseReason` and `CloseDescription` types ([#58]); -- `RpcConnectionCloseReason` variants: - - `Finished` ([#58]); - - `NewConnection` ([#58]); - - `Idle` ([#58]); - - `ConnectionRejected` ([#58]); - - `ServerError` ([#58]). +- `CloseReason` and `CloseDescription` types ([#58](/../../pull/58)). [#28]: /../../pull/28 -[#58]: /../../pull/58 diff --git a/proto/client-api/src/lib.rs b/proto/client-api/src/lib.rs index 7b706a8cc..acb15fab5 100644 --- a/proto/client-api/src/lib.rs +++ b/proto/client-api/src/lib.rs @@ -99,38 +99,38 @@ pub enum Command { }, } -/// Reason of disconnecting client from the server. +/// Reason of disconnecting Web Client from Media Server. #[derive(Debug, Deserialize, Serialize)] -pub enum RpcConnectionCloseReason { - /// Client session was finished on the server side. +pub enum CloseReason { + /// Client session was finished on a server side. Finished, - /// Old connection was closed due to client reconnection. - NewConnection, + /// Old connection was closed due to a client reconnection. + Reconnected, - /// Connection for a while was inactive and server considers that - /// connection is idle. + /// Connection has been inactive for a while and thus considered idle + /// by a server. Idle, - /// Establishing of connection with server was rejected on server side. + /// Establishing of connection with a server was rejected on server side. /// - /// Most likely because wrong `Member` credentials. - ConnectionRejected, + /// Most likely because of incorrect Member credentials. + Rejected, - /// Some server error was occurred while connecting. + /// Server internal error has occurred while connecting. /// - /// This close reason is similar to 500 HTTP code. That is, the client is - /// not to blame for this error. - ServerError, + /// This close reason is similar to 500 HTTP status code. + InternalError, } -/// Description which will be sent in [Close] WebSocket frame. +/// Description which is sent in [Close] WebSocket frame from Media Server +/// to Web Client. /// /// [Close]: https://tools.ietf.org/html/rfc6455#section-5.5.1 #[derive(Constructor, Debug, Deserialize, Serialize)] pub struct CloseDescription { - /// Reason of why connection was closed. - pub reason: RpcConnectionCloseReason, + /// Reason of why WebSocket connection has been closed. + pub reason: CloseReason, } /// WebSocket message from Medea to Jason. @@ -357,8 +357,8 @@ mod test { \"command\":\"MakeSdpOffer\",\ \"data\":{\ \"peer_id\":77,\ - \"sdp_offer\":\"offer\",\ - \"mids\":{\"0\":\"1\"}\ + \"sdp_offer\":\"offer\",\ + \"mids\":{\"0\":\"1\"}\ }\ }"; diff --git a/src/api/client/rpc_connection.rs b/src/api/client/rpc_connection.rs index abfbd5924..0fc051af0 100644 --- a/src/api/client/rpc_connection.rs +++ b/src/api/client/rpc_connection.rs @@ -25,12 +25,12 @@ pub struct EventMessage(Event); /// [`Member`]: crate::signalling::elements::member::Member pub trait RpcConnection: fmt::Debug + Send { /// Closes [`RpcConnection`] and sends [`CloseDescription`] to the client - /// (in WebSocket implementation description will be sent in [Close] + /// (in WebSocket implementation description will be sent in a [Close] /// frame). /// /// No [`RpcConnectionClosed`] signals should be emitted. /// - /// Always returns success. + /// Always succeeds. /// /// [Close]: https://tools.ietf.org/html/rfc6455#section-5.5.1 fn close( diff --git a/src/api/client/server.rs b/src/api/client/server.rs index 9ec00bd5e..a720cddb2 100644 --- a/src/api/client/server.rs +++ b/src/api/client/server.rs @@ -145,9 +145,8 @@ mod test { use actix_http::{ws::Message, HttpService}; use actix_http_test::{TestServer, TestServerRuntime}; - use actix_web_actors::ws::CloseReason; use futures::{future::IntoFuture as _, sink::Sink as _, Stream as _}; - use medea_client_api_proto::{CloseDescription, RpcConnectionCloseReason}; + use medea_client_api_proto::{CloseDescription, CloseReason}; use crate::{ api::control, conf::Conf, signalling::Room, @@ -233,9 +232,9 @@ mod test { .map_err(|(e, _)| panic!("{:?}", e)) .map(|(item, _)| { let description = CloseDescription::new( - RpcConnectionCloseReason::Idle, + CloseReason::Idle, ); - let close_reason = CloseReason { + let close_reason = ws::CloseReason { code: ws::CloseCode::Normal, description: Some( serde_json::to_string( diff --git a/src/api/client/session.rs b/src/api/client/session.rs index 2fec7aedf..5a18e29a6 100644 --- a/src/api/client/session.rs +++ b/src/api/client/session.rs @@ -6,10 +6,10 @@ use actix::{ fut::wrap_future, Actor, ActorContext, ActorFuture, Addr, AsyncContext, Handler, Message, StreamHandler, }; -use actix_web_actors::ws::{self, CloseReason}; +use actix_web_actors::ws; use futures::future::Future; use medea_client_api_proto::{ - ClientMsg, CloseDescription, RpcConnectionCloseReason, ServerMsg, + ClientMsg, CloseDescription, CloseReason, ServerMsg, }; use crate::{ @@ -84,7 +84,7 @@ impl WsSession { ) } ctx.notify(Close::with_normal_code(&CloseDescription::new( - RpcConnectionCloseReason::Idle, + CloseReason::Idle, ))) } }); @@ -119,9 +119,7 @@ impl Actor for WsSession { session.member_id, e ); ctx.notify(Close::with_normal_code( - &CloseDescription::new( - RpcConnectionCloseReason::ConnectionRejected, - ), + &CloseDescription::new(CloseReason::Rejected), )); } }, @@ -136,9 +134,7 @@ impl Actor for WsSession { session.member_id, send_err, ); ctx.notify(Close::with_normal_code( - &CloseDescription::new( - RpcConnectionCloseReason::ServerError, - ), + &CloseDescription::new(CloseReason::InternalError), )); }, ), @@ -184,13 +180,13 @@ impl RpcConnection for Addr { /// Message for closing [`WsSession`]. #[derive(Message)] -pub struct Close(CloseReason); +pub struct Close(ws::CloseReason); impl Close { /// Creates [`Close`] message with [`ws::CloseCode::Normal`] and provided /// [`CloseDescription`] as serialized description. fn with_normal_code(description: &CloseDescription) -> Self { - Self(CloseReason { + Self(ws::CloseReason { code: ws::CloseCode::Normal, description: Some(serde_json::to_string(&description).unwrap()), }) diff --git a/src/signalling/participants.rs b/src/signalling/participants.rs index a98b66d27..a77b81799 100644 --- a/src/signalling/participants.rs +++ b/src/signalling/participants.rs @@ -24,9 +24,7 @@ use futures::{ Future, }; -use medea_client_api_proto::{ - CloseDescription, Event, RpcConnectionCloseReason, -}; +use medea_client_api_proto::{CloseDescription, CloseReason, Event}; use crate::{ api::{ @@ -199,9 +197,7 @@ impl ParticipantService { } Box::new(wrap_future( connection - .close(CloseDescription::new( - RpcConnectionCloseReason::NewConnection, - )) + .close(CloseDescription::new(CloseReason::Reconnected)) .then(move |_| Ok(member)), )) } else { @@ -307,9 +303,10 @@ impl ParticipantService { let mut close_fut = self.connections.drain().fold( vec![], |mut futures, (_, mut connection)| { - futures.push(connection.close(CloseDescription::new( - RpcConnectionCloseReason::Finished, - ))); + futures.push( + connection + .close(CloseDescription::new(CloseReason::Finished)), + ); futures }, );