Commit 708eda49 by Simhachalam ch

added socket id to chat log table

parent 9508e0fd
...@@ -156,6 +156,7 @@ public class CatalogueApplication extends MultiDexApplication { ...@@ -156,6 +156,7 @@ public class CatalogueApplication extends MultiDexApplication {
options.upgrade = true; options.upgrade = true;
mSocket = IO.socket(Constants.CHAT_SERVER_URL,options); mSocket = IO.socket(Constants.CHAT_SERVER_URL,options);
// mSocket = IO.socket("http://10.1.8.229:12811",options);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
......
...@@ -46,9 +46,10 @@ public interface DBConstants { ...@@ -46,9 +46,10 @@ public interface DBConstants {
*/ */
String CHAT_ID = "chat_id"; String CHAT_ID = "chat_id";
String CHAT_CLIENT_MESSAGE = "client_message"; String CHAT_CLIENT_MESSAGE = "client_message";
String CHAT_SERVER__RESPONSE = "title"; String CHAT_SERVER__RESPONSE = "server_response";
String CHAT_TIMESTAMP = "description"; String CHAT_TIMESTAMP = "timestamp";
String CHAT_CONN_STATUS= "icon"; String CHAT_CONN_STATUS= "conn_status";
String CHAT_SOCKET_ID= "socket_id";
/** /**
* Catalogue table * Catalogue table
......
...@@ -83,7 +83,8 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -83,7 +83,8 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
+ CHAT_CLIENT_MESSAGE + " text, " + CHAT_CLIENT_MESSAGE + " text, "
+ CHAT_SERVER__RESPONSE + " text, " + CHAT_SERVER__RESPONSE + " text, "
+ CHAT_TIMESTAMP + " text, " + CHAT_TIMESTAMP + " text, "
+ CHAT_CONN_STATUS + " text" + CHAT_CONN_STATUS + " text, "
+ CHAT_SOCKET_ID + " text"
+ ");"); + ");");
} }
......
...@@ -47,6 +47,7 @@ public class ChatLogManager implements DBConstants { ...@@ -47,6 +47,7 @@ public class ChatLogManager implements DBConstants {
chatLog.setServerResponse(c.getString(2)); chatLog.setServerResponse(c.getString(2));
chatLog.setTimestamp(c.getString(3)); chatLog.setTimestamp(c.getString(3));
chatLog.setConnStatus(c.getString(4)); chatLog.setConnStatus(c.getString(4));
chatLog.setSocketConnId(c.getString(5));
chatLogList.add(chatLog); chatLogList.add(chatLog);
} }
...@@ -67,12 +68,13 @@ public class ChatLogManager implements DBConstants { ...@@ -67,12 +68,13 @@ public class ChatLogManager implements DBConstants {
} }
return -1; return -1;
} }
public static void saveLogEvent(String clientMsg, String serverMsg, String connStatus, Date timestamp){ public static void saveLogEvent(String clientMsg, String serverMsg, String connStatus, String connId, Date timestamp){
ChatLog chatLog = new ChatLog(); ChatLog chatLog = new ChatLog();
chatLog.setTimestamp(Util.getDateTime(timestamp.getTime())); chatLog.setTimestamp(Util.getDateTime(timestamp.getTime()));
chatLog.setServerResponse(serverMsg); chatLog.setServerResponse(serverMsg);
chatLog.setClientMessage(clientMsg); chatLog.setClientMessage(clientMsg);
chatLog.setConnStatus(connStatus); chatLog.setConnStatus(connStatus);
chatLog.setSocketConnId(connId);
ChatLogManager.save(chatLog); ChatLogManager.save(chatLog);
} }
private static ContentValues getChatLogContentValues(ChatLog chatLog) { private static ContentValues getChatLogContentValues(ChatLog chatLog) {
...@@ -81,6 +83,7 @@ public class ChatLogManager implements DBConstants { ...@@ -81,6 +83,7 @@ public class ChatLogManager implements DBConstants {
cv.put(CHAT_SERVER__RESPONSE, chatLog.getServerResponse()); cv.put(CHAT_SERVER__RESPONSE, chatLog.getServerResponse());
cv.put(CHAT_TIMESTAMP, chatLog.getTimestamp()); cv.put(CHAT_TIMESTAMP, chatLog.getTimestamp());
cv.put(CHAT_CONN_STATUS, chatLog.getConnStatus()); cv.put(CHAT_CONN_STATUS, chatLog.getConnStatus());
cv.put(CHAT_SOCKET_ID, chatLog.getSocketConnId());
return cv; return cv;
} }
} }
\ No newline at end of file
...@@ -601,6 +601,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -601,6 +601,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
exportAndSaveLogs(chatLogList); exportAndSaveLogs(chatLogList);
//delete all logs //delete all logs
ChatLogManager.deleteAllRows(); ChatLogManager.deleteAllRows();
Toast.makeText(getApplicationContext(),
"Export Completed. Check in your external storage.", Toast.LENGTH_LONG).show();
return true; return true;
/* case R.id.text_menu_icon: /* case R.id.text_menu_icon:
...@@ -636,11 +638,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -636,11 +638,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
} else { } else {
try { try {
writer = new CSVWriter(new FileWriter(filePath)); writer = new CSVWriter(new FileWriter(filePath));
String[] headerLine = {"Chat Id","Client Msg","Server Msg", "Conn Status" , "Time Stamp"} ; String[] headerLine = {"Chat Id", "Time Stamp", "Conn Status" ,"Socket Id" , "Client Msg","Server Msg"} ;
writer.writeNext(headerLine); writer.writeNext(headerLine);
for (ChatLog chat: chatLogList) { for (ChatLog chat: chatLogList) {
String[] line = {""+chat.getChatId(),chat.getClientMessage(), chat.getServerResponse(), chat.getConnStatus(), chat.getTimestamp() } ; String[] line = {""+chat.getChatId(),chat.getTimestamp() , chat.getConnStatus(), chat.getSocketConnId(), chat.getClientMessage(), chat.getServerResponse() } ;
writer.writeNext(line); writer.writeNext(line);
} }
writer.close(); writer.close();
...@@ -760,7 +762,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -760,7 +762,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
Log.i("Print", jsonObject.toString()); Log.i("Print", jsonObject.toString());
mSocket.emit(NEW_MESSAGE, jsonObject); mSocket.emit(NEW_MESSAGE, jsonObject);
ChatLogManager.saveLogEvent(message,"","true",new Date()); ChatLogManager.saveLogEvent(message,"",String.valueOf(mSocket.connected()), mSocket.id(),new Date());
} else { } else {
mInputMessageView.requestFocus(); mInputMessageView.requestFocus();
...@@ -801,10 +803,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -801,10 +803,11 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override @Override
public void run() { public void run() {
// userAuthenticateTask(); // userAuthenticateTask();
Log.e(TAG, "socket got connected"); Log.e(TAG, "socket got connected" + mSocket.id());
// Toast.makeText(getApplicationContext(), // Toast.makeText(getApplicationContext(),
// R.string.connect, Toast.LENGTH_LONG).show(); // R.string.connect, Toast.LENGTH_LONG).show();
initChatMessage(INIT_MSG); initChatMessage(INIT_MSG);
ChatLogManager.saveLogEvent("New Connection Created","","true", mSocket.id(), new Date());
} }
}); });
} }
...@@ -872,6 +875,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -872,6 +875,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private Emitter.Listener onDisconnect = new Emitter.Listener() { private Emitter.Listener onDisconnect = new Emitter.Listener() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
ChatLogManager.saveLogEvent("Connection Disconnected","", String.valueOf(mSocket.connected()), mSocket.id(), new Date());
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -903,6 +908,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -903,6 +908,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override @Override
public void call(Object... args) { public void call(Object... args) {
Log.e(TAG, "onConnectTimeOut Called"); Log.e(TAG, "onConnectTimeOut Called");
ChatLogManager.saveLogEvent("Connection Timed Out","", String.valueOf(mSocket.connected()), mSocket.id(), new Date());
// Toast.makeText(getApplicationContext(), // Toast.makeText(getApplicationContext(),
// "onConnectTimeOut Called", Toast.LENGTH_LONG).show(); // "onConnectTimeOut Called", Toast.LENGTH_LONG).show();
//reconnect(); //reconnect();
...@@ -916,6 +923,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -916,6 +923,8 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
@Override @Override
public void call(Object... args) { public void call(Object... args) {
Log.e(TAG, "Reconnection Called"); Log.e(TAG, "Reconnection Called");
ChatLogManager.saveLogEvent("Reconnection Called","", String.valueOf(mSocket.connected()), mSocket.id(), new Date());
// Toast.makeText(getApplicationContext(), // Toast.makeText(getApplicationContext(),
// "Reconnection Called", Toast.LENGTH_LONG).show(); // "Reconnection Called", Toast.LENGTH_LONG).show();
...@@ -929,11 +938,13 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -929,11 +938,13 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
private Emitter.Listener onConnectError = new Emitter.Listener() { private Emitter.Listener onConnectError = new Emitter.Listener() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
ChatLogManager.saveLogEvent("Failed create a socket connection","", String.valueOf(mSocket.connected()), mSocket.id(), new Date());
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
if(!isConnectError) { if(!isConnectError) {
Log.e(TAG,"failed to connect"); Log.e(TAG,"failed to connect");
Snackbar snackbar = Snackbar Snackbar snackbar = Snackbar
.make(mMessagesView, R.string.error_connect, Snackbar.LENGTH_LONG) .make(mMessagesView, R.string.error_connect, Snackbar.LENGTH_LONG)
.setAction("Dismiss", new View.OnClickListener() { .setAction("Dismiss", new View.OnClickListener() {
...@@ -1024,7 +1035,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD ...@@ -1024,7 +1035,7 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
} }
if(!message.isEmpty()) { if(!message.isEmpty()) {
ChatLogManager.saveLogEvent("",message,"true",new Date()); ChatLogManager.saveLogEvent("",message,String.valueOf(mSocket.connected()), mSocket.id(),new Date());
if(message.contains(Constants.RESET_PASSWORD_NAVIGATION_SCREEN)){ if(message.contains(Constants.RESET_PASSWORD_NAVIGATION_SCREEN)){
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
......
...@@ -2,9 +2,11 @@ package com.vsoft.vera.utils; ...@@ -2,9 +2,11 @@ package com.vsoft.vera.utils;
public class ChatLog { public class ChatLog {
private Long chatId; private Long chatId;
/**
* socket connection id
*/
private String socketConnId;
private String serverResponse; private String serverResponse;
private String timestamp; private String timestamp;
/** /**
...@@ -14,6 +16,13 @@ public class ChatLog { ...@@ -14,6 +16,13 @@ public class ChatLog {
private String connStatus; private String connStatus;
private String clientMessage; private String clientMessage;
public String getSocketConnId() {
return socketConnId;
}
public void setSocketConnId(String socketConnId) {
this.socketConnId = socketConnId;
}
public Long getChatId() { public Long getChatId() {
return chatId; return chatId;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment