 
                             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"
 
+                peer.on "connection", (connection) =>
+
+                    console.log "connection from #{ connection.peer }"
+
+                    connection.on "open", =>
+
+                        console.log "connection from #{ connection.peer } open"
+
+                        @connections.push connection
+
+                        @listenForMessage connection
+
                 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
+                    @connections.push connection
+
+                    @listenForMessage connection
 
                     connection.on "data", (data) =>
                         if data.type == "newConnection"

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

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


                                    @connections.push connection

                                    @listenForMessage connection

    render: ->
        (Dom.div null,
