 # modules
 socketIo = require 'socket.io'
+events = require 'events'
 
-class WebSockets
+
+class WebSockets extends events.EventEmitter
     # socket.io object
     io: null
     users: {}


# export
module.exports = new WebSockets

# Message : {
#   type: "message|notif"
#   to: "public|team|side",
#    msg: "content of message",
#    author: {
#        id: "ID",
#        user: "Username"
#    },
#    cDate: "Datetime",
#}

    # and handles multiple connections by user
    handleConnection: ->
        @io.on 'connection', (socket) =>
            @emit 'connection', socket
            socket.user = socket.handshake.session.user
            # if the client isn't authenticated, do not continue
            unless socket.user then return
