Level session playtime logging

This commit is contained in:
Michael Schmatz 2014-05-16 15:27:46 -07:00
parent 5b93414862
commit e631bae248
2 changed files with 15 additions and 3 deletions
app/lib
server/levels/sessions

View file

@ -21,19 +21,30 @@ module.exports = class LevelBus extends Bus
'level-show-victory': 'onVictory'
'tome:spell-changed': 'onSpellChanged'
'tome:spell-created': 'onSpellCreated'
'application:idle-changed': 'onIdleChanged'
constructor: ->
super(arguments...)
@changedSessionProperties = {}
@saveSession = _.debounce(@saveSession, 1000, {maxWait: 5000})
@playerIsIdle = false
init: ->
super()
@fireScriptsRef = @fireRef?.child('scripts')
setSession: (@session) ->
@listenTo(@session, 'change:multiplayer', @onMultiplayerChanged)
@timerIntervalID = setInterval(@incrementSessionPlaytime, 1000)
onIdleChanged: (e) ->
@playerIsIdle = e.idle
incrementSessionPlaytime: =>
if @playerIsIdle then return
@changedSessionProperties.playtime = true
@session.set("playtime",@session.get("playtime") + 1)
onPoint: ->
return true unless @session?.get('multiplayer')
super()
@ -226,4 +237,5 @@ module.exports = class LevelBus extends Bus
tempSession.save(patch, {patch: true})
destroy: ->
clearInterval(@timerIntervalID)
super()

View file

@ -8,7 +8,7 @@ class LevelSessionHandler extends Handler
modelClass: LevelSession
editableProperties: ['multiplayer', 'players', 'code', 'codeLanguage', 'completed', 'state',
'levelName', 'creatorName', 'levelID', 'screenshot',
'chat', 'teamSpells', 'submitted', 'unsubscribed']
'chat', 'teamSpells', 'submitted', 'unsubscribed','playtime']
jsonSchema: require '../../../app/schemas/models/level_session'
getByRelationship: (req, res, args...) ->