Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
Added calling of custom disconnect events, also fixed a few websocket…
Browse files Browse the repository at this point in the history
… close issues
  • Loading branch information
MJRLegends committed Jan 30, 2020
1 parent 927d8d1 commit 8a20835
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
Expand Down Expand Up @@ -136,6 +138,17 @@ public void onMessage(String s) {
}

@Override public void onClose(int i, String s, boolean b) {
Class<? extends AbstractChatEvent> type = AbstractChatEvent.EventType.fromSerializedName("disconnect").getCorrespondingClass();
Gson gson = null;
gson = new GsonBuilder().create();
JsonObject json = new JsonObject();
JsonObject obj = new JsonObject();
obj.addProperty("code", i);
obj.addProperty("reason", s);
obj.addProperty("remote", b);
json.add("data", obj);
this.dispatchEvent(this.mixer.gson.fromJson(json, type));
this.close(i);
this.producer.notifyClose(i, s, b);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
Expand Down Expand Up @@ -122,9 +124,21 @@ public void onMessage(String s) {
}

@Override public void onClose(int i, String s, boolean b) {
this.producer.notifyClose(i, s, b);
Class<? extends AbstractConstellationEvent> type = AbstractConstellationEvent.EventType
.fromSerializedName("disconnect").getCorrespondingClass();
Gson gson = null;
gson = new GsonBuilder().create();
JsonObject obj = new JsonObject();
obj.addProperty("code", i);
obj.addProperty("reason", s);
obj.addProperty("remote", b);
JsonObject json = new JsonObject();
json.add("data", obj);
this.dispatchEvent(this.mixer.gson.fromJson(json, type));
this.close(i);
this.producer.notifyClose(i, s, b);
}

private <T extends AbstractConstellationEvent> void dispatchEvent(T event) {
Class<? extends AbstractConstellationEvent> eventType = event.getClass();

Expand Down

0 comments on commit 8a20835

Please sign in to comment.