implement KraSocketClient
parent
0db831b697
commit
2592b5d3e5
|
@ -52,8 +52,6 @@ public class KrakatoaAPI extends JavaPlugin {
|
||||||
this.configHandler.getWebSocketPort(), this.configHandler.getWebSocketAccessKey(),
|
this.configHandler.getWebSocketPort(), this.configHandler.getWebSocketAccessKey(),
|
||||||
CloudNetDriver.getInstance().getComponentName());
|
CloudNetDriver.getInstance().getComponentName());
|
||||||
|
|
||||||
System.out.println("load kraSocketClient " + CloudNetDriver.getInstance().getComponentName());
|
|
||||||
|
|
||||||
this.kraSocketClientEventInitiater = new KraSocketClientEventInitiater();
|
this.kraSocketClientEventInitiater = new KraSocketClientEventInitiater();
|
||||||
this.kraSocketClientEventInterface = new SocketClientMessageListener();
|
this.kraSocketClientEventInterface = new SocketClientMessageListener();
|
||||||
|
|
||||||
|
@ -61,8 +59,6 @@ public class KrakatoaAPI extends JavaPlugin {
|
||||||
this.kraSocketClient = new KraSocketClient(kraSocketClientConfig,
|
this.kraSocketClient = new KraSocketClient(kraSocketClientConfig,
|
||||||
this.kraSocketClientEventInterface, this.kraProtocol);
|
this.kraSocketClientEventInterface, this.kraProtocol);
|
||||||
|
|
||||||
System.out.println("here " + this.kraSocketClient.sendTest());
|
|
||||||
|
|
||||||
this.kraSocketClient.getSocketClient().connect();
|
this.kraSocketClient.getSocketClient().connect();
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -73,21 +69,6 @@ public class KrakatoaAPI extends JavaPlugin {
|
||||||
this.configHandler.getMongodbPassword());
|
this.configHandler.getMongodbPassword());
|
||||||
this.mongoManager.connect(this.configHandler.getMongodbDatabase());
|
this.mongoManager.connect(this.configHandler.getMongodbDatabase());
|
||||||
|
|
||||||
this.kraSocketClient.sendTest();
|
|
||||||
|
|
||||||
/*
|
|
||||||
try {
|
|
||||||
socketClient = new SocketClient(
|
|
||||||
new URI(configHandler.getWebSocketProtocol() + "://" + configHandler.getWebSocketHost()
|
|
||||||
+ ":" + configHandler.getWebSocketPort() + "/ws?t="
|
|
||||||
+ configHandler.getWebSocketAccessKey() + "&s=" + CloudNetDriver.getInstance()
|
|
||||||
.getComponentName()));
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
socketClient.connect(); */
|
|
||||||
|
|
||||||
loadListeners();
|
loadListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +76,8 @@ public class KrakatoaAPI extends JavaPlugin {
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
super.onDisable();
|
super.onDisable();
|
||||||
|
|
||||||
//socketClient.getConnection().close();
|
this.kraSocketClient.getSocketClient().getConnection().close();
|
||||||
//socketClient.getConnection().closeConnection(1, "");
|
this.kraSocketClient.getSocketClient().getConnection().closeConnection(1, "");
|
||||||
|
|
||||||
instance = null;
|
instance = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,29 +2,28 @@ package net.krakatoaapi.listener;
|
||||||
|
|
||||||
import earth.krakatao.events.KraSocketClientEventInterface;
|
import earth.krakatao.events.KraSocketClientEventInterface;
|
||||||
import earth.krakatao.protocol.KraSocketClientProtocolMessage;
|
import earth.krakatao.protocol.KraSocketClientProtocolMessage;
|
||||||
|
import net.krakatoaapi.KrakatoaAPI;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.java_websocket.handshake.ServerHandshake;
|
import org.java_websocket.handshake.ServerHandshake;
|
||||||
|
|
||||||
public class SocketClientMessageListener implements KraSocketClientEventInterface {
|
public class SocketClientMessageListener implements KraSocketClientEventInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void kraSocketClientOnMessage(
|
public void onOpen(ServerHandshake serverHandshake) {
|
||||||
KraSocketClientProtocolMessage kraSocketClientProtocolMessage) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void kraSocketClientOnOpen(ServerHandshake serverHandshake) {
|
public void onMessage(KraSocketClientProtocolMessage kraSocketClientProtocolMessage) {
|
||||||
System.out.println("OPEN");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void kraSocketClientOnClose(int i, String s, boolean b) {
|
public void onClose(int code, String reason, boolean remote) {
|
||||||
System.out.println("ONCLOSE " + i + " " + b);
|
if (code != 1) {
|
||||||
|
Bukkit.getScheduler().runTaskLater(KrakatoaAPI.getInstance(), () -> {
|
||||||
|
KrakatoaAPI.getInstance().getKraSocketClient().getSocketClient().Reconnect();
|
||||||
|
}, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void test(String s) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue