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


                                    @connections.push connection

                                    connection.on "data", (data) =>
                                        console.log "RECEIVED MESSAGE FROM NEW PEER"
                                        if data.type == "message"
                                            messages = @state.messages
                                            messages.push data.message
                                            @setState messages: messages

    render: ->
        (Dom.div null,

        _.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]
