Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //OnConnected event we are
- //Binding all the requested client into a list
- public override Task OnConnected()
- {
- //Creating UserConnection object
- UserConnection objUserConnection = new UserConnection();
- //Assigning UserName from a queryString
- objUserConnection.UserName = Context.Request.QueryString["UserName"].ToString();
- //Assigning ConnectionId
- objUserConnection.ConnectionID = Context.ConnectionId;
- //Adding object into list
- _listUserConnetion.Add(objUserConnection);
- if (_listUserConnetion != null)
- {
- //Sending data to connected cliets
- SendData(objUserConnection.ConnectionID);
- }
- return base.OnConnected();
- }
- //OnDisconnected we will remove connectionId
- //From UserConnection list
- //It takes near around 35 seconds to call OnDisconnect
- public override Task OnDisconnected(bool stopCalled)
- {
- if (!stopCalled)
- {
- //Finding Connection based on ConnectionId
- var userToBeRemove = _listUserConnetion.Find(o => o.ConnectionID == Context.ConnectionId);
- //Removing object from list
- _listUserConnetion.Remove(userToBeRemove);
- }
- return base.OnDisconnected(false);
- }
- //OnReconnect Signalr send the data to user
- public override Task OnReconnected()
- {
- //Check if UserExist
- var checkUserIsExists = _listUserConnetion.Find(o => o.ConnectionID == Context.ConnectionId);
- if (checkUserIsExists != null)
- {
- //Send the data
- SendData(checkUserIsExists.ConnectionID);
- }
- return base.OnReconnected();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement