protected override async void OnClientConnected( IWebSocketContext context, System.Net.IPEndPoint localEndPoint, System.Net.IPEndPoint remoteEndPoint) { context.RequestRegexUrlParams("/ws/{token}").TryGetValue("token", out object token); bool valid = false; try { valid = await JWTService.Validate(token.ToString(), this.web.secret); } catch (Exception e) { this.api.Server.Logger.Warning(e.Message); } if (valid) { var response = new IServerAPIToJSON(api.Server); var msg = new WSMessage("Notification", "Websocket server started."); Send(context, msg.ToJSON()); return; } var err = new WSMessage("Error", "Unauthorized"); Send(context, err.ToJSON()); await context.WebSocket.CloseAsync(); }
private void OnServerLogEntry(EnumLogType logType, string message, object[] args) { if (logType == EnumLogType.VerboseDebug) { return; } var msg = new WSMessage(logType.ToString(), BuildLogEntry(message, args)); SendWSMessage?.Invoke(null, msg); }