vendredi 22 avril 2016

ember-cli-mirage redirects socket.io client which is injected in mirage

the issue that occurs here, is that, when i connect between sample socekt.io client with this socket.io server by node.js ( just running two terminals and opening socket connection between client and server) I have no problems.

But, when I am trying to inject this socket.io-client into my Ember.js application, precisely to ember-cli-mirage it redirects my client from given address :
( 'http: //localhost:8080')
to something like
http: //localhost:8080/http://ift.tt/248QXgd;.....
also Mirage displays me an error that I cannot handle, even by setting up precise namespace, routing the wsClient.connect() method or calling this.passthrough() , before calling wsClient.connect() .


I also paste the the screenshot of error from inspect console in browser:

error image


Do you have any idea how to resolve this problem? Thank you in advance and I also hope that the topic is not duplicated.

// server.js
var app = require('http').createServer(handler);
var io = require('socket.io')(app);
app.listen(8080);

function handler(req, res) {
  res.writeHead(200);
  res.end('default.index');
}

var rooms = {
  'room1': [

  ],
  'room2': [

  ]
};

io.on('connection', function(socket) {
  console.log('client connected');


  socket.on('join', function(roomName) {
    rooms[roomName].push(socket.id);
    socket.join(roomName);
  });

  socket.on('leave', function(roomName) {
    var toRemove = rooms[roomName].indexOf(socket.id);
    rooms[roomName].splice(toRemove, 1);
    socket.leave('roomName');
  });


  socket.on('eNotification', function(data) {
    console.log(data);
    io.to(socket.id).emit('eNotificationCall', data);
    io.to('room2').emit('eventNotification', data);
  });


  socket.on('gNotification', function(data) {
    console.log(data);
    io.to(socket.id).emit('gNotificationCall', data);
    io.to('room1').emit('diagram1Notification', data);
  });


  socket.on('close', function() {
    console.log('client disconnected');
  });

});


//client.js
var wsClient = {
  socket: null,
  connect: function() {
    this.socket = io.connect('http://localhost:8080');
    this.socket.on('connect', function() {

      console.log('mirage client connected!');
    });

  },
  send: function(eventData, graphData) {
    this.socket.emit('eNotification', eventData);
    this.socket.emit('gNotification', graphData);
  }

};
export default wsClient;



//config.js
import wsClient from './websockets/client';

export default function() {
wsClient.connect();
console.log(wsClient.socket);
var graphData = {X: "2", Y: "3"};
var eventData = {myDAta: 'myDAta', message: 'message'};
setInterval(function() {
    wsClient.send(graphData, eventData);
}, 5000);
}




Aucun commentaire:

Enregistrer un commentaire