File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ var MAX_BYTES_IN_FLIGHT = 600;
1818
1919function MessageQueue ( ) {
2020 this . queue = [ ] ;
21+ this . log = null ;
2122 this . messagesInFlight = 0 ;
2223 this . bytesInFlight = 0 ;
2324}
@@ -44,7 +45,22 @@ function countBytes(message) {
4445 return bytes ;
4546}
4647
48+ MessageQueue . prototype . startLogging = function ( ) {
49+ this . log = [ ] ;
50+ } ;
51+
52+ MessageQueue . prototype . stopLogging = function ( ) {
53+ this . log = null ;
54+ }
55+
56+ MessageQueue . prototype . getLog = function ( ) {
57+ return this . log || [ ] ;
58+ }
59+
4760MessageQueue . prototype . enqueue = function ( message ) {
61+ if ( this . log ) {
62+ this . log . push ( message ) ;
63+ }
4864 this . queue . push ( message ) ;
4965 if ( this . messagesInFlight < 10 && this . bytesInFlight < MAX_BYTES_IN_FLIGHT ) {
5066 console . log ( 'sending immediately, messages in flight: ' + this . messagesInFlight + ', bytes in flight: ' + this . bytesInFlight ) ;
Original file line number Diff line number Diff line change 1414 * limitations under the License.
1515 */
1616
17+ var LOGGING_ENABLED = false ;
18+
1719var location = require ( './location' ) ;
1820var config = require ( './config' ) ;
1921var actions = require ( './actions' ) ;
@@ -35,6 +37,9 @@ function getSettings() {
3537}
3638
3739Session . prototype . run = function ( ) {
40+ if ( LOGGING_ENABLED ) {
41+ messageQueue . startLogging ( ) ;
42+ }
3843 console . log ( "Opening websocket connection..." ) ;
3944 var url = API_URL + '?prompt=' + encodeURIComponent ( this . prompt ) + '&token=' + exports . userToken ;
4045 if ( location . isReady ( ) && config . isLocationEnabled ( ) ) {
@@ -151,6 +156,10 @@ Session.prototype.handleMessage = function(event) {
151156 this . enqueue ( {
152157 CHAT_DONE : true
153158 } ) ;
159+ if ( LOGGING_ENABLED ) {
160+ console . log ( JSON . stringify ( messageQueue . getLog ( ) ) ) ;
161+ messageQueue . stopLogging ( ) ;
162+ }
154163 } else if ( message [ 0 ] == 'a' ) {
155164 actions . handleAction ( this , this . ws , message . substring ( 1 ) ) ;
156165 } else if ( message [ 0 ] == 't' ) {
You can’t perform that action at this time.
0 commit comments