@@ -39,8 +39,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3939// should all be imported BEFORE this file
4040
4141
42- // EXPERIMENTAL
43- var enableTogetherJS = true ;
42+ var enableTogetherJS = true ; // EXPERIMENTAL
4443
4544var TogetherJSConfig_disableWebRTC = true ;
4645var TogetherJSConfig_suppressJoinConfirmation = true ;
@@ -54,7 +53,8 @@ var TogetherJSConfig_suppressInvite = true;
5453var TogetherJSConfig_suppressJoinConfirmation = true ;
5554
5655// clone clicks ONLY in certain elements to keep things simple:
57- var TogetherJSConfig_cloneClicks = '#pyInputPane select,#pyInputPane #executeBtn' ;
56+ //var TogetherJSConfig_cloneClicks = '#pyInputPane select,#pyInputPane #executeBtn';
57+ var TogetherJSConfig_cloneClicks = '#pyInputPane select' ;
5858
5959var TogetherJSConfig_siteName = "Online Python Tutor live help" ;
6060var TogetherJSConfig_toolName = "Online Python Tutor live help" ;
@@ -72,9 +72,14 @@ var isTutor = false;
7272//TogetherJSConfig_callToStart = function (callback) {
7373//};
7474
75+ var origDocURL = document . URL ; // capture this ASAP before TogetherJS munges the URL
76+
77+ var tutorWaitText = 'Please wait for the next available tutor.' ;
78+ var informedConsentText = '<br/>During the tutoring session, chat logs and code may be recorded for research purposes.' ;
7579
7680// nasty globals
7781var updateOutputSignalFromRemote = false ;
82+ var executeCodeSignalFromRemote = false ;
7883
7984// Global hook for ExecutionVisualizer.
8085var try_hook = function ( hook_name , args ) {
@@ -116,7 +121,6 @@ function initTogetherJS() {
116121 if ( ! msg . sameUrl ) {
117122 return ;
118123 }
119-
120124 if ( isExecutingCode ) {
121125 return ;
122126 }
@@ -133,11 +137,28 @@ function initTogetherJS() {
133137 }
134138 } ) ;
135139
136- TogetherJS . hub . on ( "hashchange " , function ( msg ) {
140+ TogetherJS . hub . on ( "executeCode " , function ( msg ) {
137141 if ( ! msg . sameUrl ) {
138142 return ;
139143 }
144+ if ( isExecutingCode ) {
145+ return ;
146+ }
140147
148+ executeCodeSignalFromRemote = true ;
149+ try {
150+ executeCodeFromScratch ( ) ;
151+ }
152+ finally {
153+ executeCodeSignalFromRemote = false ;
154+ }
155+
156+ } ) ;
157+
158+ TogetherJS . hub . on ( "hashchange" , function ( msg ) {
159+ if ( ! msg . sameUrl ) {
160+ return ;
161+ }
141162 if ( isExecutingCode ) {
142163 return ;
143164 }
@@ -197,15 +218,21 @@ function initTogetherJS() {
197218 source . onmessage = function ( e ) {
198219 var dat = JSON . parse ( e . data ) ;
199220
200- if ( dat . helpQueueUrls == 1 ) {
201- $ ( "#helpQueueUrls" ) . html ( 'Please wait ... there is now 1 person in the queue.' ) ;
202- }
203- else if ( dat . helpQueueUrls == 0 || dat . helpQueueUrls > 1 ) {
204- $ ( "#helpQueueUrls" ) . html ( 'Please wait ... there are now ' + dat . helpQueueUrls +
205- ' people in the queue.' ) ;
206- }
207- else {
208- $ ( "#helpQueueUrls" ) . html ( '' ) ;
221+ if ( ! isTutor ) {
222+ if ( dat . helpQueueUrls == 1 ) {
223+ $ ( "#helpQueueUrls" ) . html ( tutorWaitText +
224+ ' There is 1 person in line.' +
225+ informedConsentText ) ;
226+ }
227+ else if ( dat . helpQueueUrls == 0 || dat . helpQueueUrls > 1 ) {
228+ $ ( "#helpQueueUrls" ) . html ( tutorWaitText +
229+ ' There are ' + dat . helpQueueUrls +
230+ ' people in line.' +
231+ informedConsentText ) ;
232+ }
233+ else {
234+ $ ( "#helpQueueUrls" ) . html ( '' ) ;
235+ }
209236 }
210237
211238 if ( dat . helpAvailable ) {
@@ -242,14 +269,18 @@ function initTogetherJS() {
242269 $ ( "#togetherJSHeader" ) . fadeIn ( 750 , redrawConnectors ) ; // always show when ready
243270
244271 if ( isTutor ) {
272+ $ ( "#helpQueueUrls" ) . html ( origDocURL ) ;
245273 // if you're a tutor, immediately try to sync to the learner upon startup
246274 requestSync ( ) ;
247275 }
248276 else {
249277 // if you're a learner, request help when TogetherJS is activated
250278 $ . get ( TogetherJSConfig_hubBase + 'request-help' ,
251- { url : TogetherJS . shareUrl ( ) } ,
279+ { url : TogetherJS . shareUrl ( ) , id : TogetherJS . shareId ( ) } ,
252280 null /* don't use a callback; rely on SSE */ ) ;
281+
282+ // also log the learner's initial state when they first requested help
283+ TogetherJS . send ( { type : "initialAppState" , myAppState : getAppState ( ) } ) ;
253284 }
254285 } ) ;
255286
@@ -343,13 +374,18 @@ function executeCode(forceStartingInstr) {
343374 enterDisplayMode , handleUncaughtExceptionFunc ) ;
344375}
345376
377+ // side effect: fires a TogetherJS signal if enabled
346378function executeCodeFromScratch ( ) {
347379 // don't execute empty string:
348380 if ( $ . trim ( pyInputCodeMirror . getValue ( ) ) == '' ) {
349381 alert ( 'Type in some code to visualize.' ) ;
350382 return ;
351383 }
352384
385+ if ( TogetherJS . running && ! executeCodeSignalFromRemote ) {
386+ TogetherJS . send ( { type : "executeCode" , myAppState : getAppState ( ) } ) ;
387+ }
388+
353389 // reset these globals
354390 rawInputLst = [ ] ;
355391 executeCode ( ) ;
@@ -396,7 +432,9 @@ $(document).ready(function() {
396432 updateAppDisplay ( newMode ) ;
397433
398434 if ( TogetherJS . running && ! isExecutingCode ) {
399- TogetherJS . send ( { type : "hashchange" , appMode : appMode } ) ;
435+ TogetherJS . send ( { type : "hashchange" ,
436+ appMode : appMode ,
437+ myAppState : getAppState ( ) } ) ;
400438 }
401439 } ) ;
402440
0 commit comments