Node.js, socket, io and HTTPS -


i'm making whiteboard app:

var app = require('express')(); var http = require('http').server(app); var io = require('socket.io')(http);  io.on('connect', function(socket) {   socket.on('join', function(data) {     socket.join(data.room);     console.log(data.room);   });    socket.on('drawing', function(data) {     console.log(data);     io.sockets.in(data.room).emit("senddraw", data);   });    socket.on('writetext', function(data) {     console.log(data);     io.sockets.in(data.room).emit("senddraw", data);   });    socket.on('action', function(data) {     console.log(data);     io.sockets.in(data.room).emit("action", data);   });  });  http.listen(8080, function() {   console.log('listening on localhost:8080'); }); 

if run node script on server, can connect via localhost copy of webpage. however, canon't connect copy hosted on server it's served on https. error:

polling-xhr.js:264 mixed content: page at: ***** loaded on https, requested insecure xmlhttprequest endpoint 'http://...*:8080/socket.io/?eio=3&transport=polling&t=lu2nogl'. request has been blocked; content must served on https.

how can make resolve without disabling ssl on server?

client has equivalent to:

  //var socket = io.connect("http://localhost:8080");   var socket = io.connect("http://**.***.***.**:8080");    socket.on("connect", function(data) {     socket.emit("join", {room : "@roomid"});   }); 

on drawing events:

socket.emit("drawing", {x0 : x0, y0 : y0, x1 : x1, y1: y1, current : current, room : "@roomid"}); 

which picked on by:

socket.on("drawing", function(data) {do blah}); 

you need change socket.io client code in webpage's javascript connecting / instead of http://...*:8080:

var socket = io.connect('/'); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -