-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(relay): Remove reference to the Agent from Relay after it is disc…
…onnected. (#121)
- Loading branch information
Showing
7 changed files
with
81 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,23 @@ | ||
use crate::models::socket_reader::{SocketReader, SocketSubscriber}; | ||
use crate::models::socket_writer::{SocketPublisher, SocketWriter}; | ||
use crate::models::socket_connection::SocketConnection; | ||
use axum::extract::ws::WebSocket; | ||
use futures::StreamExt; | ||
|
||
pub struct FrontendConnection { | ||
frontend_writer: SocketWriter, | ||
frontend_reader: SocketReader, | ||
socket_connection: SocketConnection, | ||
} | ||
|
||
impl FrontendConnection { | ||
pub async fn new(socket: WebSocket) -> Self { | ||
let (frontend_writer, frontend_reader) = socket.split(); | ||
let frontend_reader = SocketReader::new(frontend_reader); | ||
let frontend_writer = SocketWriter::new(frontend_writer); | ||
let conn = SocketConnection::new(socket); | ||
Self { | ||
frontend_writer, | ||
frontend_reader, | ||
socket_connection: conn, | ||
} | ||
} | ||
|
||
pub fn publisher(&self) -> SocketPublisher { | ||
self.frontend_writer.publisher() | ||
} | ||
|
||
pub fn subscriber(&self) -> SocketSubscriber { | ||
self.frontend_reader.subscriber() | ||
pub fn socket(&self) -> &SocketConnection { | ||
&self.socket_connection | ||
} | ||
|
||
pub async fn close(&self) { | ||
let _ = self.frontend_writer.close().await; | ||
let _ = self.socket().writer().close().await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::models::socket_reader::{SocketReader, SocketSubscriber}; | ||
use crate::models::socket_writer::{SocketPublisher, SocketWriter}; | ||
use axum::extract::ws::WebSocket; | ||
use futures::StreamExt; | ||
use std::sync::Arc; | ||
use tokio::sync::Notify; | ||
|
||
pub struct SocketConnection { | ||
writer: SocketWriter, | ||
reader: SocketReader, | ||
close_notifier: Arc<Notify>, | ||
} | ||
|
||
impl SocketConnection { | ||
pub fn new(socket: WebSocket) -> Self { | ||
let (writer, reader) = socket.split(); | ||
let notifier = Arc::new(Notify::new()); | ||
Self { | ||
writer: SocketWriter::new(writer), | ||
reader: SocketReader::new(reader, notifier.clone()), | ||
close_notifier: notifier.clone(), | ||
} | ||
} | ||
|
||
pub fn close_notifier(&self) -> Arc<Notify> { | ||
self.close_notifier.clone() | ||
} | ||
|
||
pub fn writer(&self) -> &SocketWriter { | ||
&self.writer | ||
} | ||
|
||
pub fn publisher(&self) -> SocketPublisher { | ||
self.writer.publisher() | ||
} | ||
|
||
pub fn subscriber(&self) -> SocketSubscriber { | ||
self.reader.subscriber() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters