     username:     undefined
     color:        undefined
 
+    # Registers callbacks for events
     constructor: (@host, @username, @color) ->
       @net = new netClient @host
 

    handleEnd: =>
      @emit 'end'

    handleServerDown: ->

    initialize: (transform) =>
      @emit types.clear
      @id       = transform.clientId

    selectionChanged: (transform) ->
      @sendToServer transform

    # An textChange event has been sent by the server.
    # The text needs to be changed now.
    changeText: (transform) ->
      @state.set transform.id, transform.state.get transform.id
      @emit types.textChange, transform

    # Update the cursor of a client.
    updateCursor: (transform) ->
      @emit types.updateCursor, transform

    # Update the selection of a client.
    changeSelection: (transform) ->
      @emit types.selectionChanged, transform

    # A new client has connected
    newClient: (transform) ->
      @clients.push transform.client
      @state.add transform.client.id
      @emit types.newUser,
        clientId:   transform.client.id
        username:   transform.client.username
        color:      transform.client.color

    # A client left the session
    clientLeft: (transform) ->
      @emit types.userLeft,
        clientId: transform.client.id