当前位置: 首页>>代码示例>>Java>>正文


Java WebSocket类代码示例

本文整理汇总了Java中com.neovisionaries.ws.client.WebSocket的典型用法代码示例。如果您正苦于以下问题:Java WebSocket类的具体用法?Java WebSocket怎么用?Java WebSocket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WebSocket类属于com.neovisionaries.ws.client包,在下文中一共展示了WebSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: openWebSocket

import com.neovisionaries.ws.client.WebSocket; //导入依赖的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) {
    }
}
 
开发者ID:pupnewfster,项目名称:Necessities,代码行数:26,代码来源:JanetSlack.java

示例2: Session

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
Session(
        final Gson gson,
        final String sessionId,
        final WebSocket webSocket,
        final Map<Integer, WSContext> contextList,
        final SessionFactory sessionFactory,
        final List<EventListener<?>> eventListeners,
        final CdpLoggerFactory loggerFactory) {
    this.sessionId = sessionId;
    this.invocationHandler = new SessionInvocationHandler(
                                                    gson,
                                                    webSocket,
                                                    contextList,
                                                    this,
                                                    loggerFactory.getLogger("cdp4j.ws.request"));
    this.sesessionFactory = sessionFactory;
    this.eventListeners   = eventListeners;
    this.webSocket        = webSocket;
    this.log              = loggerFactory.getLogger("cdp4j.session");
    this.logFlow          = loggerFactory.getLogger("cdp4j.flow");
    this.gson             = gson;
    this.command          = new Command(this);
}
 
开发者ID:webfolderio,项目名称:cdp4j,代码行数:24,代码来源:Session.java

示例3: onConnected

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
@Override
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
    if (websocket == mWS) {
        mConnectionStatusFuture.setDone(true);

        mLatch = new CountDownLatch(1);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    while (!mLatch.await(20, TimeUnit.SECONDS))
                        sendJSONText("{\"TestReqID\": " + GetNextRequestID() + ", \"MsgType\": \"1\", \"FingerPrint\": \"" + mFingerPrint + "\"}");
                } catch (InterruptedException ex) {
                }
            }
        }).start();
    }
}
 
开发者ID:gbizzotto,项目名称:dapay,代码行数:19,代码来源:BlinktradeAPI.java

示例4: onDisconnected

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
@Override
public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception {
    identity.CONNECTION = Identity.Connection.OFFLINE;

    final int closeCode;
    final String closeReason;
    if (closedByServer) {
        closeCode = serverCloseFrame.getCloseCode();
        closeReason = serverCloseFrame.getCloseReason();
    } else {
        closeCode = clientCloseFrame.getCloseCode();
        closeReason = clientCloseFrame.getCloseReason();
    }

    identity.getEventManager().dispatchEvent(new DisconnectEvent(identity, this, 0, closedByServer, closeCode, closeReason));
    LOG.log(LogLevel.INFO, "[CONNECTION] Disconnected [Code: " + closeCode + "][Reason: " + closeReason + "]");
}
 
开发者ID:AlienIdeology,项目名称:J-Cord,代码行数:18,代码来源:GatewayAdaptor.java

示例5: onNOTICE

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
protected void onNOTICE(WebSocket webSocket, String message, Tags tags) {
  switch (message) {
    case MSG_INVALID_NICK:
    case MSG_LOGIN_ERROR:
      logger.error("Error logging in , check the bot username");
      webSocket.disconnect();
      break;
    case MSG_AUTH_FAIL:
      logger.error("Failed authenticating, check the oAuth token for {}", username);
      webSocket.disconnect();
      break;
    default:
      break;
  }

  eventBus.post(new IrcChannelNoticeEvent(channelName, tags, message));
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:18,代码来源:BotChatClient.java

示例6: onConnected

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
@Override
public void onConnected(WebSocket websocket, Map<String, List<String>> headers)
{

    if (shutdown)
    {
        //Somehow this AudioWebSocket was shutdown before we finished connecting....
        // thus we just disconnect here since we were asked to shutdown
        socket.sendClose(1000);
        return;
    }

    connected = true;
    if (reconnecting)
        sendResume();
    else
        sendIdentify();
    changeStatus(ConnectionStatus.CONNECTING_AWAITING_AUTHENTICATING);
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA-Audio,代码行数:20,代码来源:AudioWebSocket.java

示例7: onThreadCreated

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
@Override
public void onThreadCreated(WebSocket websocket, ThreadType threadType, Thread thread) throws Exception
{
    String identifier = "JDA-Audio";
    String guildId = this.guildId;
    switch (threadType)
    {
        case CONNECT_THREAD:
            thread.setName(identifier + " AudioWS-ConnectThread (guildId: " + guildId + ')');
            break;
        case FINISH_THREAD:
            thread.setName(identifier + " AudioWS-FinishThread (guildId: " + guildId + ')');
            break;
        case WRITING_THREAD:
            thread.setName(identifier + " AudioWS-WriteThread (guildId: " + guildId + ')');
            break;
        case READING_THREAD:
            thread.setName(identifier + " AudioWS-ReadThread (guildId: " + guildId + ')');
            break;
        default:
            thread.setName(identifier + " AudioWS-" + threadType + " (guildId: " + guildId + ')');
    }
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA-Audio,代码行数:24,代码来源:AudioWebSocket.java

示例8: onError

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
/**
 * 连接中途失败回调
 *
 * @param websocket
 * @param cause
 * @throws Exception
 */
@Override
public void onError(WebSocket websocket, final WebSocketException cause) throws Exception {
    super.onError(websocket, cause);
    e("webSocket连接失败onError:" + cause.getMessage());
    webSocketState = WEB_SOCKET_CLOSE;
    onMain(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < mListeners.size(); i++) {
                RWebSocketListener listener = mListeners.get(i);
                listener.disConnectWebsocket(CODE_ERROR, cause.getMessage());
            }
        }
    });
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:23,代码来源:RWebSocket.java

示例9: onConnectError

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
/**
 * 连接中途失败回调
 *
 * @param websocket
 * @param exception
 * @throws Exception
 */
@Override
public void onConnectError(WebSocket websocket, final WebSocketException exception) throws Exception {
    super.onConnectError(websocket, exception);
    e("webSocket连接失败onConnectError:" + exception.getMessage());
    webSocketState = WEB_SOCKET_CLOSE;
    onMain(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < mListeners.size(); i++) {
                RWebSocketListener listener = mListeners.get(i);
                listener.disConnectWebsocket(CODE_CONNECT_ERROR, exception.getMessage());
            }
        }
    });
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:23,代码来源:RWebSocket.java

