reactjs - laravel/beyondcode pusher 不使用 react-native 返回不可用状态
问题描述
const PusherClient = new Pusher('pusherAppKey001', {
encrypted:true,
wssPort:6001,
wsHost:`${PUSHER_SERVER}`,
cluster:'mt1',
disableStats:true,
authEndpoint: `${PUSHER_SERVER}/broadcasting/auth`,
auth:{
headers: {
Authorization: "Bearer " + jwtToken,
Accept: "application/json"
}
},
});
PusherClient.connection.bind('state_change',(state)=>
{
console.log(state);
console.log(state.current);
})
如果我使用 pusher 中的密钥,它可以正常工作,但根据超出代码文档,我们可以在我们的 .env 文件中设置任何 app_id,key... ,它会正常工作
解决方案
经过几个小时尝试不同的事情后终于解决了,事实证明,因为我在我的本地机器上工作,我需要将加密设置为错误,将传输介质设置为 ws,并更改我的默认 URL,我当前的设置如下所示:
useEffect(() => {
Pusher.logToConsole = true;
let PusherClient = new Pusher('cf33f3r45fe34',{
cluster: 'mt1',
wsHost: PUSHER_SERVER,
wsPort: '6001',
encrypted:false,
enabledTransports: ['ws'],
forceTLS: false
});
let echo = new Echo({
broadcaster: 'pusher',
client: PusherClient
});
PusherClient.connection.bind('state_change',(data)=>
{
console.log('did it work?')
console.log(data);
})
echo.channel('home').listen('NewMessage', (e) => {
alert()
});
})
请注意,我的推送服务器是我的 IP 地址,没有附加 http,更像是“192.168.33.12”
推荐阅读
- jdbc - KAFKA JDBC Source 连接器添加了默认模式
- java - 布尔到二进制字节的数组
- c# - 如果我选择相同的选项(相同的索引),如何触发 DropDownList SelectedIndexChanged?
- javascript - 开玩笑的模拟异步存储测试失败,收到空值,测试它的正确方法是什么?
- javascript - 如何使用字符串访问类型化对象的值?
- reactjs - Vscode Webpack Bable 运行来自不同项目的反应组件
- c# - 使用自定义图像时,MKAnnotationView 不显示标题
- laravel - 我应该在 laravel 8 项目部署时忽略 .editorconfig 文件吗
- blazor-server-side - 使用 Blazor 显示图像
- python - gevent.hub.LoopExit:此操作将永远阻塞