private void LeaveRoom(string r, Room room, WebSocketDialog wsd) { if (room.Leave(wsd)) { _rooms.TryRemove(r, out room); } }
/// <summary> /// Do not invoke. Is invoked by the server with every websocket request /// </summary> public async Task <bool> Process(string path, Request req, Response res, WebSocketDialog wsd) { if (!_settings.ShouldAuthenticate(path)) { return(true); } string token = null; string auth = req.Headers["Authorization"]; if (string.IsNullOrEmpty(auth)) { await _settings.OnNotAuthenticated(req, res); return(false); } if (auth.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase)) { token = auth.Substring("Bearer ".Length).Trim(); } if (string.IsNullOrEmpty(token) || !TryAuthenticateToken(token, out var session)) { await _settings.OnNotAuthenticated(req, res); return(false); } req.SetData(session.Data); return(true); }
public void Add(WebSocketDialog wsd) { lock (_lock) { _connected.Add(wsd); } wsd.OnTextReceived += RelayMessage; BroadcastCount(); }
/// <summary> /// Do not invoke. Is invoked by the server with every websocket request /// </summary> public async Task <bool> Process(string path, Request req, Response res, WebSocketDialog wsd) { if (_settings.ShouldAuthenticate(path)) { return(await Authenticate(req, res)); } return(true); }
public void Join(string room, WebSocketDialog wsd) { Room r; if (!_rooms.TryGetValue(room, out r)) { r = new Room(); _rooms.TryAdd(room, r); } r.Add(wsd); wsd.OnClosed += (sender, args) => LeaveRoom(room, r, wsd); }
public bool Leave(WebSocketDialog wsd) { lock (_lock) { _connected.Remove(wsd); } if (_connected.Count == 0) { return(true); } BroadcastCount(); return(false); }
public WebSocketDialogChannelConnection(BaseSubscriptionApi subscriptionApi, WebSocketDialog webSocketDialog) : base(subscriptionApi) { this.webSocketDialog = webSocketDialog; this.webSocketDialog.OnTextReceived += (sender, eventArgs) => { try { this.ReceiveMessageAsync(eventArgs.Text).Wait(); } catch (Exception e) { logger.Trace(e); this.Dispose(); webSocketDialog.Close(); } }; }
public Player(string id, WebSocketDialog wsd) { Id = id; Wsd = wsd; }
static async Task <HandlerType> Auth(Request req, Response res, WebSocketDialog wsd) { return(HandlerType.Final); }
/// <summary> /// Do not invoke. Is invoked by the server with every websocket request /// </summary> public Task <HandlerType> Invoke(Request req, WebSocketDialog wsd, Response res) => InvokeInternal(req, res);
/// <summary> /// Do not invoke. Is invoked by the server with every websocket request /// </summary> public Task <HandlerType> Invoke(Request req, Response res, WebSocketDialog _) => Authenticate(req, res);
public WebSocketDialogWebRequest(WebSocketDialog webSocketDialog) { this.webSocketDialog = webSocketDialog; }