【发布时间】:2015-04-09 13:35:21
【问题描述】:
我正在尝试从 Android 客户端订阅在线状态频道,但我一直未能通过身份验证部分。我可以毫无问题地订阅普通频道。 连接推送器:
try {
authorizer = new HttpAuthorizer("http://test.xxxx.io/pusher/auth");
authorizer.setHeaders(getHeaders());
PusherOptions options = new PusherOptions().setEncrypted(true).setAuthorizer(authorizer);
pusher = new Pusher(JWTHelper.pusherKey, options);
pusher.connect(new ConnectionEventListener() {
@Override
public void onConnectionStateChange(ConnectionStateChange change) {
Log.d(TAG, "State changed to " + change.getCurrentState() + " from " + change.getPreviousState());
if (change.getCurrentState().toString().equalsIgnoreCase("CONNECTED")) {
Log.d(TAG, "Try to connect to presence channel.");
connectToChannels(pusher);
}
}
@Override
public void onError(String message, String code, Exception e) {
Log.d(TAG, "There was a problem connecting to Pusher." + message);
}
}, ConnectionState.ALL);
if (pusher.getConnection().getState() == ConnectionState.DISCONNECTED) {
pusher.connect();
} else if (pusher.getConnection().getState() == ConnectionState.CONNECTED) {
pusher.disconnect();
}
} catch (Exception e) {
Log.d(TAG, "Pusher exception:" + e.getMessage());
}
然后我尝试订阅一个频道(有效)和一个出席频道(这是它不起作用的地方):
String socketId = pusher.getConnection().getSocketId();
Log.d(TAG, "socket id: " + socketId);
HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put("socket_id", socketId);
parameters.put("channel_name", "presence-mod_111");
authorizer.setQueryStringParameters(parameters);
// test. this works
pusher.subscribe("account_111");
// error
pusher.subscribePresence("presence-mod_111");
这是堆栈跟踪:
State changed to CONNECTING from DISCONNECTED
(standard input):D/TEST( 6949): State changed to CONNECTED from CONNECTING
(standard input):D/TEST( 6949): Try to connect to presence channel.
(standard input):D/TEST( 6949): (in method)socket id: 45048.110272
(standard input):D/TEST( 7676): connect to account 111...
(standard input):D/TEST( 7676): State changed to CONNECTING from DISCONNECTED
(standard input):D/TEST( 7676): connection..null
(standard input):D/TEST( 7676): State changed to CONNECTED from CONNECTING
(standard input):D/TEST( 7676): Try to connect to presence channel.
(standard input):D/TEST( 7676): (in method)socket id: 45142.76981
(standard input):D/TEST( 9258): State changed to CONNECTING from DISCONNECTED
(standard input):D/TEST( 9258): State changed to CONNECTED from CONNECTING
(standard input):D/TEST( 9258): Try to connect to presence channel.
(standard input):D/TEST( 9258): socket id: 45107.97746
(standard input):D/TEST( 9258): arg0 java.io.FileNotFoundException: http://test.xxx.com/pusher/auth, arg1: com.pusher.client.AuthorizationFailureException: java.io.FileNotFoundException: http://test.xxx.com/pusher/auth
我没有更多的想法,任何提示都会很棒。谢谢。
【问题讨论】:
-
嗨,您找到解决方案了吗?