W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
如果你的單頁面應(yīng)用需要通過 private / presence broadcast channels 進(jìn)行身份認(rèn)證,你需要在你的 routes/api.php
文件中調(diào)用 Broadcast::routes
方法:
Broadcast::routes(['middleware' => ['auth:sanctum']]);
接下來,為了使 Pusher 的授權(quán)請求成功,你需要在初始化 Laravel Echo 時提供自定義的 Pusher authorizer
。這可以讓你的應(yīng)用程序?qū)?Pusher 配置為 為了跨域請求正確配置的 axios
實(shí)例 properly configured for cross-domain requests:
window.Echo = new Echo({
broadcaster: "pusher",
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
encrypted: true,
key: process.env.MIX_PUSHER_APP_KEY,
authorizer: (channel, options) => {
return {
authorize: (socketId, callback) => {
axios.post('/api/broadcasting/auth', {
socket_id: socketId,
channel_name: channel.name
})
.then(response => {
callback(false, response.data);
})
.catch(error => {
callback(true, error);
});
}
};
},
})
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: