Example #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();
        }
Example #2
0
        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();
        }
Example #3
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();
        }
 private void RegisterServerSideReceivingActions()
 {
     _hubProxy.On <User>("ParticipantLogin", loggedUser => ParticipantLoggedIn?.Invoke(loggedUser));
     _hubProxy.On <string>("ParticipantLogout", loggedOutUserName => ParticipantLoggedOut?.Invoke(loggedOutUserName));
     _hubProxy.On <string>("ParticipantDisconnection", disconnectionConnectionId => ParticipantDisconnected?.Invoke(disconnectionConnectionId));
     _hubProxy.On <string>("ParticipantReconnection", reconnectionConnectionId => ParticipantReconnected?.Invoke(reconnectionConnectionId));
     _hubProxy.On <string, string, DateTime, TimeSpan>("BroadcastMessage", (senderConnectionId, message, messagePostedDateTime, minDisplayTime) => NewMessage?.Invoke(senderConnectionId, message, messagePostedDateTime, minDisplayTime, MessageType.Broadcast));
     _hubProxy.On <string, string, DateTime>("UnicastMessage", (senderConnectionId, message, messagePostedDateTime) => NewMessage?.Invoke(senderConnectionId, message, messagePostedDateTime, TimeSpan.Zero, MessageType.Unicast));
     _hubProxy.On <string, string, DateTime, TimeSpan>("UnicastNotification", (senderConnectionId, message, messagePostedDateTime, minDisplayTime) => NewMessage?.Invoke(senderConnectionId, message, messagePostedDateTime, minDisplayTime, MessageType.UnicastNotification));
 }
Example #5
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, string>("BroadcastMessage", (n, m) => NewMessage?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, string>("UnicastMessage", (n, m) => NewMessage?.Invoke(n, m, MessageType.Unicast));
            connection.Reconnecting += Reconnecting;
            connection.Reconnected  += Reconnected;
            connection.Closed       += Disconnected;

            ServicePointManager.DefaultConnectionLimit = 10;
            await connection.Start();
        }
        public async Task ConnectAsync()
        {
            Connection = new HubConnectionBuilder()
                         .WithUrl(ServerURI)
                         .Build();
            Connection.On <string, string, string>("SendMessage", (name, sender, message) =>
                                                   SendMessage?.Invoke(name, sender, message));
            Connection.On <string, string, string>("SendGroupeMessage", (roomName, name, message) =>
                                                   AddMessageToGroup?.Invoke(roomName, name, message));
            Connection.On <User>("ParticipantLogin", (u) => ParticipantLoggedIn?.Invoke(u));
            Connection.On <string>("ParticipantLogout", (n) => ParticipantLoggedOut?.Invoke(n));
            Connection.On <string>("ParticipantDisconnection", (n) => ParticipantDisconnected?.Invoke(n));
            Connection.On <string>("ParticipantReconnection", (n) => ParticipantReconnected?.Invoke(n));
            Connection.On <string>("ParticipantTyping", (p) => ParticipantTyping?.Invoke(p));

            await Connection.StartAsync();
        }
        public async Task ConnectAsync()
        {
            string ipAdddresSett = ConfigurationManager.AppSettings["ipAddress"];
            int    ipPortSett    = Int32.Parse(ConfigurationManager.AppSettings["ipPort"]);

            connection = new HubConnection(string.Format(url, ipAdddresSett, ipPortSett));
            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, string>("BroadcastMessage", (n, m) => NewMessage?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, string>("UnicastMessage", (n, m) => NewMessage?.Invoke(n, m, MessageType.Unicast));
            hubProxy.On <string, string, string>("SetNewTask", (n, m, k) => SetNewTask?.Invoke(n, m, k));
            connection.Reconnecting += Reconnecting;
            connection.Reconnected  += Reconnected;
            connection.Closed       += Disconnected;

            ServicePointManager.DefaultConnectionLimit = 10;
            await connection.Start();
        }
Example #8
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();
        }