示例#1
0
        public static async Task <bool> RequestParamValidator(IClientProxy iClient, RequestAccessData payload)
        {
            if (String.IsNullOrEmpty(payload.SecondaryClientUserId))
            {
                await iClient.SendAsync(ClientSyncConstants.ErrorHandler, "Missing the parameter of secondary client's userid'");

                return(false);
            }
            if (String.IsNullOrEmpty(payload.GroupName))
            {
                await iClient.SendAsync(ClientSyncConstants.ErrorHandler, "Missing the parameter of the group name for sync");

                return(false);
            }
            return(true);
        }
示例#2
0
        public async Task HandleRequest(Hub hub, RequestAccessData payload)
        {
            // 2nd client --> 1st client : I want to connect to TransportHub

            /**
             * payload has the following values:
             * {
             *   "demo.sync.client.groupname":"mySyncGroup",
             *   "demo.sync.2ndclient.userid":"2ndclient",
             *   "demo.sync.2ndclient.connection_id":"xxx"
             * }
             */
            var iClientProxy = hub.Clients.Client(hub.Context.ConnectionId);

            if (!await SyncServer.RequestParamValidator(iClientProxy, payload))
            {
                return;
            }
            payload.SecondaryClientConnectionId = hub.Context.ConnectionId;
            await hub.Clients.Group(payload.GroupName).SendAsync(ClientSyncConstants.RequestConnectToTransportHub, payload);
        }
示例#3
0
 private static Task JoinNotificationGroupAfterConnectedCore(HubConnection hubConnection, string groupName, string userId, bool requestToken)
 {
     hubConnection.On <string>(ClientSyncConstants.HubConnected, (connectionId) =>
     {
         var selfConnectionId = connectionId;
         Console.WriteLine($"connection Id {selfConnectionId}");
         hubConnection.SendAsync(ClientSyncConstants.JoinGroup, groupName);
     });
     hubConnection.On(ClientSyncConstants.JoinedGroup, async() =>
     {
         Console.WriteLine("Joined group");
         if (requestToken)
         {
             // the 2nd connection to notification hub wants to connect transport hub
             var requestAccess = new RequestAccessData()
             {
                 GroupName             = groupName,
                 SecondaryClientUserId = userId
             };
             await hubConnection.SendAsync(ClientSyncConstants.RequestAccess, requestAccess);
         }
     });
     return(Task.CompletedTask);
 }
示例#4
0
 public async Task RequestAccess(RequestAccessData payload)
 {
     var iClientProxy = Clients.Client(Context.ConnectionId);
     await _syncServer.HandleRequest(this, payload);
 }