This commit is contained in:
14Sandee
2023-12-06 13:02:57 +05:30
parent fd7257ee12
commit 4e0a6bc587

View File

@@ -1,5 +1,6 @@
package com.app.simplitend.patientgeofencing;
import static com.app.simplitend.chats.SocketHelper.kHost;
import static com.app.simplitend.locationupdates.LocationService.LOCATION_INTERVAL_BASE_TIME;
import static com.app.simplitend.locationupdates.LocationService.LOCATION_UPDATE_MIN_INTERVAL;
import static com.app.simplitend.patientgeofencing.GeoFenceHelper.GEOFENCE_TAG;
@@ -26,6 +27,8 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import io.socket.client.IO;
import io.socket.client.Socket;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@@ -80,7 +83,7 @@ public class GeoFenceBroadcastReceiver extends BroadcastReceiver {
locationServiceIntent.putExtra(LOCATION_UPDATE_MIN_INTERVAL, LOCATION_INTERVAL_BASE_TIME);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
}else {
} else {
context.startService(intent);
}
break;
@@ -117,24 +120,31 @@ public class GeoFenceBroadcastReceiver extends BroadcastReceiver {
Log.d(GEOFENCE_TAG, "doInBackground: CONNECTING TO SOCKET");
socketHelper.establishConnection(new SocketHelper.SockCallBack() {
@Override
public void onSocketConnected() {
Log.d(GEOFENCE_TAG, "doInBackground: SOCKET CONNECTED");
try {
IO.Options options = new IO.Options();
options.forceNew = true;
options.reconnection = true;
Socket mSocket = IO.socket(kHost, options);
mSocket.on(Socket.EVENT_CONNECT, args -> {
Log.d(GEOFENCE_TAG, "Socket connected ");
socketHelper.sendMessage(message, cg_id + "", patientId + "", channel_id + "",
patient_principal_id < 0?null:patient_principal_id+"");
}
patient_principal_id < 0 ? null : patient_principal_id + "");
mSocket.disconnect();
});
@Override
public void onConnectionError(Exception e) {
Log.d(GEOFENCE_TAG, "doInBackground: SOCKET CONNECTION ERROR " + e);
}
mSocket.on(Socket.EVENT_DISCONNECT, args -> Log.d(GEOFENCE_TAG, "Socket disconnected "));
@Override
public void onDisconnected() {
Log.d(GEOFENCE_TAG, "doInBackground: SOCKET DISCONNECTED");
}
});
mSocket.on(Socket.EVENT_CONNECT_ERROR, args -> {
Exception e = (Exception) args[0];
Log.e(GEOFENCE_TAG, "call: ", e);
});
mSocket.connect();
} catch (Exception e) {
e.printStackTrace();
Log.e(GEOFENCE_TAG, "SocketHelper: ", e);
}
}
private void notifyOutOfGeofence(Context context, String senior_address) {
@@ -168,7 +178,7 @@ public class GeoFenceBroadcastReceiver extends BroadcastReceiver {
intent.putExtra(LOCATION_UPDATE_MIN_INTERVAL, 5 * 1000); // every 5 seconds
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
}else {
} else {
context.startService(intent);
}
}