“exportar soquete IO Connection” Respostas de código

exportar soquete IO Connection

let io;

module.exports = {
  init: (server) => {
    io = require('socket.io').listen(server); io.origins('*:*');
    return io;
  },
  get: () => {
    if (!io) {
      throw new Error("socket is not initialized");
    }
    return io;
  }
};
Courageous Chicken

exportar soquete IO Connection

const app = require('../app');
const http = require('http');

/**
 * Get port from environment and store in Express.
 */

const port = '3015';
app.set('port', port);

/**
 * Create HTTP server.
 */

const server = http.createServer(app);
const io = require('./socket.js').init(server);

io.on('connection', (socket) => {
  console.log('Connection success', socket.id);
  socket.on('disconnect', () => {
    console.log('Connection disconnected', socket.id);
  });
}
Courageous Chicken

exportar soquete IO Connection

const io = require('./socket.js').get();
Courageous Chicken

Respostas semelhantes a “exportar soquete IO Connection”

Perguntas semelhantes a “exportar soquete IO Connection”

Procure respostas de código populares por idioma

Procurar outros idiomas de código