@@ -8,16 +8,16 @@ var sprintf = require('sprintf-js');
88var events = require ( 'events' ) ;
99var Session = ( function ( _super ) {
1010 __extends ( Session , _super ) ;
11- function Session ( args ) {
11+ function Session ( options ) {
1212 _super . call ( this ) ;
13- this . args = args ;
13+ this . options = options ;
1414 this . msgSent = false ;
1515 this . _isReset = false ;
1616 this . lastSendTime = new Date ( ) . getTime ( ) ;
1717 this . sendQueue = [ ] ;
18- this . dialogs = args . dialogs ;
19- if ( typeof this . args . minSendDelay !== 'number' ) {
20- this . args . minSendDelay = 1000 ;
18+ this . dialogs = options . dialogs ;
19+ if ( typeof this . options . minSendDelay !== 'number' ) {
20+ this . options . minSendDelay = 1000 ;
2121 }
2222 }
2323 Session . prototype . dispatch = function ( sessionState , message ) {
@@ -60,8 +60,8 @@ var Session = (function (_super) {
6060 } ;
6161 Session . prototype . ngettext = function ( msgid , msgid_plural , count ) {
6262 var tmpl ;
63- if ( this . args . localizer && this . message ) {
64- tmpl = this . args . localizer . ngettext ( this . message . language || '' , msgid , msgid_plural , count ) ;
63+ if ( this . options . localizer && this . message ) {
64+ tmpl = this . options . localizer . ngettext ( this . message . language || '' , msgid , msgid_plural , count ) ;
6565 }
6666 else if ( count == 1 ) {
6767 tmpl = msgid ;
@@ -127,6 +127,10 @@ var Session = (function (_super) {
127127 args [ _i - 1 ] = arguments [ _i ] ;
128128 }
129129 var ss = this . sessionState ;
130+ if ( ! ss || ! ss . callstack || ss . callstack . length == 0 ) {
131+ console . error ( 'ERROR: Too many calls to session.endDialog().' ) ;
132+ return this ;
133+ }
130134 var m ;
131135 var r = { } ;
132136 if ( result ) {
@@ -172,6 +176,10 @@ var Session = (function (_super) {
172176 Session . prototype . reset = function ( dialogId , dialogArgs ) {
173177 this . _isReset = true ;
174178 this . sessionState . callstack = [ ] ;
179+ if ( ! dialogId ) {
180+ dialogId = this . options . dialogId ;
181+ dialogArgs = dialogArgs || this . options . dialogArgs ;
182+ }
175183 this . beginDialog ( dialogId , dialogArgs ) ;
176184 return this ;
177185 } ;
@@ -191,7 +199,7 @@ var Session = (function (_super) {
191199 try {
192200 var ss = this . sessionState ;
193201 if ( ss . callstack . length == 0 ) {
194- this . beginDialog ( this . args . dialogId , this . args . dialogArgs ) ;
202+ this . beginDialog ( this . options . dialogId , this . options . dialogArgs ) ;
195203 }
196204 else if ( this . validateCallstack ( ) ) {
197205 var cur = ss . callstack [ ss . callstack . length - 1 ] ;
@@ -201,7 +209,7 @@ var Session = (function (_super) {
201209 }
202210 else {
203211 console . error ( 'Callstack is invalid, resetting session.' ) ;
204- this . reset ( this . args . dialogId , this . args . dialogArgs ) ;
212+ this . reset ( this . options . dialogId , this . options . dialogArgs ) ;
205213 }
206214 }
207215 catch ( e ) {
@@ -210,8 +218,8 @@ var Session = (function (_super) {
210218 } ;
211219 Session . prototype . vgettext = function ( msgid , args ) {
212220 var tmpl ;
213- if ( this . args . localizer && this . message ) {
214- tmpl = this . args . localizer . gettext ( this . message . language || '' , msgid ) ;
221+ if ( this . options . localizer && this . message ) {
222+ tmpl = this . options . localizer . gettext ( this . message . language || '' , msgid ) ;
215223 }
216224 else {
217225 tmpl = msgid ;
@@ -239,11 +247,11 @@ var Session = (function (_super) {
239247 if ( _this . sendQueue . length > 0 ) {
240248 delaySend ( ) ;
241249 }
242- } , _this . args . minSendDelay - ( now - _this . lastSendTime ) ) ;
250+ } , _this . options . minSendDelay - ( now - _this . lastSendTime ) ) ;
243251 } ;
244252 if ( this . sendQueue . length == 0 ) {
245253 this . msgSent = true ;
246- if ( ( now - this . lastSendTime ) >= this . args . minSendDelay ) {
254+ if ( ( now - this . lastSendTime ) >= this . options . minSendDelay ) {
247255 this . lastSendTime = now ;
248256 this . emit ( event , message ) ;
249257 }
0 commit comments