|
@@ -48,11 +48,15 @@ namespace InABox.Server.WebSocket
|
|
|
|
|
|
public class PushHandler : WebSocketBehavior
|
|
public class PushHandler : WebSocketBehavior
|
|
{
|
|
{
|
|
- private PushState PushState;
|
|
|
|
|
|
+ public PushState State { get; set; }
|
|
|
|
|
|
|
|
+ public PushHandler()
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
public PushHandler(PushState state)
|
|
public PushHandler(PushState state)
|
|
{
|
|
{
|
|
- PushState = state;
|
|
|
|
|
|
+ State = state;
|
|
}
|
|
}
|
|
|
|
|
|
protected override void OnOpen()
|
|
protected override void OnOpen()
|
|
@@ -64,8 +68,8 @@ namespace InABox.Server.WebSocket
|
|
{
|
|
{
|
|
Logger.Send(LogType.Information, "", $"WebSocket client disconnected");
|
|
Logger.Send(LogType.Information, "", $"WebSocket client disconnected");
|
|
|
|
|
|
- var sessionID = PushState.SessionMap.Where(x => x.Value.ID == ID).FirstOrDefault().Key;
|
|
|
|
- PushState.SessionMap.TryRemove(sessionID, out var session);
|
|
|
|
|
|
+ var sessionID = State.SessionMap.FirstOrDefault(x => x.Value.ID == ID).Key;
|
|
|
|
+ State.SessionMap.TryRemove(sessionID, out var session);
|
|
}
|
|
}
|
|
|
|
|
|
protected override void OnError(WebSocketSharp.ErrorEventArgs e)
|
|
protected override void OnError(WebSocketSharp.ErrorEventArgs e)
|
|
@@ -76,8 +80,8 @@ namespace InABox.Server.WebSocket
|
|
private void DoInitial(InitialMessage initial)
|
|
private void DoInitial(InitialMessage initial)
|
|
{
|
|
{
|
|
var newSession = new Session(ID, initial.SessionID, initial.Platform);
|
|
var newSession = new Session(ID, initial.SessionID, initial.Platform);
|
|
- PushState.SessionMap[initial.SessionID] = newSession;
|
|
|
|
- PushState.Poll(newSession);
|
|
|
|
|
|
+ State.SessionMap[initial.SessionID] = newSession;
|
|
|
|
+ State.Poll(newSession);
|
|
}
|
|
}
|
|
|
|
|
|
protected override void OnMessage(MessageEventArgs e)
|
|
protected override void OnMessage(MessageEventArgs e)
|
|
@@ -103,7 +107,10 @@ namespace InABox.Server.WebSocket
|
|
public WebSocketServer(int port)
|
|
public WebSocketServer(int port)
|
|
{
|
|
{
|
|
Server = new InternalServer(IPAddress.Any, port);
|
|
Server = new InternalServer(IPAddress.Any, port);
|
|
- Server.AddWebSocketService("/push", NewPush);
|
|
|
|
|
|
+ Server.AddWebSocketService<PushHandler>("/push", (push) =>
|
|
|
|
+ {
|
|
|
|
+ push.State = PushState;
|
|
|
|
+ });
|
|
|
|
|
|
PushState.OnPoll += PushState_Poll;
|
|
PushState.OnPoll += PushState_Poll;
|
|
}
|
|
}
|