The awesome service that is Pushbullet have a websocket stream that you can subscribe to and then listen for pushes to your device, which is exactly what I want. I want my App to be able to connect to the messages stream and do stuff based on what they say.
I've tried using https://github.com/andrepew/Java-WebSocket/tree/1.3.0-Android-SSL-Fix (forked from https://github.com/TooTallNate/Java-WebSocket), but am getting no luck. After a bit of a timeout, the connection response comes back with
onClose -1, draft org.java_websocket.drafts.Draft_10@a38fd36 refuses handshake, false
and
05-22 03:24:30.709 15423-15904 java.lang.NullPointerException: ssl == null
05-22 03:24:30.710 15423-15904 com.android.org.conscrypt.NativeCrypto.SSL_read_BIO(Native Method)
05-22 03:24:30.710 15423-15904 com.android.org.conscrypt.OpenSSLEngineImpl.unwrap(OpenSSLEngineImpl.java:477)
05-22 03:24:30.710 15423-15904 javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:1006)
my code to get that is (without my access token...) even trying the "trust all hosts" suggested hack,
private void createConnection()
{
URI uri = URI.create("wss://stream.pushbullet.com/websocket/" + pushAT);
final WebSocketClient mWebSocketClient = new WebSocketClient(uri) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
Log.d(TAG, "onOpen " + serverHandshake);
}
@Override
public void onMessage(String s) {
Log.d(TAG, "onMessage " + s);
}
@Override
public void onClose(int i, String s, boolean b) {
Log.d(TAG, "onClose " + i + ", " + s + ", " + b);
}
@Override
public void onError(Exception e) {
Log.d(TAG, "onError " + e);
e.printStackTrace();
}
};
Log.d(TAG, "Connecting to " + uri);
trustAllHosts(mWebSocketClient);
mWebSocketClient.connect();
Log.d(TAG, "Connecting to " + uri);
}
public void trustAllHosts(WebSocketClient wsc) {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
}};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
wsc.setWebSocketFactory(new DefaultSSLWebSocketClientFactory(sc));
} catch (Exception e) {
e.printStackTrace();
}
}