   ###
   addTalkingParticipant: (nickname) ->
 
-    index = @state.talkingParticipants.indexOf nickname
-
-    if index is -1
-      @state.talkingParticipants.push nickname
+    pushToCollection @state.talkingParticipants, nickname, =>
       @emitChange()
 
 

  ###
  addVideoParticipant: (nickname, emitEvent = yes) ->

    index = @state.videoParticipants.indexOf nickname

    if index is -1
      @state.videoParticipants.push nickname
      @emitChange()  if emitEvent


  ###*

    @emitChange()


###*
 * Pushes to collection with an existential check first.
 * If item is not there already it will push it and will call the callback. If
 * item is already there, this is basically a noop. It won't call the callback
 * and so on. If this is really weird, we can change the accepted callback into
 * a callback that accepts an `err` object (just like the other ones) to make
 * it more familiar.
 *
 * @param {array} collection
 * @param {(string|number)} item
 * @param {function} callback
###
pushToCollection = (collection, item, callback) ->

  # if item is not in collection
  if collection.indexOf(item) is -1
    collection.push item
    callback?()


###*
 * Removes from collection with an existential check first.
 * If item is there already it remove it and will call the callback. If
 * item is not already there, this is basically a noop. It won't call the callback
 * and so on. If this is really weird, we can change the accepted callback into
 * a callback that accepts an `err` object (just like the other ones) to make
 * it more familiar.
 *
 * @param {array} collection
 * @param {(string|number)} item
 * @param {function} callback
###
removeFromCollection = (collection, item, callback) ->

  # if item is in collection
  unless index = collection.indexOf(item) is -1
    collection.splice index, 1
    callback?()


