【问题标题】:Pusher authEndpoint doesn't trigger in react native expoPusher authEndpoint 不会在 react native expo 中触发
【发布时间】:2022-01-04 06:46:47
【问题描述】:

这是我的 react native 代码:

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));
  });

在 Node js 代码中:

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);
    });

这是我的日志:

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"}}]

这里称为事件日志:

Pusher :  : ["Event recd",{"event":"uuganaa","channel":"my-channel","data":{"message":"Sain uu asd"}}]

并向http://10.0.27.124:8070/pusher/auth发送请求,来自auth端点的响应成功响应。

为什么它不触发 authEndpoint 谢谢你的回答。

【问题讨论】:

    标签: node.js react-native authentication pusher pusher-js


    【解决方案1】:

    那是因为您正在为用户订阅公共频道。公共频道不需要授权连接。您需要为用户订阅私人频道。

    https://pusher.com/docs/channels/using_channels/authorized-connections/

    https://pusher.com/docs/channels/using_channels/private-channels/

    【讨论】:

    • 之后我出现了这个错误。无法从身份验证端点检索身份验证字符串。你有什么解决办法吗?
    • 我看到了你的第二个问题。我认为您只是有语法错误。 stackoverflow.com/questions/70578131/…
    猜你喜欢
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    • 1970-01-01
    • 2021-06-15
    • 2021-03-28
    • 2018-12-15
    • 2022-12-29
    • 2021-07-20
    相关资源
    最近更新 更多