Overall improve log messages

This commit is contained in:
Dominik Nakamura 2022-05-21 21:28:51 +09:00
parent fd5d52405d
commit c7dc7a5d96
No known key found for this signature in database
GPG Key ID: E4C6A749B2491910
2 changed files with 14 additions and 39 deletions

View File

@ -160,7 +160,7 @@ pub(super) async fn handshake(
ServerMessage::Identified(Identified {
negotiated_rpc_version,
}) => {
debug!("identified with RPC version {}", negotiated_rpc_version);
debug!(rpc_version = %negotiated_rpc_version, "identified against obs-websocket");
}
_ => return Err(HandshakeError::NoIdentified),
}
@ -187,33 +187,3 @@ fn create_auth_response(challenge: &str, salt: &str, password: &str) -> String {
auth
}
/// Possible custom web-socket close codes, that are send by the server in case of a problem.
pub enum WebSocketCloseCode {
/// For internal use only to tell the request handler not to perform any close action.
DontClose = 0,
/// Unknown reason, should never be used.
UnknownReason = 4000,
/// The server was unable to decode the incoming web-socket message.
MessageDecodeError = 4002,
/// A data field is required but missing from the payload.
MissingDataField = 4003,
/// A data field's value type is invalid.
InvalidDataFieldType = 4004,
/// A data field's value is invalid.
InvalidDataFieldValue = 4005,
/// The specified `op` was invalid or missing.
UnknownOpCode = 4006,
/// The client sent a web-socket message without first sending `Identify` message.
NotIdentified = 4007,
/// The client sent an `Identify` message while already identified.
AlreadyIdentified = 4008,
/// The authentication attempt (via `Identify`) failed.
AuthenticationFailed = 4009,
/// The server detected the usage of an old version of the obs-websocket RPC protocol.
UnsupportedRpcVersion = 4010,
/// The web-socket session has been invalidated by the obs-websocket server.
SessionInvalidated = 4011,
/// A requested feature is not supported due to hardware/software limitations.
UnsupportedFeature = 4012,
}

View File

@ -19,8 +19,11 @@ use serde::de::DeserializeOwned;
#[cfg(feature = "events")]
use tokio::sync::broadcast;
use tokio::{net::TcpStream, sync::Mutex, task::JoinHandle};
use tokio_tungstenite::{tungstenite::Message, MaybeTlsStream, WebSocketStream};
use tracing::{debug, error, trace};
use tokio_tungstenite::{
tungstenite::{protocol::CloseFrame, Message},
MaybeTlsStream, WebSocketStream,
};
use tracing::{debug, error, info, trace};
use self::connection::{ReceiverList, ReidentifyReceiverList};
pub use self::{
@ -233,14 +236,16 @@ impl Client {
match message {
ServerMessage::RequestResponse(response) => {
trace!("got message with id {}", response.request_id);
trace!(id = %response.request_id, "got request-response message");
receivers2.notify(response).await?;
}
#[cfg(feature = "events")]
ServerMessage::Event(event) => {
trace!("got OBS event");
events_tx.send(event).ok();
}
ServerMessage::Identified(identified) => {
trace!("got identified message");
reidentify_receivers2.notify(identified).await;
}
_ => return Err(InnerError::UnexpectedMessage(message)),
@ -250,8 +255,8 @@ impl Client {
}
.await;
if let Err(e) = res {
error!("failed handling message: {:?}", e);
if let Err(error) = res {
error!(?error, "failed handling message");
}
}
@ -323,7 +328,7 @@ impl Client {
let rx = self.receivers.add(id).await;
debug!("sending message: {}", json);
trace!(%json, "sending message");
let write_result = self
.write
.lock()
@ -388,8 +393,8 @@ impl Client {
let resp = rx.await.map_err(Error::ReceiveMessage)?;
debug!(
"re-identified with RPC version {}",
resp.negotiated_rpc_version
rpc_version = %resp.negotiated_rpc_version,
"re-identified against obs-websocket",
);
Ok(())