R
R
Rishat Sultanov2018-04-09 22:06:15
JavaScript
Rishat Sultanov, 2018-04-09 22:06:15

How to trace a socket.io connection?

Good evening gentlemen!
In the component, I'm trying to track the state of the socket, and display a notification about the status of the connection.

<template>

</template>
    
<script>
    export default {
        name: "MessageComponent"
    };
    var vm = new Vue({
        sockets:{
            connect: function(){
                this.$vs.notify({title:'Соединение',text:'Вы успешно подключились к чату!',color:'success',position:'bottom-center'});
            }
        },
    });
</script>

<style scoped>

</style>

How to output that you have lost connection with the socket?
Failed to load resource: net::ERR_CONNECTION_REFUSED

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rishat Sultanov, 2018-04-12
@rishatss

I found observer statuses and caught the error like this. If you are interested, you can see all other statuses in the docks :)

export default {
        mounted() {
            var vm = new Vue({
                sockets:{
                    connect: function(){
                        this.$vs.notify({title:'Соединение',text:'Вы успешно подключились к чату!',color:'success',position:'bottom-center'});
                    },
                    connect_error: function(){
                        this.$vs.notify({title:'Соединение',text:'Ошибка сервера, не могу подключить к чату!',color:'danger',position:'bottom-center'});
                    }
                }
            });
        }
    }

P
pingo, 2018-04-10
@pingo

watch : {
     status : (vol) => {
       if(vol == 'ERR_CONNECTION_REFUSED'){
             this.do(something)
           }
      }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question