Java 类com.squareup.okhttp.ws.WebSocket 实例源码

项目:weex-3d-map    文件:WXWebSocketManager.java   
@Override
public void onOpen(WebSocket webSocket, Request arg1, Response arg2)
    throws IOException {
  mWebSocket = webSocket;
  setEnvironment(WXEnvironment.getConfig());
  WXSDKManager.getInstance().postOnUiThread(new Runnable() {
    @Override
    public void run() {
      Toast.makeText(WXEnvironment.sApplication, "Has switched to DEBUG mode, you can see the DEBUG information on the browser!", Toast.LENGTH_SHORT).show();
    }
  },0);
  for (JSDebuggerCallback callback : mCallbacks.values()) {
    callback.onSuccess(arg2);
  }
  WXLogUtils.e("into--[onOpen]");
}
项目:ReactNativeSignatureExample    文件:WebSocketModule.java   
@ReactMethod
public void close(int code, String reason, int id) {
  WebSocket client = mWebSocketConnections.get(id);
  if (client == null) {
    // WebSocket is already closed
    // Don't do anything, mirror the behaviour on web
    FLog.w(
      ReactConstants.TAG,
      "Cannot close WebSocket. Unknown WebSocket id " + id);

    return;
  }
  try {
    client.close(code, reason);
    mWebSocketConnections.remove(id);
  } catch (Exception e) {
    FLog.e(
      ReactConstants.TAG,
      "Could not close WebSocket connection for id " + id,
      e);
  }
}
项目:react-native-ibeacon-android    文件:WebSocketModule.java   
@ReactMethod
public void close(int code, String reason, int id) {
  WebSocket client = mWebSocketConnections.get(id);
  if (client == null) {
    // WebSocket is already closed
    // Don't do anything, mirror the behaviour on web
    FLog.w(
      ReactConstants.TAG,
      "Cannot close WebSocket. Unknown WebSocket id " + id);

    return;
  }
  try {
    client.close(code, reason);
    mWebSocketConnections.remove(id);
  } catch (Exception e) {
    FLog.e(
      ReactConstants.TAG,
      "Could not close WebSocket connection for id " + id,
      e);
  }
}
项目:react-native-box-loaders    文件:WebSocketModule.java   
@ReactMethod
public void close(int code, String reason, int id) {
  WebSocket client = mWebSocketConnections.get(id);
  if (client == null) {
    // WebSocket is already closed
    // Don't do anything, mirror the behaviour on web
    FLog.w(
      ReactConstants.TAG,
      "Cannot close WebSocket. Unknown WebSocket id " + id);

    return;
  }
  try {
    client.close(code, reason);
    mWebSocketConnections.remove(id);
  } catch (Exception e) {
    FLog.e(
      ReactConstants.TAG,
      "Could not close WebSocket connection for id " + id,
      e);
  }
}
项目:weex-3d-map    文件:WXWebSocketManager.java   
@Override
public void onOpen(WebSocket webSocket, Request arg1, Response arg2)
    throws IOException {
  mWebSocket = webSocket;
  setEnvironment(WXEnvironment.getConfig());
  WXSDKManager.getInstance().postOnUiThread(new Runnable() {
    @Override
    public void run() {
      Toast.makeText(WXEnvironment.sApplication, "Has switched to DEBUG mode, you can see the DEBUG information on the browser!", Toast.LENGTH_SHORT).show();
    }
  },0);
  for (JSDebuggerCallback callback : mCallbacks.values()) {
    callback.onSuccess(arg2);
  }
  WXLogUtils.e("into--[onOpen]");
}
项目:Weex-TestDemo    文件:WXWebSocketManager.java   
@Override
public void onOpen(WebSocket webSocket, Request arg1, Response arg2)
    throws IOException {
  mWebSocket = webSocket;
  setEnvironment(WXEnvironment.getConfig());
  WXSDKManager.getInstance().postOnUiThread(new Runnable() {
    @Override
    public void run() {
      Toast.makeText(WXEnvironment.sApplication, "Has switched to DEBUG mode, you can see the DEBUG information on the browser!", Toast.LENGTH_SHORT).show();
    }
  },0);
  for (JSDebuggerCallback callback : mCallbacks.values()) {
    callback.onSuccess(arg2);
  }
  WXLogUtils.e("into--[onOpen]");
}
项目:weex    文件:WXWebSocketManager.java   
@Override
public void onOpen(WebSocket webSocket, Request arg1, Response arg2)
    throws IOException {
  mWebSocket = webSocket;
  setEnvironment(WXEnvironment.getConfig());
  WXSDKManager.getInstance().postOnUiThread(new Runnable() {
    @Override
    public void run() {
      Toast.makeText(WXEnvironment.sApplication, "Has switched to DEBUG mode, you can see the DEBUG information on the browser!", Toast.LENGTH_SHORT).show();
    }
  },0);
  for (JSDebuggerCallback callback : mCallbacks.values()) {
    callback.onSuccess(arg2);
  }
  WXLogUtils.e("into--[onOpen]");
}
项目:Rocket.Chat-android    文件:Meteor.java   
/**
 * Sends a string over the websocket
 *
 * @param message the string to send
 */
