在休假,加入,输入vue.js时是否有任何回调? [英] Is there any callback for on leave, on join , on typing in vue.js?
本文介绍了在休假,加入,输入vue.js时是否有任何回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
关于
我正在与Laravel学习Vue.js.目前,正在练习在2个用户之间发送实时文本消息.
I am learning Vue.js with Laravel. Presently, practicing on sending real time text messages between 2 users.
下面的代码将消息发送给另一个用户
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
频道.如上所述,这些渠道也是私有的:
You need to user a presence
channel. As described these channels are also private:
所有在线状态频道也是私人频道
All presence channels are also private channels
您可以使用.join
设置状态频道.
You can set up a presence channel by using .join
.
Echo.join(`chat.${roomId}`)
.here((users) => {
//
})
.joining((user) => {
console.log(user.name);
})
.leaving((user) => {
console.log(user.name);
});
您可以访问要查找的回调.
There you have access to the callback that you are looking for.
这篇关于在休假,加入,输入vue.js时是否有任何回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文