74 lines
2.7 KiB
C#
74 lines
2.7 KiB
C#
namespace bts.websocket_core;
|
|
|
|
using bts.websocket_core.json_rpc;
|
|
|
|
public class WebsocketConnectionUpdate {
|
|
readonly WebsocketClientID? connection;
|
|
readonly WebsocketIncomingMessage? incomingMessage;
|
|
readonly WebsocketOutgoingMessage? outgoingMessage;
|
|
readonly WebsocketConnectNotification? connect;
|
|
readonly WebsocketDisconnectNotification? disconnect;
|
|
|
|
WebsocketConnectionUpdate(
|
|
WebsocketClientID connection,
|
|
WebsocketIncomingMessage? incomingMessage = null,
|
|
WebsocketOutgoingMessage? outgoingMessage = null,
|
|
WebsocketConnectNotification? connect = null,
|
|
WebsocketDisconnectNotification? disconnect = null) {
|
|
this.connection = connection;
|
|
this.incomingMessage = incomingMessage;
|
|
this.outgoingMessage = outgoingMessage;
|
|
this.connect = connect;
|
|
this.disconnect = disconnect;
|
|
}
|
|
|
|
public static WebsocketConnectionUpdate Create(
|
|
WebsocketClientID connection, WebsocketConnectNotification connect) =>
|
|
new(connection, connect: connect);
|
|
|
|
public static WebsocketConnectionUpdate Create(
|
|
WebsocketClientID connection, WebsocketDisconnectNotification disconnect) =>
|
|
new(connection, disconnect: disconnect);
|
|
|
|
public static WebsocketConnectionUpdate Create(
|
|
WebsocketClientID connection, WebsocketIncomingMessage incomingMessage) =>
|
|
new(connection, incomingMessage: incomingMessage);
|
|
|
|
public static WebsocketConnectionUpdate Create(
|
|
WebsocketClientID connection, WebsocketOutgoingMessage outgoingMessage) =>
|
|
new(connection, outgoingMessage: outgoingMessage);
|
|
|
|
public WebsocketClientID Connection =>
|
|
connection ?? throw new InvalidOperationException();
|
|
|
|
public WebsocketConnectionUpdateType Type {
|
|
get {
|
|
if (incomingMessage is not null) {
|
|
return WebsocketConnectionUpdateType.IncomingMessage;
|
|
}
|
|
if (outgoingMessage is not null) {
|
|
return WebsocketConnectionUpdateType.OutgoingMessage;
|
|
}
|
|
if (connect is not null) {
|
|
return WebsocketConnectionUpdateType.Connect;
|
|
}
|
|
if (disconnect is not null) {
|
|
return WebsocketConnectionUpdateType.Disconnect;
|
|
}
|
|
return WebsocketConnectionUpdateType.Unspecified;
|
|
}
|
|
}
|
|
|
|
public WebsocketIncomingMessage IncomingMessage =>
|
|
incomingMessage ?? throw new InvalidOperationException();
|
|
|
|
public WebsocketOutgoingMessage OutgoingMessage =>
|
|
outgoingMessage ?? throw new InvalidOperationException();
|
|
|
|
public WebsocketConnectNotification Connect =>
|
|
connect ?? throw new InvalidOperationException();
|
|
|
|
public WebsocketDisconnectNotification Disconnect =>
|
|
disconnect ?? throw new InvalidOperationException();
|
|
}
|