private void send(String callId, final String message) {
    if (message == null) {
        throw new RuntimeException("You cannot send `null` messages");
    }

    try {
        Timber.d("-->" + message);
        synchronized (mConnection) {
            RequestBody request = RequestBody.create(WebSocket.TEXT, message);
            mConnection.sendMessage(request);
        }
    } catch (Exception e) {
        final Listener listener = mListeners.remove(callId);
        if (listener != null) {
            if (listener instanceof ResultListener) {
                ((ResultListener) listener).onError(new MeteorException(e));
            }
        }
        if (mCallback != null) {
            mCallback.onException(e);
        }
    }
}
项目:weex-3d-map    文件:WXWebSocketManager.java   
public void sendMessage(String message) {
  if(!isSupportWebSocket){
    return;
  }
  if (mWebSocket == null) {
    return;
  }
  Buffer messageBuffer = new Buffer();
  messageBuffer.writeUtf8(message);
  try {
    mWebSocket.sendMessage(WebSocket.PayloadType.TEXT, messageBuffer);
  } catch (IOException e) {
  }
}
项目:weex-3d-map    文件:WXWebSocketManager.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type)
    throws IOException {
  if (type != WebSocket.PayloadType.TEXT) {
    WXLogUtils.w(
        "Websocket received unexpected message with payload of type "
        + type);
    return;
  }
  for (JSDebuggerCallback callback : mCallbacks.values()) {
    callback.onMessage(payload, type);
  }

  String message = null;
  try {
    message = payload.readUtf8();
    JSONObject jsonObject = JSONObject.parseObject(message);
    Object name = jsonObject.get("method");
    Object value = jsonObject.get("arguments");
    if (name == null || value == null) {
      return;
    }
    if (TextUtils.equals(name.toString(), "setLogLevel")) {
      JSONArray jsonArray = JSONObject.parseArray(value.toString());
      String level = jsonArray.get(0).toString();
      WXEnvironment.sLogLevel = LogLevel.valueOf(level.toUpperCase());
      WXLogUtils.v("into--[onMessage]setLogLevel");
    }
  } catch (Exception e) {

  } finally {
    payload.close();
  }
}
项目:weex-3d-map    文件:HotRefreshManager.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type) throws IOException {
  if (type == WebSocket.PayloadType.TEXT) {
    String temp = payload.readUtf8();
    Log.e(TAG, "into--[onMessage] msg:" + temp);
    payload.close();

    if (TextUtils.equals("refresh", temp) && mHandler != null) {
      mHandler.obtainMessage(Constants.HOT_REFRESH_REFRESH, 0, 0, mUrl).sendToTarget();
    }
  }
}
项目:ReactNativeSignatureExample    文件:WebSocketModule.java   
@ReactMethod
public void send(String message, int id) {
  WebSocket client = mWebSocketConnections.get(id);
  if (client == null) {
    // This is a programmer error
    throw new RuntimeException("Cannot send a message. Unknown WebSocket id " + id);
  }
  try {
    client.sendMessage(
      WebSocket.PayloadType.TEXT,
      new Buffer().writeUtf8(message));
  } catch (IOException | IllegalStateException e) {
    notifyWebSocketFailed(id, e.getMessage());
  }
}
项目:ReactNativeSignatureExample    文件:JSDebuggerWebSocketClient.java   
private void sendMessage(int requestID, String message) {
  if (mWebSocket == null) {
    triggerRequestFailure(
        requestID,
        new IllegalStateException("WebSocket connection no longer valid"));
    return;
  }
  Buffer messageBuffer = new Buffer();
  messageBuffer.writeUtf8(message);
  try {
    mWebSocket.sendMessage(WebSocket.PayloadType.TEXT, messageBuffer);
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
项目:ReactNativeSignatureExample    文件:JSDebuggerWebSocketClient.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type) throws IOException {
  if (type != WebSocket.PayloadType.TEXT) {
    FLog.w(TAG, "Websocket received unexpected message with payload of type " + type);
    return;
  }

  String message = null;
  try {
    message = payload.readUtf8();
  } finally {
    payload.close();
  }
  Integer replyID = null;

  try {
    JsonParser parser = new JsonFactory().createParser(message);
    String result = null;
    while (parser.nextToken() != JsonToken.END_OBJECT) {
      String field = parser.getCurrentName();
      if ("replyID".equals(field)) {
        parser.nextToken();
        replyID = parser.getIntValue();
      } else if ("result".equals(field)) {
        parser.nextToken();
        result = parser.getText();
      }
    }
    if (replyID != null) {
      triggerRequestSuccess(replyID, result);
    }
  } catch (IOException e) {
    if (replyID != null) {
      triggerRequestFailure(replyID, e);
    } else {
      abort("Parsing response message from websocket failed", e);
    }
  }
}
项目:react-native-ibeacon-android    文件:WebSocketModule.java   
@ReactMethod
public void send(String message, int id) {
  WebSocket client = mWebSocketConnections.get(id);
  if (client == null) {
    // This is a programmer error
    throw new RuntimeException("Cannot send a message. Unknown WebSocket id " + id);
  }
  try {
    client.sendMessage(
      WebSocket.PayloadType.TEXT,
      new Buffer().writeUtf8(message));
  } catch (IOException | IllegalStateException e) {
    notifyWebSocketFailed(id, e.getMessage());
  }
}
项目:react-native-ibeacon-android    文件:JSDebuggerWebSocketClient.java   
private void sendMessage(int requestID, String message) {
  if (mWebSocket == null) {
    triggerRequestFailure(
        requestID,
        new IllegalStateException("WebSocket connection no longer valid"));
    return;
  }
  Buffer messageBuffer = new Buffer();
  messageBuffer.writeUtf8(message);
  try {
    mWebSocket.sendMessage(WebSocket.PayloadType.TEXT, messageBuffer);
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
项目:react-native-ibeacon-android    文件:JSDebuggerWebSocketClient.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type) throws IOException {
  if (type != WebSocket.PayloadType.TEXT) {
    FLog.w(TAG, "Websocket received unexpected message with payload of type " + type);
    return;
  }

  String message = null;
  try {
    message = payload.readUtf8();
  } finally {
    payload.close();
  }
  Integer replyID = null;

  try {
    JsonParser parser = new JsonFactory().createParser(message);
    String result = null;
    while (parser.nextToken() != JsonToken.END_OBJECT) {
      String field = parser.getCurrentName();
      if ("replyID".equals(field)) {
        parser.nextToken();
        replyID = parser.getIntValue();
      } else if ("result".equals(field)) {
        parser.nextToken();
        result = parser.getText();
      }
    }
    if (replyID != null) {
      triggerRequestSuccess(replyID, result);
    }
  } catch (IOException e) {
    if (replyID != null) {
      triggerRequestFailure(replyID, e);
    } else {
      abort("Parsing response message from websocket failed", e);
    }
  }
}
项目:weex-analyzer-android    文件:HotRefreshManager.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type) throws IOException {
  if (type == WebSocket.PayloadType.TEXT) {
    String temp = payload.readUtf8();
    Log.e(TAG, "into--[onMessage] msg:" + temp);
    payload.close();

    if (TextUtils.equals("refresh", temp) && mHandler != null) {
      mHandler.obtainMessage(Constants.HOT_REFRESH_REFRESH, 0, 0, mUrl).sendToTarget();
    }
  }
}
项目:react-native-box-loaders    文件:WebSocketModule.java   
@ReactMethod
public void send(String message, int id) {
  WebSocket client = mWebSocketConnections.get(id);
  if (client == null) {
    // This is a programmer error
    throw new RuntimeException("Cannot send a message. Unknown WebSocket id " + id);
  }
  try {
    client.sendMessage(
      WebSocket.PayloadType.TEXT,
      new Buffer().writeUtf8(message));
  } catch (IOException | IllegalStateException e) {
    notifyWebSocketFailed(id, e.getMessage());
  }
}
项目:react-native-box-loaders    文件:WebSocketModule.java   
@ReactMethod
public void sendBinary(String base64String, int id) {
  WebSocket client = mWebSocketConnections.get(id);
  if (client == null) {
    // This is a programmer error
    throw new RuntimeException("Cannot send a message. Unknown WebSocket id " + id);
  }
  try {
    client.sendMessage(
      WebSocket.PayloadType.BINARY,
      new Buffer().write(ByteString.decodeBase64(base64String)));
  } catch (IOException | IllegalStateException e) {
    notifyWebSocketFailed(id, e.getMessage());
  }
}
项目:react-native-box-loaders    文件:JSDebuggerWebSocketClient.java   
private void sendMessage(int requestID, String message) {
  if (mWebSocket == null) {
    triggerRequestFailure(
        requestID,
        new IllegalStateException("WebSocket connection no longer valid"));
    return;
  }
  Buffer messageBuffer = new Buffer();
  messageBuffer.writeUtf8(message);
  try {
    mWebSocket.sendMessage(WebSocket.PayloadType.TEXT, messageBuffer);
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
项目:react-native-box-loaders    文件:JSDebuggerWebSocketClient.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type) throws IOException {
  if (type != WebSocket.PayloadType.TEXT) {
    FLog.w(TAG, "Websocket received unexpected message with payload of type " + type);
    return;
  }

  String message = null;
  try {
    message = payload.readUtf8();
  } finally {
    payload.close();
  }
  Integer replyID = null;

  try {
    JsonParser parser = new JsonFactory().createParser(message);
    String result = null;
    while (parser.nextToken() != JsonToken.END_OBJECT) {
      String field = parser.getCurrentName();
      if ("replyID".equals(field)) {
        parser.nextToken();
        replyID = parser.getIntValue();
      } else if ("result".equals(field)) {
        parser.nextToken();
        result = parser.getText();
      }
    }
    if (replyID != null) {
      triggerRequestSuccess(replyID, result);
    }
  } catch (IOException e) {
    if (replyID != null) {
      triggerRequestFailure(replyID, e);
    } else {
      abort("Parsing response message from websocket failed", e);
    }
  }
}
项目:weex-3d-map    文件:WXWebSocketManager.java   
public void sendMessage(String message) {
  if(!isSupportWebSocket){
    return;
  }
  if (mWebSocket == null) {
    return;
  }
  Buffer messageBuffer = new Buffer();
  messageBuffer.writeUtf8(message);
  try {
    mWebSocket.sendMessage(WebSocket.PayloadType.TEXT, messageBuffer);
  } catch (IOException e) {
  }
}
项目:weex-3d-map    文件:WXWebSocketManager.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type)
    throws IOException {
  if (type != WebSocket.PayloadType.TEXT) {
    WXLogUtils.w(
        "Websocket received unexpected message with payload of type "
        + type);
    return;
  }
  for (JSDebuggerCallback callback : mCallbacks.values()) {
    callback.onMessage(payload, type);
  }

  String message = null;
  try {
    message = payload.readUtf8();
    JSONObject jsonObject = JSONObject.parseObject(message);
    Object name = jsonObject.get("method");
    Object value = jsonObject.get("arguments");
    if (name == null || value == null) {
      return;
    }
    if (TextUtils.equals(name.toString(), "setLogLevel")) {
      JSONArray jsonArray = JSONObject.parseArray(value.toString());
      String level = jsonArray.get(0).toString();
      WXEnvironment.sLogLevel = LogLevel.valueOf(level.toUpperCase());
      WXLogUtils.v("into--[onMessage]setLogLevel");
    }
  } catch (Exception e) {

  } finally {
    payload.close();
  }
}
项目:weex-3d-map    文件:HotRefreshManager.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type) throws IOException {
  if (type == WebSocket.PayloadType.TEXT) {
    String temp = payload.readUtf8();
    Log.e(TAG, "into--[onMessage] msg:" + temp);
    payload.close();

    if (TextUtils.equals("refresh", temp) && mHandler != null) {
      mHandler.obtainMessage(Constants.HOT_REFRESH_REFRESH, 0, 0, mUrl).sendToTarget();
    }
  }
}
项目:Weex-TestDemo    文件:WXWebSocketManager.java   
public void sendMessage(String message) {
  if(!isSupportWebSocket){
    return;
  }
  if (mWebSocket == null) {
    return;
  }
  Buffer messageBuffer = new Buffer();
  messageBuffer.writeUtf8(message);
  try {
    mWebSocket.sendMessage(WebSocket.PayloadType.TEXT, messageBuffer);
  } catch (IOException e) {
  }
}
项目:Weex-TestDemo    文件:WXWebSocketManager.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type)
    throws IOException {
  if (type != WebSocket.PayloadType.TEXT) {
    WXLogUtils.w(
        "Websocket received unexpected message with payload of type "
        + type);
    return;
  }
  for (JSDebuggerCallback callback : mCallbacks.values()) {
    callback.onMessage(payload, type);
  }

  String message = null;
  try {
    message = payload.readUtf8();
    JSONObject jsonObject = JSONObject.parseObject(message);
    Object name = jsonObject.get("method");
    Object value = jsonObject.get("arguments");
    if (name == null || value == null) {
      return;
    }
    if (TextUtils.equals(name.toString(), "setLogLevel")) {
      JSONArray jsonArray = JSONObject.parseArray(value.toString());
      String level = jsonArray.get(0).toString();
      WXEnvironment.sLogLevel = LogLevel.valueOf(level.toUpperCase());
      WXLogUtils.v("into--[onMessage]setLogLevel");
    }
  } catch (Exception e) {

  } finally {
    payload.close();
  }
}
项目:Weex-TestDemo    文件:HotRefreshManager.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type) throws IOException {
  if (type == WebSocket.PayloadType.TEXT) {
    String temp = payload.readUtf8();
    Log.e(TAG, "into--[onMessage] msg:" + temp);
    payload.close();

    if (TextUtils.equals("refresh", temp) && mHandler != null) {
      mHandler.obtainMessage(Constants.HOT_REFRESH_REFRESH, 0, 0, mUrl).sendToTarget();
    }
  }
}
项目:weex    文件:WXWebSocketManager.java   
public void sendMessage(String message) {
  if(!isSupportWebSocket){
    return;
  }
  if (mWebSocket == null) {
    return;
  }
  Buffer messageBuffer = new Buffer();
  messageBuffer.writeUtf8(message);
  try {
    mWebSocket.sendMessage(WebSocket.PayloadType.TEXT, messageBuffer);
  } catch (IOException e) {
  }
}
项目:weex    文件:WXWebSocketManager.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type)
    throws IOException {
  if (type != WebSocket.PayloadType.TEXT) {
    WXLogUtils.w(
        "Websocket received unexpected message with payload of type "
        + type);
    return;
  }
  for (JSDebuggerCallback callback : mCallbacks.values()) {
    callback.onMessage(payload, type);
  }

  String message = null;
  try {
    message = payload.readUtf8();
    JSONObject jsonObject = JSONObject.parseObject(message);
    Object name = jsonObject.get("method");
    Object value = jsonObject.get("arguments");
    if (name == null || value == null) {
      return;
    }
    if (TextUtils.equals(name.toString(), "setLogLevel")) {
      JSONArray jsonArray = JSONObject.parseArray(value.toString());
      String level = jsonArray.get(0).toString();
      WXEnvironment.sLogLevel = LogLevel.valueOf(level.toUpperCase());
      WXLogUtils.v("into--[onMessage]setLogLevel");
    }
  } catch (Exception e) {

  } finally {
    payload.close();
  }
}
项目:weex    文件:DebugSocketClient.java   
public void sendMessage(int requestID, String message) {
    if (mWebSocket == null) {
        return;
    }
    Buffer messageBuffer = new Buffer();
    messageBuffer.writeUtf8(message);
    try {
        Log.v(TAG, "sendMessage " + message);
        mWebSocket.sendMessage(WebSocket.PayloadType.TEXT, messageBuffer);
    } catch (IOException e) {
        Log.e(TAG, "sendMessage IOException " + e.toString());
    }
}
项目:weex    文件:DebugSocketClient.java   
@Override
public void onOpen(WebSocket webSocket, Request arg1, Response arg2)
        throws IOException {
    mWebSocket = webSocket;
    if (mConnectCallback != null) {
        mConnectCallback.onSuccess(null);
    }
}
项目:weex    文件:HotRefreshManager.java   
@Override
public void onMessage(BufferedSource payload, WebSocket.PayloadType type) throws IOException {
  if (type == WebSocket.PayloadType.TEXT) {
    String temp = payload.readUtf8();
    Log.e(TAG, "into--[onMessage] msg:" + temp);
    payload.close();

    if (TextUtils.equals("refresh", temp) && mHandler != null) {
      mHandler.obtainMessage(Constants.HOT_REFRESH_REFRESH, 0, 0, mUrl).sendToTarget();
    }
  }
}
项目:appstax-java    文件:AxSocket.java   
private void write(final Item item) {
    new Thread() {
        public void run() {
            try {
                socket.sendMessage(
                    WebSocket.PayloadType.TEXT,
                    new Buffer().writeUtf8(item.payload)
                );
            } catch (IOException e) {
                item.channel.onError(e);
            }
        }
    }.start();
}
项目:appstax-java    文件:AxSocket.java   
@Override
public void onMessage(BufferedSource source, WebSocket.PayloadType payloadType) {
    try {
        String payload = source.readUtf8();
        JSONObject item = new JSONObject(payload);
        onMessageAll(new AxEvent(client, item));
        source.close();
    } catch (IOException e) {
        onErrorAll(e);
    }
}
项目:appstax-java    文件:AxChannelTest.java   
@Override
public void onMessage(BufferedSource source, WebSocket.PayloadType type) throws IOException {
    String payload = source.readUtf8();

    if (payload.contains(pattern)) {
        res.set(payload);
        lock.countDown();
    }

    source.close();
}
项目:appstax-java    文件:AxChannelTest.java   
@Override
public void onOpen(final WebSocket socket, final Response response) {
    new Thread() {
        public void run() {
            try {
                Thread.sleep(100);
                socket.sendMessage(TEXT, new Buffer().writeUtf8(payload));
            } catch (IOException | InterruptedException e) {
                throw new AssertionError(e);
            }
        }
    }.start();

}
项目:bigbang-client-java    文件:DefaultBigBangClient.java   
public void sendToServer(PewMessage msg) {
    final Buffer b = new Buffer();
    b.writeUtf8(wireProtocol.wrapNetstring(msg));

    pool.execute(new Runnable() {
        @Override
        public void run() {
            try {
                socket.sendMessage(WebSocket.PayloadType.TEXT, b);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}
项目:actioncable-client-java    文件:Connection.java   
private void doSend(String data) {
    if (webSocket != null) {
        try {
            webSocket.sendMessage(WebSocket.PayloadType.TEXT, new Buffer().writeUtf8(data));
        } catch (IOException e) {
            if (listener != null) {
                listener.onFailure(e);
            }
        }
    }
}
项目:actioncable-client-java    文件:SubscriptionsTest.java   
@Test(timeout = TIMEOUT)
public void createAfterOpeningConnection() throws URISyntaxException, IOException, InterruptedException {
    final BlockingQueue<String> events = new LinkedBlockingQueue<String>();

    final MockWebServer mockWebServer = new MockWebServer();
    final MockResponse response = new MockResponse();
    response.withWebSocketUpgrade(new DefaultWebSocketListener() {
        @Override
        public void onMessage(BufferedSource payload, WebSocket.PayloadType type) throws IOException {
            events.offer("onMessage:" + payload.readUtf8());
            payload.close();
        }
    });
    mockWebServer.enqueue(response);
    mockWebServer.start();

    final Consumer consumer = new Consumer(mockWebServer.url("/").uri());
    consumer.connect();

    final Subscriptions subscriptions = consumer.getSubscriptions();
    final Subscription subscription = subscriptions.create(new Channel("CommentsChannel"));

    // Callback test
    assertThat(events.take(), is("onMessage:" + Command.subscribe(subscription.getIdentifier()).toJson()));

    mockWebServer.shutdown();
}