function init(server) {
  // init params
  const { WebSocketPort, NuxtPort, isProduction } = require('../_env')
  const { userNamespace } = require('./namespaces/user_NameSpace')
  const { agentNamespace } = require('./namespaces/agent_NameSpace')
  const { adminNamespace } = require('./namespaces/admin_NameSpace')
  const { Server } = require('socket.io')
  const socketIO = require('socket.io')

  // init ws
  let io
  if (isProduction) io = socketIO(server)
  else io = new Server(WebSocketPort, { cors: { origin: '*' } })
  console.log(`🟢 ~ WebSocket Server is listening on port ${isProduction ? NuxtPort : WebSocketPort}`)
  global._io = io

  // namespaces
  userNamespace()
  agentNamespace()
  adminNamespace()
}

module.exports = init
