@@ -38,6 +38,10 @@ module SocksToRTC {
3838
3939 /**
4040 * Start the Peer, based on the remote peer's info.
41+ * This will emit a socksToRtcSuccess signal when the peer connection is esablished,
42+ * or a socksToRtcFailure signal if there is an error openeing the peer connection.
43+ * TODO: update this to return a promise that fulfills/rejects, after freedom v0.5
44+ * is ready.
4145 */
4246 public start = ( remotePeer :PeerInfo ) => {
4347 this . reset ( ) ; // Begin with fresh components.
@@ -55,7 +59,17 @@ module SocksToRTC {
5559 // Messages received via signalling channel must reach the remote peer
5660 // through something other than the peerconnection. (e.g. XMPP)
5761 fCore . createChannel ( ) . then ( ( chan ) => {
58- this . transport_ . setup ( 'SocksToRtc-' + peerId , chan . identifier ) ;
62+ this . transport_ . setup ( 'SocksToRtc-' + peerId , chan . identifier ) . then (
63+ ( ) => {
64+ dbg ( 'SocksToRtc transport_.setup succeeded' ) ;
65+ freedom . emit ( 'socksToRtcSuccess' , remotePeer ) ;
66+ }
67+ ) . catch (
68+ ( e ) => {
69+ dbgErr ( 'SocksToRtc transport_.setup failed ' + e ) ;
70+ freedom . emit ( 'socksToRtcFailure' , remotePeer ) ;
71+ }
72+ ) ;
5973 this . signallingChannel_ = chan . channel ;
6074 this . signallingChannel_ . on ( 'message' , function ( msg ) {
6175 freedom . emit ( 'sendSignalToPeer' , {
@@ -64,6 +78,14 @@ module SocksToRTC {
6478 } ) ;
6579 } ) ;
6680 dbg ( 'signalling channel to SCTP peer connection ready.' ) ;
81+ // Send hello command to initiate communication, which will cause
82+ // the promise returned this.transport_.setup to fulfill.
83+ // TODO: remove hello command once freedom.transport.setup
84+ // is changed to automatically negotiate the connection.
85+ dbg ( 'sending hello command.' ) ;
86+ var command :Channel . Command = { type : Channel . COMMANDS . HELLO } ;
87+ this . transport_ . send ( 'control' , ArrayBuffers . stringToArrayBuffer (
88+ JSON . stringify ( command ) ) ) ;
6789 } ) ; // fCore.createChannel
6890
6991 // Create SOCKS server and start listening.
0 commit comments