use of org.java_websocket.drafts.Draft_17 in project ChatExchange by HueToYou.
the class WebSocketBackend method createWebSocket.
/**
* Creates the WebSocket using the provided URI
* @param uri WebSocket URI
*/
private void createWebSocket(URI uri) {
Map<String, String> headers = new HashMap<>();
headers.put("Cookie", mRequestFactory.cookies());
headers.put("Origin", "https://chat.stackexchange.com");
mWebSocketClient = new WebSocketClient(uri, new Draft_17(), headers, 0) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
Log.i(TAG, "WebSocket connection opened");
}
@Override
public void onMessage(String s) {
for (Event event : mGson.fromJson(s, WsMessage.class).events) {
mBroadcaster.broadcastEvent(event);
}
}
@Override
public void onClose(int i, String s, boolean b) {
// TODO
}
@Override
public void onError(Exception e) {
Log.e(TAG, e.getMessage());
// TODO
}
};
}
Aggregations