3 回答

TA貢獻1900條經(jīng)驗 獲得超5個贊
連接到套接字服務器后需要使用emit:
window.io = require('socket.io-client');
const socket = io('https://localhost:8080');
socket.on('connect', () => {
socket.emit('your_channel_to_emit', {your_data});
});

TA貢獻1817條經(jīng)驗 獲得超6個贊
將其添加到您的事件 (App\EventName):
public function broadcastWith()
{
return [
'data' => "your data",
'moredata' => "more data",
];
}
并在 JS 中像這樣訪問您的數(shù)據(jù):
Echo.channel('channel-name')
.listen('EventName', (event) => {
console.log(event.data);
console.log(event.moredata);
console.log(event['moredata']);
}

TA貢獻1836條經(jīng)驗 獲得超13個贊
默認情況下,Echo 將使用/broadcasting/auth端點來授權通道訪問。如果您的客戶端不在同一主機上,您將必須自定義推送器的 authEndpoint。authEndpoint您可以通過將配置選項傳遞給您的 Echo 實例來指定您自己的授權端點:
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'your-pusher-channels-key',
authEndpoint: '/custom/endpoint/auth', //customize here.
});
- 3 回答
- 0 關注
- 130 瀏覽
添加回答
舉報