public async Task ConnectAsync() { _connection = new HubConnection(Url); _hubProxy = _connection.CreateHubProxy("ChatHub"); _hubProxy.On <User>("ParticipantLogin", (u) => ParticipantLoggedIn?.Invoke(u)); _hubProxy.On <string>("ParticipantDisconnection", (n) => ParticipantDisconnected?.Invoke(n)); _hubProxy.On <string>("ParticipantLogout", (n) => ParticipantLoggedOut?.Invoke(n)); _hubProxy.On <string>("ParticipantReconnection", (n) => ParticipantReconnected?.Invoke(n)); _hubProxy.On <string>("ParticipantTyping", (p) => ParticipantTyping?.Invoke(p)); _hubProxy.On <string, string>("BroadcastTextMessage", (n, m) => NewTextMessage?.Invoke(n, m, MessageType.Broadcast)); _hubProxy.On <string, byte[]>("BroadcastPictureMessage", (n, m) => NewImageMessage?.Invoke(n, m, MessageType.Broadcast)); _hubProxy.On <string, string>("UnicastTextMessage", (n, m) => NewTextMessage?.Invoke(n, m, MessageType.Unicast)); _hubProxy.On <string, byte[]>("UnicastPictureMessage", (n, m) => NewImageMessage?.Invoke(n, m, MessageType.Unicast)); _connection.Reconnecting += Reconnecting; _connection.Reconnected += Reconnected; _connection.Closed += Disconnected; ServicePointManager.DefaultConnectionLimit = 30; await _connection.Start(); }
public async Task ConnectAsync() { connection = new HubConnection(url); connection.TraceLevel = TraceLevels.All; connection.TraceWriter = Console.Out; hubProxy = connection.CreateHubProxy("ChatHub"); hubProxy.On <string>("ParticipantDisconnection", (n) => ParticipantDisconnected?.Invoke(n)); hubProxy.On <string>("ParticipantLogout", (n) => ParticipantLoggedOut?.Invoke(n)); hubProxy.On <User>("ParticipantLogin", (u) => ParticipantLoggedIn?.Invoke(u)); hubProxy.On <string>("ParticipantReconnection", (n) => ParticipantReconnected?.Invoke(n)); hubProxy.On <string, string>("BroadcastTextMessage", (n, m) => NewTextMessage?.Invoke(n, m, MessageType.Broadcast)); hubProxy.On <string, string>("UnicastTextMessage", (n, m) => NewTextMessage?.Invoke(n, m, MessageType.Unicast)); hubProxy.On <string>("ParticipantTyping", (p) => ParticipantTyping?.Invoke(p)); hubProxy.On <string, int>("InviteToPlay", (p, t) => InviteToPlay?.Invoke(p, t)); hubProxy.On <string, string>("GetResponse", (p, q) => GetResponse?.Invoke(p, q)); hubProxy.On <string, int, int, int, int, bool?, string>("ReceiveMove", (p1, p2, p3, p4, p5, p6, p7) => ReceiveMove?.Invoke(p1, p2, p3, p4, p5, p6, p7)); hubProxy.On <string, bool>("NotifyIsInGame", (p1, p2) => NotifyIsInGame?.Invoke(p1, p2)); hubProxy.On("ParticipantDisconnectedWinGame", () => ParticipantDisconnectedWinGame?.Invoke()); hubProxy.On("ParticipantSurrended", () => ParticipantSurrended?.Invoke()); connection.Reconnecting += Reconnecting; connection.Reconnected += Reconnected; connection.Closed += Disconnected; ServicePointManager.DefaultConnectionLimit = 10; await connection.Start(); }
public async Task ConnectAsync() { connection = new HubConnection(url); hubProxy = connection.CreateHubProxy("ChatHub"); hubProxy.On <User>("ParticipantLogin", (u) => ParticipantLoggedIn?.Invoke(u)); hubProxy.On <string>("ParticipantLogout", (n) => ParticipantLoggedOut?.Invoke(n)); hubProxy.On <string>("ParticipantDisconnection", (n) => ParticipantDisconnected?.Invoke(n)); hubProxy.On <string>("ParticipantReconnection", (n) => ParticipantReconnected?.Invoke(n)); hubProxy.On <string>("BroadcastGameStart", (n) => GameStart?.Invoke(n, MessageType.Broadcast)); hubProxy.On <string>("BroadcastGameEnd", (n) => GameEnd?.Invoke(n, MessageType.Broadcast)); hubProxy.On <string, string>("BroadcastSetHost", (n, m) => SetNewHost?.Invoke(n, m, MessageType.Broadcast)); hubProxy.On <string, string>("BroadcastTextMessage", (n, m) => NewTextMessage?.Invoke(n, m, MessageType.Broadcast)); hubProxy.On <string, byte[]>("BroadcastPictureMessage", (n, m) => NewImageMessage?.Invoke(n, m, MessageType.Broadcast)); hubProxy.On <string, byte[]>("BroadcastStrokes", (n, m) => NewStrokesCollected?.Invoke(n, m, MessageType.Broadcast)); hubProxy.On <string, string>("BraodcastAnswerIsRight", (n, m) => Correct?.Invoke(n, m)); hubProxy.On <string, string>("UnicastTextMessage", (n, m) => NewTextMessage?.Invoke(n, m, MessageType.Unicast)); hubProxy.On <string, byte[]>("UnicastPictureMessage", (n, m) => NewImageMessage?.Invoke(n, m, MessageType.Unicast)); hubProxy.On <string>("ParticipantTyping", (p) => ParticipantTyping?.Invoke(p)); connection.Reconnecting += Reconnecting; connection.Reconnected += Reconnected; connection.Closed += Disconnected; ServicePointManager.DefaultConnectionLimit = 10; await connection.Start(); }
public void Connect() { try { connection = new HubConnectionBuilder().WithUrl(url).Build(); connection.On <string, string>("SendMessage", (n, m) => NewTextMessage?.Invoke(n, m)); ServicePointManager.DefaultConnectionLimit = 10; connection.StartAsync(); } catch (Exception ex) { throw; } }
public async Task ConnectAsync() { connection = new HubConnection(url); hubProxy = connection.CreateHubProxy("ChatHub"); hubProxy.On <User>("ParticipantLogin", (login) => ParticipantLoggedIn?.Invoke(login)); hubProxy.On <string>("ParticipantLogout", (logout) => ParticipantLoggedOut?.Invoke(logout)); hubProxy.On <string>("ParticipantReconnection", (recon) => ParticipantReconnected?.Invoke(recon)); hubProxy.On <string>("ParticipantDisconnection", (discon) => ParticipantDisconnected?.Invoke(discon)); hubProxy.On <string, string>("BroadcastTextMessage", (sender, message) => NewTextMessage?.Invoke(sender, message, MessageType.Broadcast)); hubProxy.On <string, byte[]>("BroadcastPicturePhoto", (sender, img) => NewImageMessage?.Invoke(sender, img, MessageType.Broadcast)); hubProxy.On <string, byte[]>("UnicastPicturePhoto", (sender, img) => NewImageMessage?.Invoke(sender, img, MessageType.Unicast)); hubProxy.On <string, string>("UnicastTextMessage", (sender, message) => NewTextMessage?.Invoke(sender, message, MessageType.Unicast)); hubProxy.On <string>("ParticipantTyping", (sender) => ParticipantTyping?.Invoke(sender)); connection.Reconnecting += Connection_Reconnecting; connection.Reconnected += Connection_Reconnected; connection.Closed += Disconnected; ServicePointManager.DefaultConnectionLimit = 7; await connection.Start(); }
private void HandleTextMessage(Message message) { _textMessages.Add(message); NewTextMessage?.Invoke(this, GetSender(message), message); }