本文整理汇总了Java中com.neovisionaries.ws.client.WebSocketAdapter类的典型用法代码示例。如果您正苦于以下问题:Java WebSocketAdapter类的具体用法?Java WebSocketAdapter怎么用?Java WebSocketAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketAdapter类属于com.neovisionaries.ws.client包,在下文中一共展示了WebSocketAdapter类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openWebSocket
import com.neovisionaries.ws.client.WebSocketAdapter; //导入依赖的package包/类
private void openWebSocket(String url) {
try {
ws = new WebSocketFactory().createSocket(url).addListener(new WebSocketAdapter() {
@Override
public void onTextMessage(WebSocket websocket, String message) {
JsonObject json = Jsoner.deserialize(message, new JsonObject());
if (json.containsKey("type")) {
if (json.getString(Jsoner.mintJsonKey("type", null)).equals("message")) {
//TODO: Figure out if there is a way to get the user id of a bot instead of just using janet's
SlackUser info = json.containsKey("bot_id") ? getUserInfo("U2Y19AVNJ") : getUserInfo(json.getString(Jsoner.mintJsonKey("user", null)));
String text = json.getString(Jsoner.mintJsonKey("text", null));
while (text.contains("<") && text.contains(">"))
text = text.split("<@")[0] + '@' + getUserInfo(text.split("<@")[1].split(">:")[0]).getName() + ':' + text.split("<@")[1].split(">:")[1];
String channel = json.getString(Jsoner.mintJsonKey("channel", null));
if (channel.startsWith("D")) //Direct Message
sendSlackChat(info, text, true);
else if (channel.startsWith("C") || channel.startsWith("G")) //Channel or Group
sendSlackChat(info, text, false);
}
}
}
}).connect();
} catch (Exception ignored) {
}
}