@@ -27,8 +27,13 @@ export class RTSPStream {
2727 this . track = null ;
2828 }
2929
30- start ( ) {
31- return this . sendSetup ( ) ; //.then(this.sendPlay.bind(this));
30+ start ( lastSetupPromise = null ) {
31+ if ( lastSetupPromise != null ) {
32+ // if a setup was already made, use the same session
33+ return lastSetupPromise . then ( ( obj ) => this . sendSetup ( obj . session ) )
34+ } else {
35+ return this . sendSetup ( ) ;
36+ }
3237 }
3338
3439 stop ( ) {
@@ -102,14 +107,18 @@ export class RTSPStream {
102107 return this . client . sendRequest ( _cmd , this . getControlURL ( ) , params ) ;
103108 }
104109
105- sendSetup ( ) {
110+ sendSetup ( session = null ) {
106111 this . state = RTSPClient . STATE_SETUP ;
107112 this . rtpChannel = this . client . interleaveChannelIndex ;
108113 let interleavedChannels = this . client . interleaveChannelIndex ++ + "-" + this . client . interleaveChannelIndex ++ ;
109- return this . client . sendRequest ( 'SETUP' , this . getSetupURL ( this . track ) , {
114+ let params = {
110115 'Transport' : `RTP/AVP/TCP;unicast;interleaved=${ interleavedChannels } ` ,
111116 'Date' : new Date ( ) . toUTCString ( )
112- } ) . then ( ( _data ) => {
117+ } ;
118+ if ( session ) {
119+ params . Session = session ;
120+ }
121+ return this . client . sendRequest ( 'SETUP' , this . getSetupURL ( this . track ) , params ) . then ( ( _data ) => {
113122 this . session = _data . headers [ 'session' ] ;
114123 let transport = _data . headers [ 'transport' ] ;
115124 if ( transport ) {
@@ -122,7 +131,7 @@ export class RTSPStream {
122131 let sessionParams = { } ;
123132 for ( let chunk of sessionParamsChunks ) {
124133 let kv = chunk . split ( '=' ) ;
125- sessionParams [ kv [ 0 ] ] = kv [ 1 ] ;
134+ sessionParams [ kv [ 0 ] ] = kv [ 1 ] ;
126135 }
127136 if ( sessionParams [ 'timeout' ] ) {
128137 this . keepaliveInterval = Number ( sessionParams [ 'timeout' ] ) * 500 ; // * 1000 / 2
@@ -133,7 +142,7 @@ export class RTSPStream {
133142 }*/
134143 this . client . useRTPChannel ( this . rtpChannel ) ;
135144 this . startKeepAlive ( ) ;
136- return { track : this . track , data : _data } ;
145+ return { track : this . track , data : _data , session : this . session } ;
137146 } ) ;
138147 }
139148}
0 commit comments