added user events

This commit is contained in:
Kevin Jahns
2015-04-28 11:31:43 +02:00
parent 729d7ed3aa
commit 80f1cfd21b
11 changed files with 429 additions and 158 deletions

View File

@@ -45,6 +45,10 @@ module.exports =
@current_sync_target = null
@sent_hb_to_all_users = false
@is_initialized = true
@connections_listeners = []
onUserEvent: (f)->
@connections_listeners.push f
isRoleMaster: ->
@role is "master"
@@ -66,6 +70,12 @@ module.exports =
userLeft: (user)->
delete @connections[user]
@findNewSyncTarget()
for f in @connections_listeners
f {
action: "userLeft"
user: user
}
userJoined: (user, role)->
if not role?
@@ -81,6 +91,12 @@ module.exports =
# TODO: What if there are two masters? Prevent sending everything two times!
@performSyncWithMaster user
for f in @connections_listeners
f {
action: "userJoined"
user: user
role: role
}
#
# Execute a function _when_ we are connected. If not connected, wait until connected.