Skip to content

Commit 484d96d

Browse files
committed
[ENH] Change for public API for chat demo to include timeStamp in message listener
- Public API onReceiveServerMessage and onReceiveP2PMessage have been changed to include timeStamp in Long type - Handle JSONObject when receiving from remote peer
1 parent 2786695 commit 484d96d

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

sampleapp/src/main/java/sg/com/temasys/skylink/sdk/sampleapp/chat/ChatPresenter.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import android.content.Context;
44
import android.util.Log;
55

6+
import org.json.JSONException;
7+
import org.json.JSONObject;
8+
69
import java.util.ArrayList;
710
import java.util.Date;
811
import java.util.List;
@@ -272,12 +275,25 @@ public void processServerMessageReceived(String remotePeerId, Object message, bo
272275
chatPrefix = "[GRP]" + chatPrefix;
273276
}
274277

278+
String remotePeerName = null;
279+
String data = null;
280+
275281
// add message to listview and update ui
276282
if (message instanceof String) {
277-
String remotePeerName = chatService.getPeerNameById(remotePeerId);
278-
chatMessageCollection.add(remotePeerName + " : " + chatPrefix + message);
279-
chatView.updateUIChatCollection();
283+
remotePeerName = chatService.getPeerNameById(remotePeerId);
284+
data = (String) message;
285+
} else if (message instanceof JSONObject) {
286+
JSONObject jsonMessage = (JSONObject) message;
287+
try {
288+
remotePeerName = jsonMessage.getString("senderId");
289+
data = jsonMessage.getString("data");
290+
} catch (JSONException e) {
291+
e.printStackTrace();
292+
}
280293
}
294+
295+
chatMessageCollection.add(remotePeerName + " : " + chatPrefix + data);
296+
chatView.updateUIChatCollection();
281297
}
282298

283299
/**

sampleapp/src/main/java/sg/com/temasys/skylink/sdk/sampleapp/service/SkylinkCommonService.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,12 +856,14 @@ public void onUpdateFileTransferReceivingProgress(
856856
* or 'org.json.JSONArray'.
857857
* @param isPublic Flag to specify whether the message was sent to us only (as opposed to
858858
* broadcast to all peers in the room).
859+
* @param timeStamp The timestamp of the message,
860+
* The number of milliseconds since the epoch of 1970-01-01T00:00:00Z (midnight, January 1, 1970 UTC).
859861
* @param remotePeerId The id of the remote peer
860862
*/
861863
@Override
862-
public void onReceiveServerMessage(Object message, boolean isPublic, String
864+
public void onReceiveServerMessage(Object message, boolean isPublic, Long timeStamp, String
863865
remotePeerId) {
864-
Log.d(TAG, "onReceiveServerMessage(message: " + message + ",isPublic: " + isPublic + ", remotePeerId: " + remotePeerId);
866+
Log.d(TAG, "onReceiveServerMessage(message: " + message + ",isPublic: " + isPublic + ", timeStamp: " + timeStamp + ", remotePeerId: " + remotePeerId);
865867

866868
presenter.processServerMessageReceived(remotePeerId, message, !isPublic);
867869
}
@@ -874,12 +876,14 @@ public void onReceiveServerMessage(Object message, boolean isPublic, String
874876
* or 'org.json.JSONArray'.
875877
* @param isPublic Flag to specify whether the message was sent to us only (as opposed to
876878
* broadcast to all peers in the room).
879+
* @param timeStamp The timestamp of the message,
880+
* The number of milliseconds since the epoch of 1970-01-01T00:00:00Z (midnight, January 1, 1970 UTC).
877881
* @param remotePeerId The id of the remote peer
878882
*/
879883
@Override
880-
public void onReceiveP2PMessage(Object message, boolean isPublic, String
884+
public void onReceiveP2PMessage(Object message, boolean isPublic, Long timeStamp, String
881885
remotePeerId) {
882-
Log.d(TAG, "onReceiveP2PMessage(message: " + message + ",isPublic: " + isPublic + ", remotePeerId: " + remotePeerId);
886+
Log.d(TAG, "onReceiveP2PMessage(message: " + message + ",isPublic: " + isPublic + ", timeStamp: " + timeStamp + ", remotePeerId: " + remotePeerId);
883887

884888
presenter.processP2PMessageReceived(remotePeerId, message, !isPublic);
885889
}

0 commit comments

Comments
 (0)