示例10: onDisconnected

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
/**
 * 连接断开  主动关闭webSocket时回调
 *
 * @param websocket
 * @param serverCloseFrame
 * @param clientCloseFrame
 * @param closedByServer
 * @throws Exception
 */
@Override
public void onDisconnected(WebSocket websocket, final WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception {
    super.onDisconnected(websocket, serverCloseFrame, clientCloseFrame, closedByServer);
    e("webSocket断开" + mWebSocket);
    webSocketState = WEB_SOCKET_CLOSE;
    //final int closeCode = serverCloseFrame.getCloseCode();
    //final String closeReason = serverCloseFrame.getCloseReason();

    onMain(new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < mListeners.size(); i++) {
                RWebSocketListener listener = mListeners.get(i);
                listener.disConnectWebsocket();
            }
        }
    });
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:28,代码来源:RWebSocket.java

示例11: onConnected

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
/**
 * 连接成功
 *
 * @param websocket
 * @param headers
 * @throws Exception
 */
@Override
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
    super.onConnected(websocket, headers);
    i("webSocket连接成功");
    if (websocket != null) {
        this.mWebSocket = websocket;
        webSocketState = WEB_SOCKET_OPEN;
        onMain(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < mListeners.size(); i++) {
                    RWebSocketListener listener = mListeners.get(i);
                    //listener.connectSuccessWebsocket(mWebSocket);
                    listener.connectSuccessWebsocket(mWebSocket, isReconnect);
                }
            }
        });
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:27,代码来源:RWebSocket.java

示例12: onTextFrame

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
@Override
public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception {
    try {
        String response = frame.getPayloadText();
        Gson gson = new Gson();

        Type GetLimitiOrdersResponse = new TypeToken<WitnessResponse<ArrayList<Market>>>() {
        }.getType();
        WitnessResponse<ArrayList<Market>> witnessResponse = gson.fromJson(response, GetLimitiOrdersResponse);
        if (witnessResponse.error != null) {
            this.mListener.onError(witnessResponse.error);
        } else {
            this.mListener.onSuccess(witnessResponse);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    websocket.disconnect();
}
 
开发者ID:kenCode-de,项目名称:smartcoins-wallet,代码行数:20,代码来源:GetLimitOrders.java

示例13: run

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
@Override
public void run() {
    byte[] buffer = new byte[audioBufferSize];
    recorder = new AudioRecord(audioSource, sampleRate, channel, audioFormat, audioBufferSize);
    try {
        while (recorder.getState() != AudioRecord.STATE_INITIALIZED)
            Thread.sleep(100, 0);
    } catch (InterruptedException e) {
        recorder.release();
        return;
    }

    recorder.startRecording();
    for (; ; ) {
        int length = recorder.read(buffer, 0, buffer.length);
        if (length < 0)
            Log.e("Record", "error: " + Integer.toString(length));
        else {
            for (WebSocket ws : wss)
                ws.sendBinary(buffer);
        }
        if (Thread.interrupted()) {
            recorder.stop();
            return;
        }
    }
}
 
开发者ID:zackszhu,项目名称:hack_sjtu_2017,代码行数:28,代码来源:LiuLiShuo.java

示例14: GatewayAdaptor

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
/**
 * The listener for Gateway messages.
 *
 * @param identity The identity this gateway belongs to.
 * @param webSocket The WebSocket where events are fired.
 */
public GatewayAdaptor(IdentityImpl identity, WebSocket webSocket) {
    this.identity = identity;
    this.webSocket = webSocket;
    LOG = identity.LOG.clone(this);
    setEventHandler();
}
 
开发者ID:AlienIdeology,项目名称:J-Cord,代码行数:13,代码来源:GatewayAdaptor.java

示例15: onConnected

import com.neovisionaries.ws.client.WebSocket; //导入依赖的package包/类
@Override
public void onConnected(WebSocket websocket, Map<String, List<String>> headers) throws Exception {
    LOG.log(LogLevel.INFO, "[CONNECTION] Connected");
    identity.CONNECTION = Identity.Connection.CONNECTED;

    if (session_id == null || session_id.isEmpty()) {
        sendIdentification();
    } else {
        sendResume();
    }
}
 
开发者ID:AlienIdeology,项目名称:J-Cord,代码行数:12,代码来源:GatewayAdaptor.java


注:本文中的com.neovisionaries.ws.client.WebSocket类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。