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

Commit 8a20835

Browse files
committed
Added calling of custom disconnect events, also fixed a few websocket close issues
1 parent 927d8d1 commit 8a20835

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/main/java/com/mixer/api/resource/chat/ws/MixerChatConnection.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.google.common.collect.HashMultimap;
44
import com.google.common.collect.Maps;
55
import com.google.common.collect.Multimap;
6+
import com.google.gson.Gson;
7+
import com.google.gson.GsonBuilder;
68
import com.google.gson.JsonObject;
79
import com.google.gson.JsonParser;
810
import com.google.gson.JsonSyntaxException;
@@ -136,6 +138,17 @@ public void onMessage(String s) {
136138
}
137139

138140
@Override public void onClose(int i, String s, boolean b) {
141+
Class<? extends AbstractChatEvent> type = AbstractChatEvent.EventType.fromSerializedName("disconnect").getCorrespondingClass();
142+
Gson gson = null;
143+
gson = new GsonBuilder().create();
144+
JsonObject json = new JsonObject();
145+
JsonObject obj = new JsonObject();
146+
obj.addProperty("code", i);
147+
obj.addProperty("reason", s);
148+
obj.addProperty("remote", b);
149+
json.add("data", obj);
150+
this.dispatchEvent(this.mixer.gson.fromJson(json, type));
151+
this.close(i);
139152
this.producer.notifyClose(i, s, b);
140153
}
141154

src/main/java/com/mixer/api/resource/constellation/ws/MixerConstellationConnection.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.google.common.collect.HashMultimap;
44
import com.google.common.collect.Maps;
55
import com.google.common.collect.Multimap;
6+
import com.google.gson.Gson;
7+
import com.google.gson.GsonBuilder;
68
import com.google.gson.JsonObject;
79
import com.google.gson.JsonParser;
810
import com.google.gson.JsonSyntaxException;
@@ -122,9 +124,21 @@ public void onMessage(String s) {
122124
}
123125

124126
@Override public void onClose(int i, String s, boolean b) {
125-
this.producer.notifyClose(i, s, b);
127+
Class<? extends AbstractConstellationEvent> type = AbstractConstellationEvent.EventType
128+
.fromSerializedName("disconnect").getCorrespondingClass();
129+
Gson gson = null;
130+
gson = new GsonBuilder().create();
131+
JsonObject obj = new JsonObject();
132+
obj.addProperty("code", i);
133+
obj.addProperty("reason", s);
134+
obj.addProperty("remote", b);
135+
JsonObject json = new JsonObject();
136+
json.add("data", obj);
137+
this.dispatchEvent(this.mixer.gson.fromJson(json, type));
138+
this.close(i);
139+
this.producer.notifyClose(i, s, b);
126140
}
127-
141+
128142
private <T extends AbstractConstellationEvent> void dispatchEvent(T event) {
129143
Class<? extends AbstractConstellationEvent> eventType = event.getClass();
130144

0 commit comments

Comments
 (0)