37 lines
817 B
CoffeeScript
37 lines
817 B
CoffeeScript
# node libraries
|
|
socketio = (require 'socket.io')
|
|
path = (require 'path')
|
|
|
|
# my libraries
|
|
|
|
FFTCGSOCKET = (http, session) ->
|
|
that = @
|
|
|
|
# create server socket
|
|
@io = socketio http
|
|
@io.use session
|
|
|
|
# on new connection
|
|
@io.on 'connection', (socket) ->
|
|
@session = socket.handshake.session
|
|
console.log "session '#{@session.id}' connected"
|
|
console.log "is user '#{@session.userID}'" if @session.userID
|
|
|
|
socket.on 'disconnect', ->
|
|
console.log "session '#{that.session.id}' disconnected"
|
|
console.log "is user '#{that.session.userID}'" if that.session.userID
|
|
|
|
return
|
|
|
|
FFTCGSOCKET::close = ->
|
|
console.log '[FFTCGSOCKET] shutting down'
|
|
if @db
|
|
@db.close()
|
|
.then (msg) ->
|
|
console.log msg
|
|
.catch (err) ->
|
|
console.error err
|
|
|
|
|
|
|
|
module.exports = FFTCGSOCKET
|