             alert error.type
 
         peer.on "open", (peerId) =>
-            if isHost
-                peerIdForHost = peer.id
-                @setState peerIdForHost: peerIdForHost
+            if isFounder
+                peerIdForFounder = peer.id
+                @setState peerIdForFounder: peerIdForFounder
 
                 peer.on "connection", (connection) =>
                     connection.on "open", =>

    displayName: "ChatLink"

    render: ->
        if not @props.peerIdForHost
            return Noop()

        (Input id: "chatLink", label: "Chat Link", readOnly: true, value: @getLink())

    getLink: ->
        "#{ BASE_URL }/#/chat/#{ @props.peerIdForHost}"

Chat = React.createClass
    displayName: "Chat"

    getInitialState: ->
        peerIdForHost: null
        messages: []

    componentWillMount: ->
        peerIdForHost = getSegments()[1]
        isHost = not peerIdForHost?

        peer = new Peer(key: PEER_KEY)



    render: ->
        (Dom.div null,
            (ChatLink peerIdForFounder: @state.peerIdForFounder),
            (ChatMessages messages: @state.messages),
            (ChatForm sendMessage: @sendMessage))

