@@ -63,13 +63,7 @@ var TogetherJSConfig_toolName = "Online Python Tutor live help";
6363//var TogetherJSConfig_hubBase = "http://184.173.101.176:30035/"; // online
6464var TogetherJSConfig_hubBase = "http://localhost:30035/" ; // local
6565
66- // TODO: generalize beyond tutor to "joiner" or something, since we
67- // can imagine other learners joining into the original session as well
68- var isTutor = false ;
69-
70- var manualSharedSession = false ; // XXX: this is uber-unreliable since
71- // it's not set on page reload unless
72- // there's a special url hash
66+ var tutorRequested = false ;
7367
7468var helpQueueSize = 0 ;
7569var tutorAvailable = false ;
@@ -85,7 +79,7 @@ var tutorAvailable = false;
8579var origDocURL = document . URL ; // capture this ASAP before TogetherJS munges the URL
8680
8781var tutorWaitText = 'Please wait for the next available tutor.' ;
88- var informedConsentText = '<p >During shared sessions, chat logs and code may be recorded and published for<br/>educational purposes. Do not reveal any private or confidential information.</p >' ;
82+ var informedConsentText = '<div style="color: #666;" >During shared sessions, chat logs and code may be recorded and published for<br/>educational purposes. Do not reveal any private or confidential information.</div >' ;
8983
9084// nasty globals
9185var updateOutputSignalFromRemote = false ;
@@ -128,35 +122,14 @@ function syncAppState(appState) {
128122 }
129123}
130124
131- /*
132- var TogetherJSConfig_getUserName = function() {
133- if (isTutor) {
134- return 'Tutor';
135- }
136- else {
137- return 'Learner';
138- }
139- }
140- */
141-
142-
143- function getTutor ( ) {
144- manualSharedSession = false ; // icky global!
145-
146- $ ( "#togetherjsStatus" ) . html ( '<div style="font-size: 11pt;">Please wait for the next available tutor. <span id="helpQueueText"></span></div>' ) ;
147125
126+ function requestTutor ( ) {
127+ tutorRequested = true ;
148128 TogetherJS ( ) ;
149129}
150130
151131function startSharedSession ( ) {
152- manualSharedSession = true ; // icky global!
153-
154- $ ( "#togetherjsStatus" ) . html ( '<div style="font-size: 11pt;">\
155- Copy and send this URL to let others join your session:\
156- </div>\
157- <input type="text" style="font-size:\
158- 12pt; font-weight: bold; padding: 5px;" id="togetherjsURL"\
159- size="80" readonly="readonly"/>' ) ;
132+ tutorRequested = false ;
160133 TogetherJS ( ) ;
161134}
162135
@@ -165,24 +138,13 @@ function setHelpQueueSizeLabel() {
165138 $ ( "#helpQueueText" ) . html ( 'There is 1 person in line.' ) ;
166139 }
167140 else if ( helpQueueSize == 0 || helpQueueSize > 1 ) {
168- $ ( "#helpQueueText" ) . html ( 'There are ' + dat . helpQueueUrls + ' people in line.' ) ;
141+ $ ( "#helpQueueText" ) . html ( 'There are ' + helpQueueSize + ' people in line.' ) ;
169142 }
170143}
171144
172145
173146// get this app ready for TogetherJS
174147function initTogetherJS ( ) {
175- if ( isTutor ) {
176- $ ( "#getTutorBtn" ) . html ( "TUTOR - Join live help session" ) ;
177- /*
178- $("#togetherJSHeader").append('<button id="syncBtn"\
179- type="button">Sync with learner</button>');
180- $("#syncBtn").click(requestSync);
181- */
182-
183- $ ( "#sharedSessionBtn" ) . hide ( ) ;
184- }
185-
186148 // This event triggers when you first join a session and say 'hello',
187149 // and then one of your peers says hello back to you. If they have the
188150 // exact same name as you, then change your own name to avoid ambiguity.
@@ -328,14 +290,7 @@ function initTogetherJS() {
328290 } , 1000 ) ;
329291 } ) ;
330292
331- // learner receives a sync request from tutor and responds by
332- // sending its current app state
333293 TogetherJS . hub . on ( "requestSync" , function ( msg ) {
334- // only a learner should receive sync requests from a tutor
335- if ( isTutor ) {
336- return ;
337- }
338-
339294 if ( TogetherJS . running ) {
340295 TogetherJS . send ( { type : "myAppState" ,
341296 myAppState : getAppState ( ) ,
@@ -346,17 +301,7 @@ function initTogetherJS() {
346301 }
347302 } ) ;
348303
349- // tutor receives an app state from a learner, either using a regular
350- // myAppState or an initialAppState signal, which occurs when the
351- // learner, say, REFRESHES THE PAGE!!!
352- // TODO: what happens if more than one learner sends state to tutor?
353- // i suppose the last one wins at this point :/
354- TogetherJS . hub . on ( "myAppState initialAppState" , function ( msg ) {
355- // only a tutor should handle receiving an app state from a learner
356- if ( ! isTutor ) {
357- return ;
358- }
359-
304+ TogetherJS . hub . on ( "myAppState" , function ( msg ) {
360305 var learnerAppState = msg . myAppState ;
361306
362307 if ( learnerAppState . mode == 'display' ) {
@@ -439,12 +384,11 @@ function initTogetherJS() {
439384 } ;
440385 }
441386 catch ( err ) {
442- // ugh, SSE doesn't work in Safari when testing on localhost,
443- // but I think it works when deployed on pythontutor.com (maybe?)
387+ // ugh, SSE doesn't seem to work in Safari
444388 console . warn ( "Sad ... EventSource not supported :(" ) ;
445389 }
446390
447- $ ( "#getTutorBtn" ) . click ( getTutor ) ;
391+ $ ( "#getTutorBtn" ) . click ( requestTutor ) ;
448392 $ ( "#sharedSessionBtn" ) . click ( startSharedSession ) ;
449393 $ ( "#stopTogetherJSBtn" ) . click ( TogetherJS ) ; // toggles off
450394
@@ -456,32 +400,36 @@ function initTogetherJS() {
456400 $ ( "#surveyHeader" ) . hide ( ) ;
457401 $ ( "#stopTogetherJSBtn" ) . show ( ) ;
458402
459- $ ( "#togetherjsStatus" ) . append ( informedConsentText ) . fadeIn ( 500 ) ;
403+ // without anything after the '#' in the hash
404+ var cleanUrl = $ . param . fragment ( location . href , { } , 2 /* override */ ) ;
405+ var urlToShare = cleanUrl + 'togetherjs=' + TogetherJS . shareId ( ) ;
406+
407+ requestSync ( ) ; // immediately try to sync upon startup so that if
408+ // others are already in the session, we will be
409+ // synced up. and if nobody is here, then this is a NOP.
460410
461- if ( isTutor ) {
462- $ ( "#togetherjsStatus" ) . html ( origDocURL ) ;
463- // if you're a tutor, immediately try to sync to the learner upon startup
464- requestSync ( ) ;
411+ if ( tutorRequested ) {
412+ $ . get ( TogetherJSConfig_hubBase + 'request-help' ,
413+ { url : TogetherJS . shareUrl ( ) , id : TogetherJS . shareId ( ) } ,
414+ null /* don't use a callback; rely on SSE */ ) ;
415+
416+ $ ( "#togetherjsStatus" ) . html ( '<div style="font-size: 11pt; margin-bottom: 5pt;">\
417+ Please wait for the next available tutor. \
418+ <span id="helpQueueText"></span></div>' ) ;
419+ setHelpQueueSizeLabel ( ) ; // run after creating span#helpQueueText
465420 }
466421 else {
467- if ( manualSharedSession ) {
468- // without anything after the '#' in the hash
469- var cleanUrl = $ . param . fragment ( location . href , { } , 2 /* override */ ) ;
470- var urlToShare = cleanUrl + 'togetherjs=' + TogetherJS . shareId ( ) ;
471- $ ( "#togetherjsURL" ) . val ( urlToShare ) . attr ( 'size' , urlToShare . length + 15 ) ;
472- }
473- else {
474- // if you're a learner, request help when TogetherJS is activated
475- $ . get ( TogetherJSConfig_hubBase + 'request-help' ,
476- { url : TogetherJS . shareUrl ( ) , id : TogetherJS . shareId ( ) } ,
477- null /* don't use a callback; rely on SSE */ ) ;
478- }
479-
480- // also log the learner's initial state when they first requested help
481- TogetherJS . send ( { type : "initialAppState" , myAppState : getAppState ( ) } ) ;
422+ $ ( "#togetherjsStatus" ) . html ( '<div>\
423+ Copy and send this URL to let others join your session:\
424+ </div>\
425+ <input type="text" style="font-size: 12pt; \
426+ font-weight: bold; padding: 5px;\
427+ margin-bottom: 10pt;" \
428+ id="togetherjsURL" size="80" readonly="readonly"/>' ) ;
429+ $ ( "#togetherjsURL" ) . val ( urlToShare ) . attr ( 'size' , urlToShare . length + 15 ) ;
482430 }
483431
484- setHelpQueueSizeLabel ( ) ;
432+ $ ( "#togetherjsStatus" ) . append ( informedConsentText ) . fadeIn ( 500 ) ;
485433 } ) ;
486434
487435 // emitted when TogetherJS is closed. This is not emitted when the
@@ -614,12 +562,7 @@ function optFinishSuccessfulExecution() {
614562$ ( document ) . ready ( function ( ) {
615563 setSurveyHTML ( ) ;
616564
617- var role = $ . bbq . getState ( 'role' ) ;
618- isTutor = ( role == 'tutor' ) ; // GLOBAL
619-
620- manualSharedSession = ( $ . bbq . getState ( 'share' ) == 'manual' ) ; // GLOBAL
621-
622- if ( enableTogetherJS || isTutor ) {
565+ if ( enableTogetherJS ) {
623566 initTogetherJS ( ) ;
624567 }
625568
@@ -972,18 +915,6 @@ $(document).ready(function() {
972915
973916 genericOptFrontendReady ( ) ; // initialize at the end
974917
975- // if blank, then select a canned example on start-up
976- // (need to do this after pyInputCodeMirror is initialized)
977- // TODO: generalize beyond tutor to "joiner" or something, since we
978- // can imagine other learners joining into the original session as well
979- if ( ! isTutor ) { // don't pre-seed since things will go screwy when the
980- // input box automatically syncs
981- if ( ! pyInputCodeMirror . getValue ( ) ) {
982- $ ( "#aliasExampleLink" ) . trigger ( 'click' ) ;
983- }
984- }
985-
986-
987918 pyInputCodeMirror . on ( "change" , function ( cm , change ) {
988919 // only trigger when the user explicitly typed something
989920 if ( change . origin != 'setValue' ) {
0 commit comments