sessions?
This commit is contained in:
parent
b24b05009f
commit
8d5a31a5dc
4 changed files with 25 additions and 13 deletions
|
@ -7,9 +7,11 @@ FFTCGDB = (require './fftcgdb')
|
|||
|
||||
FFTCGSOCKET = (http, dbfile) ->
|
||||
that = @
|
||||
# create server socket, open fftcg.db
|
||||
@io = socketio http
|
||||
@db = new FFTCGDB dbfile
|
||||
|
||||
# on new connection
|
||||
@io.on 'connection', (socket) ->
|
||||
that.__connection socket
|
||||
|
||||
|
@ -18,13 +20,16 @@ FFTCGSOCKET = (http, dbfile) ->
|
|||
FFTCGSOCKET::__connection = (socket) ->
|
||||
that = @
|
||||
|
||||
console.log 'a user connected'
|
||||
# offer server socket id
|
||||
socket.emit 'serverid', socket.id
|
||||
|
||||
console.log socket.handshake.headers['cookie']
|
||||
socket.emit 'id', socket.handshake.headers['cookie']
|
||||
# accept client side id
|
||||
socket.on 'clientid', (clientid) ->
|
||||
@clientid = clientid
|
||||
console.log "user '#{@clientid}' connected"
|
||||
|
||||
socket.on 'disconnect', ->
|
||||
console.log 'a user disconnected'
|
||||
console.log "user '#{@clientid}' disconnected"
|
||||
|
||||
socket.on 'register', (login, password) ->
|
||||
that.__register login, password
|
|
@ -5,13 +5,10 @@ http = (require 'http')
|
|||
path = (require 'path')
|
||||
|
||||
# my libraries
|
||||
FFTCGSOCKET = (require './inc/socket')
|
||||
FFTCGSOCKET = (require './inc/fftcgsocket')
|
||||
|
||||
# express + socket framework
|
||||
app = express()
|
||||
web = http.Server app
|
||||
socket = new FFTCGSOCKET(web, path.resolve(__dirname, 'fftcg.db'))
|
||||
|
||||
app.use helmet()
|
||||
|
||||
# Static content
|
||||
|
@ -23,9 +20,12 @@ app.get '/:template.html', (req, res) ->
|
|||
res.render (req.params.template + '.pug')
|
||||
|
||||
# Create server
|
||||
web = http.Server app
|
||||
web.listen 3000, ->
|
||||
console.log '[FFTCG] Listening on port 3000 ...'
|
||||
|
||||
socket = new FFTCGSOCKET web, path.resolve(__dirname, 'fftcg.db')
|
||||
|
||||
# Handle termination
|
||||
process.on 'SIGINT', ->
|
||||
socket.close()
|
||||
|
|
|
@ -11,11 +11,21 @@ $ ->
|
|||
|
||||
# init Socket.IO
|
||||
socket = io()
|
||||
console.log socket
|
||||
|
||||
require './index/localStorage.coffee'
|
||||
|
||||
socket.on 'id', (session) ->
|
||||
console.log session
|
||||
|
||||
|
||||
socket.on 'id', (socketid) ->
|
||||
if storageAvailable 'localStorage'
|
||||
myid = localStorage.getItem 'myid'
|
||||
if not myid
|
||||
localStorage.setItem 'myid', socketid
|
||||
myid = socketid
|
||||
|
||||
console.log "id is '#{myid}'"
|
||||
socket.emit 'id', myid
|
||||
|
||||
# login form
|
||||
$('form[name="login"]').submit ->
|
||||
|
|
|
@ -19,6 +19,3 @@ window.storageAvailable = (type) ->
|
|||
e.name == 'NS_ERROR_DOM_QUOTA_REACHED') and
|
||||
# acknowledge QuotaExceededError only if there's something already stored
|
||||
storage.length != 0
|
||||
|
||||
if storageAvailable 'sessionStorage'
|
||||
console.log "yay"
|
||||
|
|
Reference in a new issue