Skip to content

Commit bade7d1

Browse files
committed
more tweaks
1 parent 45955b0 commit bade7d1

2 files changed

Lines changed: 36 additions & 15 deletions

File tree

‎v3/js/opt-frontend-common.js‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ function setCodeMirrorVal(dat) {
7474
}
7575

7676

77+
// From: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
78+
function guid() {
79+
function s4() {
80+
return Math.floor((1 + Math.random()) * 0x10000)
81+
.toString(16)
82+
.substring(1);
83+
}
84+
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
85+
s4() + '-' + s4() + s4() + s4();
86+
}
87+
88+
7789
var myVisualizer = null; // singleton ExecutionVisualizer instance
7890
var visualizedAppState = null; // parameters necessary to generate myVisualizer
7991

@@ -304,8 +316,9 @@ function executePythonCode(pythonSourceCode,
304316
}
305317

306318
// set some nasty global state that represents the current
307-
// code that's being visualized at the moment
308-
visualizedAppState = getAppState(); // TODO: add UUID
319+
// code that's being visualized at the moment, so that we
320+
// can sync its state with other viewers via TogetherJS
321+
visualizedAppState = getAppState();
309322
visualizedAppState.visualizedAppState = null; // prevent chaining
310323

311324
handleSuccessFunc();

‎v3/js/opt-frontend.js‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
94101
function 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

Comments
 (0)