@@ -90,6 +90,13 @@ var try_hook = function(hook_name, args) {
9090}
9191
9292
93+ function requestSync ( ) {
94+ if ( enableTogetherJS && TogetherJS . running ) {
95+ nowSyncing = true ;
96+ TogetherJS . send ( { type : "requestSync" } ) ;
97+ }
98+ }
99+
93100// get this app ready for TogetherJS
94101function initTogetherJS ( ) {
95102 $ ( "#surveyHeader" ) . remove ( ) ; // kill this to save space
@@ -99,17 +106,9 @@ function initTogetherJS() {
99106 $ ( "#togetherJSHeader" ) . append ( '<button id="syncBtn"\
100107 type="button">Sync with learner</button>' ) ;
101108
102- $ ( "#syncBtn" ) . click ( function ( ) {
103- console . log ( "Sync!" ) ;
104-
105- if ( TogetherJS . running ) {
106- nowSyncing = true ;
107- TogetherJS . send ( { type : "requestSync" } ) ;
108- }
109- } ) ;
109+ $ ( "#syncBtn" ) . click ( requestSync ) ;
110110 }
111111
112-
113112 // Global hook for ExecutionVisualizer.
114113 // Set it here after TogetherJS gets defined, hopefully!
115114 try_hook = function ( hook_name , args ) {
@@ -209,11 +208,11 @@ function initTogetherJS() {
209208 var dat = JSON . parse ( e . data ) ;
210209
211210 if ( dat . helpQueueUrls == 1 ) {
212- $ ( "#helpQueueUrls" ) . html ( 'There is 1 person waiting in the queue.' ) ;
211+ $ ( "#helpQueueUrls" ) . html ( 'Please wait ... there is now 1 person in the queue.' ) ;
213212 }
214213 else if ( dat . helpQueueUrls == 0 || dat . helpQueueUrls > 1 ) {
215- $ ( "#helpQueueUrls" ) . html ( 'There are ' + dat . helpQueueUrls +
216- ' people waiting in the queue.' ) ;
214+ $ ( "#helpQueueUrls" ) . html ( 'Please wait ... there are now ' + dat . helpQueueUrls +
215+ ' people in the queue.' ) ;
217216 }
218217 else {
219218 $ ( "#helpQueueUrls" ) . html ( '' ) ;
@@ -247,9 +246,16 @@ function initTogetherJS() {
247246 console . log ( "TogetherJS ready" ) ;
248247 $ ( "#togetherBtn" ) . html ( "Stop live help session" ) ;
249248
249+ $ ( "#helpQueueUrls" ) . fadeIn ( 500 ) ;
250+
250251 $ ( "#togetherJSHeader" ) . fadeIn ( 750 , redrawConnectors ) ; // always show when ready
251252
252- if ( ! isTutor ) {
253+ if ( isTutor ) {
254+ // if you're a tutor, immediately try to sync to the learner upon startup
255+ requestSync ( ) ;
256+ }
257+ else {
258+ // if you're a learner, request help when TogetherJS is activated
253259 $ . get ( "http://togetherjs.pythontutor.com/request-help" ,
254260 { url : TogetherJS . shareUrl ( ) } ,
255261 null /* don't use a callback; rely on SSE */ ) ;
@@ -262,6 +268,8 @@ function initTogetherJS() {
262268 TogetherJS . on ( "close" , function ( ) {
263269 console . log ( "TogetherJS close" ) ;
264270
271+ $ ( "#helpQueueUrls" ) . fadeOut ( 500 ) ;
272+
265273 if ( isTutor ) {
266274 $ ( "#togetherBtn" ) . html ( "TUTOR - Join live help session" ) ;
267275 }
0 commit comments