예제 #1
0
        // Method that is invoked from client
        public void broadcastPositions(RoomPresence roomPresence)
        {
            var context = GlobalHost.ConnectionManager.GetHubContext <ServerHub>();

            // Calling client method
            context.Clients.All.broadcast(roomPresence);
        }
예제 #2
0
        // Helper method used for testing.
        public RoomPresence generateRoomPresence()
        {
            RoomPresence retVal = new RoomPresence();

            retVal.sensor = sensorId;
            retVal.room = DateTime.Now.Millisecond.ToString();
            retVal.timeStamp = DateTime.Now;

            //roomPresence = retVal;

            return retVal;
        }
예제 #3
0
        // Establishing connection, creating hub proxy and defining method that server can call. If flag is true invoke the broadcast
        public async void StartHub(RoomPresence testObject, bool flag)
        {

            var hubConnection = new HubConnection("http://localhost:8080");
            IHubProxy serverHubProxy = hubConnection.CreateHubProxy("ServerHub");
            serverHubProxy.On<RoomPresence>("broadcast", roomPresence => Console.WriteLine("Sensor '{0}' is in the room '{1}' on time: {2}", roomPresence.sensor, roomPresence.room, roomPresence.timeStamp));
            await hubConnection.Start();

            hubConnection.Error += ex => Console.WriteLine("SignalR error: {0}", ex.Message);

            // Invoking method on server

            if (flag)
            { 
                await serverHubProxy.Invoke("broadcastPositions", testObject);
            }


        }
예제 #4
0
 // Method that is invoked from client
 public void broadcastPositions(RoomPresence roomPresence)
 {
     var context = GlobalHost.ConnectionManager.GetHubContext<ServerHub>();
     // Calling client method
     context.Clients.All.broadcast(roomPresence);
 }