/// <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> /// This function will handle the serialized data received from the networking module. /// It will first deserialize and then handle the appropriate cases. /// </summary> /// <param name="serializedData"> The serialized string sent by the networking module </param> public void OnDataReceived(string serializedData) { // Deserialize the data when it arrives ServerToClientData deserializedObject = _serializer.Deserialize <ServerToClientData>(serializedData); // check the event type and get the object sent from the server side string eventType = deserializedObject.eventType; // based on the type of event, calling the appropriate functions switch (eventType) { case "addClient": UpdateClientSessionData(deserializedObject); return; case "getSummary": UpdateSummary(deserializedObject); return; case "removeClient": UpdateClientSessionData(deserializedObject); return; case "endMeet": MeetingEnded?.Invoke(); return; default: throw new NotImplementedException(); } }
public void AddClientProcedure_NewClientArrivalServerSide_BroadcastsSessionObjectToAllClientsAndUpdatesNetworkModule() { int sampleSize = 10; List <UserData> users = Utils.GenerateUserData(sampleSize); AddUsersAtServer(users); // The last inserted user should get a object that has all the previously added clients ServerToClientData recievedData = _serializer.Deserialize <ServerToClientData>(_testCommunicator.sentData); SessionData sessionData = recievedData.sessionData; Assert.NotNull(sessionData); CollectionAssert.AreEqual(users, sessionData.users); Assert.AreEqual(sampleSize, _testCommunicator.clientCount); }
/// <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); }