Implementing Android Pusher Request Object in HttpAuthorizer
I am new to Pusher. I have successfully implemented a public channel subscription in my application. I am now stuck with subscribing to a private android channel.
We have to pass the request body parameters to our server endpoint. In my iOS app, we create a custom authorizer to send the request body to PusherOption. But in Android there are only 2 options for sending parameters to PusherOptions like setHeaders () and setQueryStringParameters ().
I need to send the following body with a url:
["data": ["socket_id": SOCKET_ID, "user_id": USER_ID, "channel": "private-CHANNEL_NAME"]]
I am currently getting an exception in onAuthenticationFailure as [com.pusher.client.AuthorizationFailureException: java.io.FileNotFoundException: MY ENDPOINT URL].
My current Android code looks like this:
public static void subscribePrivateChannel(final String channelName, final String userId, final String authKey) {
final HttpAuthorizer authorizer = new HttpAuthorizer(MY_ENDPOINT_URL);
PusherOptions options = new PusherOptions().setEncrypted(true).setAuthorizer(authorizer);
final Pusher pusher = new Pusher(Config.PUSHER_APP_KEY, options);
pusher.connect(new ConnectionEventListener() {
@Override
public void onConnectionStateChange(ConnectionStateChange connectionStateChange) {
if (connectionStateChange.getCurrentState().toString().equalsIgnoreCase("CONNECTED")) {
String socketId = pusher.getConnection().getSocketId();
HashMap<String, String> parameters = new HashMap<>();
parameters.put("socket_id", socketId);
parameters.put("channel", channelName);
parameters.put("user_id", userId);
authorizer.setQueryStringParameters(parameters);
pusher.subscribePrivate(channelName, new PrivateChannelEventListener() {
@Override
public void onAuthenticationFailure(String s, Exception e) {
Log.d(TAG, "onAuthenticationFailure() called with: s = [" + s + "], e = [" + e + "]");
}
@Override
public void onSubscriptionSucceeded(String s) {
Log.d(TAG, "onSubscriptionSucceeded() called with: s = [" + s + "]");
}
@Override
public void onEvent(String s, String s1, String s2) {
Log.d(TAG, "onEvent() called with: s = [" + s + "], s1 = [" + s1 + "], s2 = [" + s2 + "]");
}
});
}
}
@Override
public void onError(String s, String s1, Exception e) {
Log.d(TAG, "onError() called with: s = [" + s + "], s1 = [" + s1 + "], e = [" + e + "]");
}
});
}
No one has answered this question yet
See similar questions:
or similar: