Is there any callback for on leave, on join , on typing in vue.js?

孤人 提交于 2020-01-24 05:28:12

问题


About

I am learning Vue.js with Laravel. Presently, practicing on sending real time text messages between 2 users.

Below code sends message to another user

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
    }
);

Receive the message

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?


回答1:


You need to user a presence channel. As described these channels are also private:

All presence channels are also private channels

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.



来源:https://stackoverflow.com/questions/48868541/is-there-any-callback-for-on-leave-on-join-on-typing-in-vue-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!