关于
我正在使用 Laravel 学习 Vue.js。目前,正在练习在 2 个用户之间发送实时短信。
下面的代码向另一个用户发送消息
var url = "http://localhost:6001/apps/My_appId/events?auth_key=My_Key";
var socketId = Echo.socketId();
var request = {
"channel": "private-Send-Message-Channel.2",
"name": "MessengerEvent",
"data": {
"msg": message
},
"socket_id": socketId
};
axios.post(url,
JSON.stringify(request))
.then((response) => {
//Success callback
}
);
接收消息
window.Echo.private('Send-Message-Channel.2')
.on('MessengerEvent', (e) => {
//Receive the message
}
);
Question: Is there any callback for on leave, on join , on typing, total users?
最佳答案
您需要使用一个presence
channel 。如前所述,这些 channel 也是私有(private)的:
All presence channels are also private channels
您可以使用 .join
设置在线 channel 。
Echo.join(`chat.${roomId}`)
.here((users) => {
//
})
.joining((user) => {
console.log(user.name);
})
.leaving((user) => {
console.log(user.name);
});
在那里您可以访问您正在寻找的回调。
关于vue.js - 休假,加入,输入vue.js时是否有任何回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48868541/