         currentComponent: Noop()
 
     componentWillMount: ->
-        @peer = new Peer key: PEER_KEY
+        @peer = new Peer key: PEER_KEY, debug: 2
+        @connections = []
+
+        otherPersonPeerId = getSegments()[1]
 
         @peer.on "open", (peerId) =>
             @peerId = peerId
 
-            otherPersonPeerId = getSegments()[1]
-
-            if otherPersonPeerId?
+            if not otherPersonPeerId?
+                @setState currentComponent: ChatDisconnected(peerId: @peerId)
+
+                @peer.on "connection", (connection) =>
+                    connection.on "error", (error) ->
+                        console.log error
+
+                    @connections.push connection
+
+                    connection.on "open", =>
+                        _.forEach @connections, (connection) =>
+                            blob =
+                                type: "connections"
+                                data: _.map @connections, (connection) -> connection.peer
+                            connection.send blob
+
+                        @setState currentComponent: ChatConnected(peerId: @peerId, connections: @connections)
+            else
                 connection = @peer.connect otherPersonPeerId
-                @onConnect()
-                @onClose connection
-
-                @setState currentComponent: ChatConnected(connection: connection)
-            else
-                @setState currentComponent: ChatDisconnected(peerId: @peerId)
-
-                @peer.on "connection", (connection) =>
-                    @onConnect()
-                    @onClose connection
-
-                    @setState currentComponent: ChatConnected(connection: connection)
+                connection.on "error", (error) ->
+                    console.log error
+
+                @connections.push connection
+
+                window.original_connection = connection
+
+                connection.on "open", =>
+
+                    connection.on "data", (blob) =>
+                        if blob.type == "connections"
+                            console.log @peerId
+                            peerIds = blob.data
+                            console.log peerIds
+                            peerIds = _.filter peerIds, (peerId) => peerId != @peerId
+                            console.log peerIds
+
+                            _.forEach peerIds, (peerId) =>
+                                connection = @peer.connect peerId
+                                connection.on "error", (error) ->
+                                    console.log error
+
+                                @connections.push connection
+
+                            @setState currentComponent: ChatConnected(peerId: @peerId, connections: @connections)
 
     componentDidMount: ->
         # TODO: This should be in `componentWillMount`.


        @props.addAlert type: "success", "Changes saved!"

routes = [
    ["/chat", Chat]
    [/chat\/[a-z0-9]+/, Chat]
    ["/settings", Settings]
]

navbarItems = [

    sendMessage: (message) ->
        @addMessage message

        _.forEach @props.connections, (connection) ->
            blob =
                type: "message"
                data: message
            connection.send blob


ChatDisconnected = React.createClass
