@@ -181,6 +181,7 @@ export class HttpSession implements Session {
181181 webio_session_id : string = 'NEW' ;
182182 debug = false ;
183183
184+ private _executed_command_msg_id = 0 ;
184185 private _closed = false ;
185186 private _session_create_callbacks : ( ( ) => void ) [ ] = [ ] ;
186187 private _session_close_callbacks : ( ( ) => void ) [ ] = [ ] ;
@@ -218,11 +219,11 @@ export class HttpSession implements Session {
218219 let that = this ;
219220 $ . ajax ( {
220221 type : "GET" ,
221- url : this . api_url ,
222+ url : ` ${ this . api_url } &ack= ${ this . _executed_command_msg_id } ` ,
222223 contentType : "application/json; charset=utf-8" ,
223224 dataType : "json" ,
224225 headers : { "webio-session-id" : this . webio_session_id } ,
225- success : function ( data : Command [ ] , textStatus : string , jqXHR : JQuery . jqXHR ) {
226+ success : function ( data : { commands : Command [ ] , seq : number } , textStatus : string , jqXHR : JQuery . jqXHR ) {
226227 safe_poprun_callbacks ( that . _session_create_callbacks , 'session_create_callback' ) ;
227228 that . _on_request_success ( data , textStatus , jqXHR ) ;
228229 } ,
@@ -232,11 +233,16 @@ export class HttpSession implements Session {
232233 } )
233234 }
234235
235- private _on_request_success ( data : Command [ ] , textStatus : string , jqXHR : JQuery . jqXHR ) {
236+ private _on_request_success ( data : { commands : Command [ ] , seq : number } , textStatus : string , jqXHR : JQuery . jqXHR ) {
237+ if ( data . seq == this . _executed_command_msg_id )
238+ return ;
239+ this . _executed_command_msg_id = data . seq ;
240+
236241 let sid = jqXHR . getResponseHeader ( 'webio-session-id' ) ;
237- if ( sid ) this . webio_session_id = sid ;
242+ if ( sid )
243+ this . webio_session_id = sid ;
238244
239- for ( let msg of data ) {
245+ for ( let msg of data . commands ) {
240246 if ( this . debug ) console . info ( '>>>' , msg ) ;
241247 this . _on_server_message ( msg ) ;
242248 }
@@ -267,7 +273,7 @@ export class HttpSession implements Session {
267273 $ . ajax ( {
268274 ...options ,
269275 type : "POST" ,
270- url : this . api_url ,
276+ url : ` ${ this . api_url } &ack= ${ this . _executed_command_msg_id } ` ,
271277 dataType : "json" ,
272278 headers : { "webio-session-id" : this . webio_session_id } ,
273279 success : this . _on_request_success . bind ( this ) ,
0 commit comments