 
                     @connections.push connection
 
+                    @listenForMessage connection
+
                     peerIds = @connectionsToPeerIds @connections
 
                     console.log "connected peers: #{ peerIds }"


                            c.send type: "newConnection", peerIds: peerIds

                    connection.on "data", (data) =>
                        if data.type == "message"
                            messages = @state.messages
                            messages.push data.message
                            @setState messages: messages

            if who != "x"
                console.log "acting as #{ who }, normal peer"

                connection = peer.connect "x"
                console.log "connecting to x, host"

                @connections.push connection

                connection.on "error", (error) =>
                    alert error

                connection.on "open", =>
                    console.log "connection to #{ connection.peer } open"

                    connection.on "data", (data) =>
                        if data.type == "message"
                            messages = @state.messages
                            messages.push data.message
                            @setState messages: messages

                    connection.on "data", (data) =>
                        if data.type == "newConnection"

        _.forEach @connections, (c) ->
            console.log "sending message to #{ c.peer }"
            c.send data

    listenForMessage: (connection) ->
        connection.on "data", (data) =>
            if data.type == "message"
                console.log "new message from #{ connection.peer }"

                messages = @state.messages
                messages.push data.message
                @setState messages: messages

Settings = React.createClass
    mixins: [React.addons.LinkedStateMixin]
