private void SetupEvents() { Socket.OnMessage((s, e) => { SocketMessageEventArgs args = new SocketMessageEventArgs { Message = s }; MessageReceived?.Invoke(this, args); }); Socket.OnConnect((s) => { SocketOpened?.Invoke(this, null); }); Socket.OnDisconnect((status, reason, socket) => { SocketClosedEventArgs args = new SocketClosedEventArgs { Reason = reason, WasClean = false, Code = status }; Console.WriteLine(status); SocketClosed?.Invoke(this, args); }); }
/// <summary> /// Connects to the WebSocket server. /// </summary> public void Connect() { //await _ws.ConnectAsync(_uri, _cancellationToken); _ws.ConnectAsync(_uri, _cancellationToken).Wait(); SocketOpened?.Invoke(this, null); StartListen(); }
/// <summary> /// Raises the SocketOpened event. /// </summary> protected void InvokeSocketOpened() { var prevSocketOpenedEventCount = Interlocked.CompareExchange(ref _socketOpenedEventCount, 1, 0); if (prevSocketOpenedEventCount == 0) { SocketOpened?.Invoke(this, EventArgs.Empty); } }
protected override void OnProcessOutputSchema(MutableObject newSchema) { SocketOpened.TransmitSchema(newSchema); var perStepSchema = newSchema.CloneKeys(); StringDataTarget.SetValue("String Data", perStepSchema); ReceivedData.TransmitSchema(perStepSchema); }
private async Task Connect() { if (_conn != null) { await _conn.DisposeAsync(); } _currentHeartbeatInterval = null; _conn = new ShardConnection(_uri, _logger, _jsonSerializerOptions) { OnReceive = OnReceive, OnOpen = () => SocketOpened?.Invoke(), OnClose = (closeStatus, message) => SocketClosed?.Invoke(closeStatus, message) }; }
/// <summary> /// Hooks up events to automatically be redirected to the interface's events. /// </summary> private void HookupEvents() { Socket.OnMessage += (sender, e) => { SocketMessageEventArgs args = new SocketMessageEventArgs { Message = e.Data }; MessageReceived?.Invoke(this, args); }; Socket.OnError += (sender, e) => { SocketErrorEventArgs args = new SocketErrorEventArgs { Exception = e.Exception, Message = e.Message }; SocketError?.Invoke(this, args); }; Socket.OnClose += (sender, e) => { SocketClosedEventArgs args = new SocketClosedEventArgs { Code = e.Code, Reason = e.Reason, WasClean = e.WasClean }; SocketClosed?.Invoke(this, args); }; Socket.OnOpen += (sender, e) => { SocketOpened?.Invoke(this, null); }; }
/// <summary> /// Handles <see cref="IWebSocket.Opened"/> event. /// </summary> protected virtual void OnOpened() => SocketOpened?.Invoke();
private void WebSocket_OnOpen(object sender, EventArgs e) { IsOpen = true; SocketOpened?.Invoke(this, e); }
private void WebSocket_OnOpen(object sender, EventArgs e) { SocketOpened?.Invoke(sender, new WebSocketOpenEventArgs()); }
/// <summary> /// Handles <see cref="IWebSocket.Open"/> event. /// </summary> protected virtual void OnOpened(object sender, EventArgs e) => SocketOpened?.Invoke();
private void WebSocket_Opened(object sender, EventArgs e) => SocketOpened?.Invoke(this, EventArgs.Empty);