Skip to content

Commit 1d00345

Browse files
committed
massive refactoring of TogetherJS support, MASSIVE!!!
1 parent 429674c commit 1d00345

6 files changed

Lines changed: 217 additions & 332 deletions

File tree

‎v3/js/opt-frontend.js‎

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4544
var TogetherJSConfig_disableWebRTC = true;
4645
var TogetherJSConfig_suppressJoinConfirmation = true;
@@ -54,7 +53,8 @@ var TogetherJSConfig_suppressInvite = true;
5453
var 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

5959
var TogetherJSConfig_siteName = "Online Python Tutor live help";
6060
var 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
7781
var updateOutputSignalFromRemote = false;
82+
var executeCodeSignalFromRemote = false;
7883

7984
// Global hook for ExecutionVisualizer.
8085
var 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
346378
function 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

‎v3/js/togetherjs/togetherjs-min.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,16 @@
751751
return session.shareUrl();
752752
};
753753

754+
// pgbovine - added
755+
TogetherJS.shareId = function () {
756+
if (! TogetherJS.require) {
757+
return null;
758+
}
759+
var session = TogetherJS.require("session");
760+
assert(session.shareId, "Attempted to access shareId before it is set");
761+
return session.shareId;
762+
};
763+
754764
var listener = null;
755765

756766
TogetherJS.listenForShortcut = function () {

‎v3/js/togetherjs/togetherjs.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,16 @@
751751
return session.shareUrl();
752752
};
753753

754+
// pgbovine - added
755+
TogetherJS.shareId = function () {
756+
if (! TogetherJS.require) {
757+
return null;
758+
}
759+
var session = TogetherJS.require("session");
760+
assert(session.shareId, "Attempted to access shareId before it is set");
761+
return session.shareId;
762+
};
763+
754764
var listener = null;
755765

756766
TogetherJS.listenForShortcut = function () {

‎v3/opt_togetherjs/admin.html‎

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,39 @@
2222

2323
var linkURL = dat.url + '&role=tutor';
2424

25-
d.html(dat.timestr + ' ' + dat.ip +
26-
' <a href="' + linkURL + '" target="_blank">' + linkURL + '</a> ' +
27-
'<button type="button" class="eraseBtn">Erase</button>');
28-
29-
d.find('button.eraseBtn').click(function() {
30-
console.log("Erase", dat.id);
31-
32-
$.get('/remove-help-queue-element', {id: dat.id}, function(ret) {
33-
if (ret == "success") {
34-
d.remove();
35-
document.title = "(" + $("div.entry").length + ") OPT live help admin panel";
36-
}
37-
else {
38-
alert("Unknown error :(");
39-
}
40-
});
41-
});
25+
26+
function removeHelpQueueElt(reason) {
27+
var p = confirm("Confirm remove " + dat.id + " for " + reason);
28+
if (!p) {
29+
return;
30+
}
31+
$.get('/remove-help-queue-element',
32+
{id: dat.id, reason: reason},
33+
function(ret) {
34+
if (ret == "success") {
35+
d.remove();
36+
document.title = "(" + $("div.entry").length +
37+
") OPT live help admin panel";
38+
}
39+
else {
40+
alert("Unknown error :(");
41+
}
42+
});
43+
}
44+
45+
d.html('<button type="button" id="eraseBtnNoShow">No-show</button>' +
46+
'<button type="button" id="eraseBtnFled">Fled</button>' +
47+
'<button type="button" id="eraseBtnSuccess">Success</button>' +
48+
'<button type="button" id="eraseBtnFail">Fail</button>' +
49+
'<button type="button" id="eraseBtnGeneric">(No reason)</button>' +
50+
' ' + dat.date + ' <a href="' + linkURL + '" target="_blank">' +
51+
linkURL + '</a>');
52+
53+
d.find('button#eraseBtnNoShow').click(function() {removeHelpQueueElt('no-show')});
54+
d.find('button#eraseBtnFled').click(function() {removeHelpQueueElt('learner-fled')});
55+
d.find('button#eraseBtnSuccess').click(function() {removeHelpQueueElt('tutoring-success')});
56+
d.find('button#eraseBtnFail').click(function() {removeHelpQueueElt('tutoring-fail')});
57+
d.find('button#eraseBtnGeneric').click(function() {removeHelpQueueElt()});
4258
}
4359

4460
$(document).ready(function() {
@@ -60,7 +76,7 @@
6076
appendDiv(e);
6177
});
6278
}
63-
else if (dat.type == 'ha') {
79+
else if (dat.type == 'help-available') {
6480
setBtnLabel(dat);
6581
}
6682
else if (dat.type == 'new-help-request') {

0 commit comments

Comments
 (0)