“exportieren Socket IO -Verbindung” Code-Antworten

exportieren Socket IO -Verbindung

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

exportieren Socket IO -Verbindung

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

exportieren Socket IO -Verbindung

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

Ähnliche Antworten wie “exportieren Socket IO -Verbindung”

Fragen ähnlich wie “exportieren Socket IO -Verbindung”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen