Here is my code on the react native code :
const pusher = new Pusher('app_key', {
cluster: 'ap1',
authEndpoint: 'http://10.0.27.124:8070/pusher/auth'
});
const channel = pusher.subscribe('my-channel');
channel.bind('uuganaa', function (data) {
alert(JSON.stringify(data));
});
in Node js code :
app.post('/pusher/auth', (req, res) => {
let socketId = req.body.socket_id;
let channel = req.body.channel_name;
random_string = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
let presenceData = {
user_id: random_string,
user_info: {
username: '@' + random_string,
}
};
let auth = pusher.authenticate(socketId, channel, presenceData);
res.send(auth);
});
Here is my log :
Pusher : : ["State changed","initialized -> connecting"]
Pusher : : ["Connecting",{"transport":"ws","url":"wss://ws-ap1.pusher.com:443/app/73286f08a5b2aeeea398?protocol=7&client=js&version=7.0.3&flash=false"}]
Pusher : : ["State changed","connecting -> connected with new socket ID 12784.212561977"]
Pusher : : ["Event sent",{"event":"pusher:subscribe","data":{"auth":"","channel":"my-channel"}}]
Here is called event log :
Pusher : : ["Event recd",{"event":"uuganaa","channel":"my-channel","data":{"message":"Sain uu asd"}}]
And send request to http://10.0.27.124:8070/pusher/auth the response from the auth endpoint succesfully responding.
Why it doesn't trigger authEndpoint Thank you for your answer.
That's because you're subscribing user to a public channel. Public channels don't require authorized connection. You need to subscribe user to a private channel.
https://pusher.com/docs/channels/using_channels/authorized-connections/
https://pusher.com/docs/channels/using_channels/private-channels/