This repository has been archived on 2024-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
node-fftcg/inc/socket.coffee

39 lines
860 B
CoffeeScript
Raw Normal View History

# node libraries
socketio = (require 'socket.io')
path = (require 'path')
2018-12-27 12:03:58 +00:00
FFTCGLOG = new (require './console')('FFTCGSOCKET')
# my libraries
FFTCGSOCKET = (http, session) ->
that = @
2018-12-15 20:09:01 +00:00
# create server socket
@io = socketio http
2018-12-15 20:09:01 +00:00
@io.use session
2018-12-14 22:41:43 +00:00
# on new connection
@io.on 'connection', (socket) ->
@session = socket.handshake.session
2018-12-27 12:03:58 +00:00
FFTCGLOG.log "session '#{@session.id}' connected"
FFTCGLOG.log "is user '#{@session.userID}'" if @session.userID
socket.on 'disconnect', ->
2018-12-27 12:03:58 +00:00
FFTCGLOG.log "session '#{that.session.id}' disconnected"
FFTCGLOG.log "is user '#{that.session.userID}'" if that.session.userID
return
FFTCGSOCKET::close = ->
2018-12-27 12:03:58 +00:00
FFTCGLOG.log 'shutting down'
if @db
@db.close()
.then (msg) ->
console.log msg
.catch (err) ->
console.error err
module.exports = FFTCGSOCKET