“Soket Ekspor Koneksi IO” Kode Jawaban

Soket Ekspor Koneksi IO

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

Soket Ekspor Koneksi IO

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

Soket Ekspor Koneksi IO

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

Jawaban yang mirip dengan “Soket Ekspor Koneksi IO”

Pertanyaan yang mirip dengan “Soket Ekspor Koneksi IO”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya