A
A
Alexander2019-04-10 16:38:29
JavaScript
Alexander, 2019-04-10 16:38:29

Why does Nuxt keep getting a 101 Switching Protocols response when connecting via socket?

I am writing an application in a bunch of Django + Channels + Nuxt + REST
Nuxt connected like this

// plugins/socket.io.js
import Vue from 'vue'
import VueSocketio from 'vue-socket.io-extended'
import socketio from 'socket.io-client'

export default ({ app, store, nuxtState, req, route }) => {

    let socket = socketio('http://127.0.0.1:8000', {
        autoConnect: false,
        transports: ['websocket'],
        query: {
            auth: 'MY_AUTH_TOKEN'
        },
        path: '/desk-socket/',
    });

    Vue.use(VueSocketio, socket);

    socket.open();

    socket.on('connect', () => {
        store.dispatch('socket/socketConnectUpdate', true);
    });

    socket.on('disconnect', () => {
        store.dispatch('socket/socketConnectUpdate', false);
    });

}

At the same time, the browser console looks like this
5cadf14baea40421524952.png
Why can't a permanent connection be established?? Already spent 3 hours googling and so far to no avail
Tried on a banal jqeury - works fine
let socket = new WebSocket("ws://127.0.0.1:8000/desk-socket/?auth=069ab868f8faf658832fd56c7577e1a9f6f4636f");

     socket.onopen = function() {
         console.log("Соединение установлено.");
     };
     socket.onmessage = function(event) {
         console.log(event);
         $('#app').append("<p>" + event.data + "</p>");
     };

     socket.onclose = function(event) {
        console.log(event)
    };

    socket.onerror = function(error) {
        console.log("Ошибка " + error.message);
    };

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question