Communication with websocket impossible

Hello,

I am currently trying to create a web page for Mopidy with socket.io, but I’m stuck a this point. Currently when I load the page, I got this error :

Firefox can't establish a connection to the server at ws://localhost:6680/mopidy/ws/.

WebSocket error: error { target: WebSocket, isTrusted: true, currentTarget: WebSocket, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, composed: false, timeStamp: 1491557237568000, cancelBubble: false, originalTarget: WebSocket }

Here is the file that I launch from node :

var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);

var Mopidy = require('mopidy');
var mopidy = new Mopidy({
    webSocketUrl: "ws://localhost:6680/mopidy/ws/"
});

app.use("/", express.static(__dirname + "/"));

http.listen(8080);
console.log('Server running on port 8080');

But I think this is not the problem as, when I start Node, Mopidy write on the console :

DEBUG    2017-04-07 09:26:48,791 [1108:HttpServer] mopidy.http.handlers
  New WebSocket connection from 127.0.0.1
DEBUG    2017-04-07 09:26:48,822 [1108:HttpServer] mopidy.http.handlers
  Received WebSocket message from 127.0.0.1: u'{"method":"core.describe","jsonrpc":"2.0","id":0}'

So node is well connected to mopidy I guess. But the problem seem to come from the controller.js, but i dont know how to solve that.
What could be the cause ?

English isn’t my first language, so please excuse any mistakes
Thanks if you have take time to read me

You are showing your server code. Can you show the corresponding client code?

Excuse me, but what you mean by client code ?
I get an error in the browser console of the client that said :

Firefox can’t establish a connection to the server at ws://localhost:6680/mopidy/ws/.

WebSocket error: error { target: WebSocket, isTrusted: true, currentTarget: WebSocket, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, composed: false, timeStamp: 1491557237568000, cancelBubble: false, originalTarget: WebSocket }

That’s all I see, but I’m still stuck at this point

What exactly are you trying to do here? What url are you trying to load in Firefox? If you want help with your controller.js file then I suggest you provide it.

I am trying to build an http extension that allow user to remove a song by a vote system. When someone start a vote, it open a modal on my webpage, but not on the other. Here is my problem, I want it to be opened on all client connected, at the same time.

So I’ve tried to use Websocket to do this but I’m stuck, because it doesn’t communicate with Mopidy. My controller.js is working i think, as it’s working when Mopidy start the extension. But since i tried to migrate to Websocket, it doesn’t work (I use “node socket.io” to “create” the webpage)

Here is my socket.io :

var express = require(‘express’);
var app = express();
var http = require(‘http’).Server(app);
var io = require(‘socket.io’)(http);

var Mopidy = require(‘mopidy’);
var mopidy = new Mopidy({
webSocketUrl: “ws://localhost:6680/mopidy/ws/”
});

app.use(“/”, express.static(__dirname + “/”));

//When someone connect to the server
io.sockets.on(‘connection’, function (socket) {
socket.emit(‘faitUneAlerte’);
});

http.listen(8080);
console.log(‘Server running on port 8080’);

And my controller.js

‘use strict’;

// Initialize
var mopidy = new Mopidy({
‘callingConvention’ : ‘by-position-or-by-name’
});

I have a github repo if you want to see the whole files (Please don’t pay attention to all the mess) : Here

Thanks in advance for your help