feathersjs-ecosystem / socketio

[MOVED] The Feathers Socket.io websocket transport plugin
https://github.com/feathersjs/feathers
MIT License
37 stars 14 forks source link

Connecting to sockets on a path #80

Closed paranoid-android closed 7 years ago

paranoid-android commented 7 years ago

Steps to reproduce

Hello, First, thank you for creating this module for Feathers. I have an app that has a number of pages. Only two of my pages require sockets. I need to have two different socket paths. For example:

In an attempt to do this, I have the following Feathers app setup:

const feathers = require('feathers');
const socketio = require('feathers-socketio');

const app = feathers();
const routes = require('./routes');

app.configure(configuration(path.join(__dirname, '..')));

app.use(compress())
  .options('*', cors())
  .use(cors())
  .use('/public', serveStatic(app.get('public'), staticFileSettings ))
  .use(bodyParser.urlencoded({ extended: true }))
  .configure(routes)
 .configure(socketio())  

In my routes file, I have paths like:

app.get('/logs/feed', function(req, res) {
  app.io.on('connection', function(socket) {
    console.log('connected to log feed!');
    socket.emit('client-connected', { result: 200 });
  });
  res.render('/logs/feed', {});
});

app.get('/customer-support/chat', function(req, res) {
  app.io.on('connection', function(socket) {
    console.log('connected to customer support chat');
    socket.emit('client-connected', { result: 200 });
  });
  res.render('/customer-support/chat', {});
});

In my app, I then try to connect via the socket.io client library like this:

var socket = io('/customer-support/chat');
console.log(socket.id);

var self = this;
socket.on('connect', function() {
  console.log('connected!');
  console.log(socket.id);
});

Expected behavior

The client side app should successfully connect via a socket over the desired path. That desired path is /customer-support/chat

Actual behavior

The client side app never connects to the server.

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working): feathers-socketio: "2.0.0"

NodeJS version: v.6.9.4

Operating System: WIndows 10

Browser Version: Google Chrome

React Native Version: N/A

Module Loader: N/A

daffl commented 7 years ago

Are you sure Socket.io paths is what you are looking for? To me this seems like two separate services that you then connect to via Feathers on the client.

As it stands right now you are not using any of Feathers functionality which you can of course do but it kind of defeats the purpose 😉 I recommend to go through the chat guide to get an idea how all those things fit together.