Adjust log messages
This commit is contained in:
@@ -10,7 +10,6 @@ import android.content.SharedPreferences;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
@@ -37,6 +36,7 @@ public class PushService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
if (socket != null) {
|
if (socket != null) {
|
||||||
|
Log.i("Closing WebSocket (preference change)");
|
||||||
socket.close(1000, "client logout");
|
socket.close(1000, "client logout");
|
||||||
socket = null;
|
socket = null;
|
||||||
}
|
}
|
||||||
@@ -57,6 +57,8 @@ public class PushService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
|
Log.i("Creating WebSocket-Service");
|
||||||
|
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
gson = new Gson();
|
gson = new Gson();
|
||||||
start();
|
start();
|
||||||
@@ -94,42 +96,39 @@ public class PushService extends Service {
|
|||||||
|
|
||||||
HttpUrl httpUrl = HttpUrl.parse(url).newBuilder().addPathSegment("stream").addQueryParameter("token", token).build();
|
HttpUrl httpUrl = HttpUrl.parse(url).newBuilder().addPathSegment("stream").addQueryParameter("token", token).build();
|
||||||
|
|
||||||
final Request request = new Request.Builder()
|
final Request request = new Request.Builder().url(httpUrl).get().build();
|
||||||
.url(httpUrl)
|
|
||||||
.get()
|
|
||||||
.build();
|
|
||||||
foregroundNotification("Initializing WebSocket");
|
|
||||||
|
|
||||||
|
foregroundNotification("Initializing WebSocket");
|
||||||
|
Log.i("Initializing WebSocket");
|
||||||
socket = client.newWebSocket(request, new WebSocketListener() {
|
socket = client.newWebSocket(request, new WebSocketListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOpen(WebSocket webSocket, Response response) {
|
public void onOpen(WebSocket webSocket, Response response) {
|
||||||
|
Log.i("Initialized WebSocket");
|
||||||
foregroundNotification("Listening to " + request.url().host());
|
foregroundNotification("Listening to " + request.url().host());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(WebSocket webSocket, String text) {
|
public void onMessage(WebSocket webSocket, String text) {
|
||||||
Log.i("gotify-ws", "Received" + text);
|
|
||||||
|
|
||||||
Map<String, String> hashMap = gson.fromJson(text, new TypeToken<Map<String, String>>() {
|
Map<String, String> hashMap = gson.fromJson(text, new TypeToken<Map<String, String>>() {
|
||||||
}.getType());
|
}.getType());
|
||||||
|
|
||||||
showNotification(Integer.parseInt(hashMap.get("id")), hashMap.get("title"), hashMap.get("message"));
|
showNotification(Integer.parseInt(hashMap.get("id")), hashMap.get("title"), hashMap.get("message"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClosed(WebSocket webSocket, int code, String reason) {
|
public void onClosed(WebSocket webSocket, int code, String reason) {
|
||||||
foregroundNotification("Stopped");
|
Log.e("WebSocket closed " + reason);
|
||||||
showNotification(-4, "WS Conn Closed", "The websocket connection closed, this normmaly means the token was invalidated. A re-login is required");
|
foregroundNotification("WebSocket closed, re-login required");
|
||||||
|
showNotification(-4, "WebSocket closed", "The WebSocket connection closed, this normally means the token(login) was invalidated. A re-login is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(WebSocket webSocket, Throwable t, @Nullable Response response) {
|
public void onFailure(WebSocket webSocket, Throwable t, @Nullable Response response) {
|
||||||
foregroundNotification("Error: " + t.getMessage());
|
foregroundNotification("Error: " + t.getMessage());
|
||||||
|
Log.e("WebSocket failure", t);
|
||||||
if (response != null && response.code() >= 400 && response.code() <= 499) {
|
if (response != null && response.code() >= 400 && response.code() <= 499) {
|
||||||
showNotification(-2, "WS Bad Request", "Could not connect to WS: " + response.message());
|
|
||||||
preferences.edit().remove("@global:token").apply();
|
preferences.edit().remove("@global:token").apply();
|
||||||
|
showNotification(-2, "WebSocket Bad-Request", "Could not connect: " + response.message());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +150,6 @@ public class PushService extends Service {
|
|||||||
|
|
||||||
NotificationCompat.Builder b = new NotificationCompat.Builder(this, "GOTIFY_CHANNEL");
|
NotificationCompat.Builder b = new NotificationCompat.Builder(this, "GOTIFY_CHANNEL");
|
||||||
|
|
||||||
|
|
||||||
b.setAutoCancel(true)
|
b.setAutoCancel(true)
|
||||||
.setDefaults(Notification.DEFAULT_ALL)
|
.setDefaults(Notification.DEFAULT_ALL)
|
||||||
.setWhen(System.currentTimeMillis())
|
.setWhen(System.currentTimeMillis())
|
||||||
@@ -163,10 +161,13 @@ public class PushService extends Service {
|
|||||||
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
|
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
|
||||||
.setContentIntent(contentIntent);
|
.setContentIntent(contentIntent);
|
||||||
|
|
||||||
|
|
||||||
NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
notificationManager.notify(id, b.build());
|
notificationManager.notify(id, b.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
Log.i("Destroying WebSocket-Service");
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user