Пример #1
0
        internal async Task <bool> ConnectHub()
        {
            RunnersHubConnection =
                new HubConnection(eBuddyApp.Services.Azure.MobileService.Instance.Service.MobileAppUri.AbsoluteUri);
            RunnersHubProxy = RunnersHubConnection.CreateHubProxy("SocialRunsHub");

            if (eBuddyApp.Services.Azure.MobileService.Instance.Service.CurrentUser != null)
            {
                RunnersHubConnection.Headers["x-zumo-auth"] =
                    eBuddyApp.Services.Azure.MobileService.Instance.Service.CurrentUser.MobileServiceAuthenticationToken;
            }
            else
            {
                RunnersHubConnection.Headers["x-zumo-application"] = "";
            }

            await RunnersHubConnection.Start();


            if (RunnersHubConnection.State != ConnectionState.Connected)
            {
                return(false);
            }

            RunnersHubProxy.On <string>("runStart", OnHandShake);

            RunnersHubProxy.On <BuddyRunInfo>("buddyLocationUpdate", OnLocationMessage);

            await RunnersHubProxy.Invoke("Register",
                                         eBuddyApp.Services.Azure.MobileService.Instance.Service.CurrentUser.UserId);

            await RunnersHubProxy.Invoke("HandShake", "shiran6",
                                         eBuddyApp.Services.Azure.MobileService.Instance.Service.CurrentUser.UserId);

            return(true);
        }