Пример #1
0
        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();
        }
Пример #2
0
        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();
        }
Пример #3
0
        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();
        }