/// <summary> /// Compares the server side session data to the client side and update the /// client side data if they are different. /// </summary> /// <param name="recievedSessionData"> The sessionData received from the server side. </param> private void UpdateClientSessionData(ServerToClientData receivedData) { // fetching the session data and user received from the server side SessionData recievedSessionData = receivedData.sessionData; UserData user = receivedData.GetUser(); // if there was no change in the data then nothing needs to be done if (recievedSessionData == _clientSessionData) { return; } // a null _user denotes that the user is new and has not be set because all // the old user (already present in the meeting) have their _user set. if (_user == null) { _user = user; } // The user received from the server side is equal to _user only in the case of // client departure. So, the _user and received session data are set to null to indicate this departure else if (_user == user) { _user = null; recievedSessionData = null; } // update the sesseon data on the client side and notify the UX about it. lock (this) { _clientSessionData = (SessionData)recievedSessionData; } NotifyUXSession(); }
/// <summary> /// Updates the locally stored summary at the client side to the summary received from the /// server side. The summary will only be updated fro the user who requsted it. /// </summary> /// <param name="receivedData"> A ServerToClientData object that contains the summary /// created at the server side of the session manager.</param> private void UpdateSummary(ServerToClientData receivedData) { // Extract the summary string and the user. SummaryData receivedSummary = receivedData.summaryData; UserData receivedUser = receivedData.GetUser(); // check if the current user is the one who requested to get the // summary if (receivedUser.userID == _user.userID) { lock (this) { chatSummary = receivedSummary.summary; } } }
public void AddClientProcedure_NewClientArrivalServerSide_BroadcastsUserObjectToAllClients() { _testCommunicator.sentData = null; ClientToServerData clientToServerData = new("addClient", "John"); string serializedData = _serializer.Serialize(clientToServerData); serverSessionManager.OnClientJoined <TcpClient>(null); serverSessionManager.OnDataReceived(serializedData); ServerToClientData recievedData = _serializer.Deserialize <ServerToClientData>(_testCommunicator.sentData); UserData user = recievedData.GetUser(); Assert.NotNull(user); Assert.AreEqual("John", user.username); Assert.IsNotNull(user.userID); Assert.AreEqual("addClient", recievedData.eventType); }