2021-07-19 01:42:15 +00:00
|
|
|
|
$(function () {
|
|
|
|
|
|
2021-07-20 02:02:14 +00:00
|
|
|
|
let $liveModeLink = $('#live-mode-link');
|
|
|
|
|
let $liveModeStatus = $('#live-mode-status');
|
|
|
|
|
|
|
|
|
|
let isLive = false;
|
|
|
|
|
|
|
|
|
|
let isLiveMode = function () {
|
2021-07-20 02:54:16 +00:00
|
|
|
|
|
2021-07-20 02:02:14 +00:00
|
|
|
|
isLive = window.location.hash === '#live';
|
|
|
|
|
|
|
|
|
|
$liveModeLink
|
|
|
|
|
.toggleClass('btn-success text-white', isLive)
|
|
|
|
|
.attr('href', isLive ? '#' : '#live');
|
|
|
|
|
|
2021-07-20 03:43:01 +00:00
|
|
|
|
isLive ? $liveModeStatus.fadeIn() : $liveModeStatus.fadeOut();
|
2021-07-20 02:02:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isLiveMode();
|
|
|
|
|
|
|
|
|
|
$(window).on('hashchange', isLiveMode);
|
|
|
|
|
|
2021-07-19 01:42:15 +00:00
|
|
|
|
var connection = new signalR.HubConnectionBuilder().withUrl("/codeHub").build();
|
|
|
|
|
|
2021-07-20 03:43:01 +00:00
|
|
|
|
let isTeacher = window.location.hash === '#4ELQcUq7UnFGghAZCVr4Chr9JmtncigfkGu5WSf9';
|
|
|
|
|
|
2021-07-20 02:02:14 +00:00
|
|
|
|
if (isTeacher) {
|
|
|
|
|
//window.location.hash = '#';
|
|
|
|
|
$liveModeLink.hide();
|
|
|
|
|
$liveModeStatus.hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let $editors = $('.ace_editor');
|
|
|
|
|
|
|
|
|
|
if (isTeacher) {
|
|
|
|
|
|
|
|
|
|
$editors.each(function (i, e) {
|
2021-07-19 01:42:15 +00:00
|
|
|
|
|
2021-07-20 02:02:14 +00:00
|
|
|
|
let editor = ace.edit(e);
|
2021-07-19 01:42:15 +00:00
|
|
|
|
|
2021-07-20 02:02:14 +00:00
|
|
|
|
editor.session.on('change', function () {
|
2021-07-19 01:42:15 +00:00
|
|
|
|
|
2021-07-20 02:02:14 +00:00
|
|
|
|
let user = 'ryan';
|
|
|
|
|
let code = editor.getValue();
|
2021-07-19 01:42:15 +00:00
|
|
|
|
|
2021-07-20 02:02:14 +00:00
|
|
|
|
connection.invoke("UpdateCode", user, i, code).catch(function (err) {
|
|
|
|
|
return console.error(err.toString());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-07-19 01:42:15 +00:00
|
|
|
|
|
2021-07-20 02:02:14 +00:00
|
|
|
|
connection.on("ReceiveCode", function (user, index, code) {
|
2021-07-19 01:42:15 +00:00
|
|
|
|
|
2021-07-20 02:02:14 +00:00
|
|
|
|
if (!isTeacher && isLive) {
|
|
|
|
|
|
|
|
|
|
let editor = ace.edit($editors[index]);
|
|
|
|
|
|
|
|
|
|
editor.session.setValue(code);
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-07-19 01:42:15 +00:00
|
|
|
|
|
|
|
|
|
connection.start().then(function () {
|
|
|
|
|
//$('#send').prop('disabled', false);
|
|
|
|
|
}).catch(function (err) {
|
2021-07-19 01:24:08 +00:00
|
|
|
|
return console.error(err.toString());
|
|
|
|
|
});
|
|
|
|
|
});
|