@@ -27,38 +27,44 @@ ShellSocketManager.prototype.handleStream = function(stream, shellId, opts) {
2727 ) ;
2828
2929 // Initialize
30- shell
31- . init ( )
32- . then ( function ( shell ) {
33- // Shell is ready
34- } ) ;
35- return stream ;
30+ return shell . init ( ) ;
3631} ;
3732
3833
3934function setup ( options , imports , register ) {
4035 // Import
41- var shellManager = imports . shells ;
36+ var shells = imports . shells ;
4237 var io = imports . socket_io . io ;
4338 var events = imports . events ;
4439 var shells_rpc = imports . shells_rpc ;
4540
46- var socketManager = new ShellSocketManager ( shellManager ) ;
41+ var socketManager = new ShellSocketManager ( shells ) ;
42+
43+ events . on ( 'shell.spawn' , function ( data ) {
44+ return shells . shells [ data . shellId ] . ps . pause ( ) ;
45+ } ) ;
46+
47+ events . on ( 'shell.open' , function ( data ) {
48+ shells . shells [ data . shellId ] . ps . resume ( ) ;
49+ } ) ;
4750
4851 // Construct
4952 io . of ( '/stream/shells' ) . on ( 'connection' , function ( socket ) {
5053 ss ( socket ) . on ( 'shell.open' , function ( stream , data ) {
51- events . emit ( 'shell.open' , {
52- 'shellId' : data . shellId
53- } ) ;
54-
5554 // Default options
5655 data . opts = _ . defaults ( data . opts , {
5756 'arguments' : [ ]
5857 } ) ;
5958
60- // Open up shell
61- socketManager . handleStream ( stream , data . shellId , data . opts ) ;
59+ // Connect stream to socket.io
60+ // then resume shell's stream
61+ return socketManager . handleStream ( stream , data . shellId , data . opts )
62+ . then ( function ( shell ) {
63+ // Stream is now hooked up
64+ events . emit ( 'shell.open' , {
65+ 'shellId' : data . shellId
66+ } ) ;
67+ } ) ;
6268 } ) ;
6369
6470 socket . on ( 'shell.destroy' , function ( data ) {
0 commit comments