Skip to content

Commit

Permalink
Mocking up how to send processed with connections
Browse files Browse the repository at this point in the history
The idea being: if there's a viewer, then send the processed CSS up to a /spike end point (that is then propergated to connected viewers through the spike).

Obviously! Needs careful testing...maybe even some *real* tests?!?!?!?!?!?!?!?!
  • Loading branch information
remy committed Jul 17, 2014
1 parent d81027f commit 817ebe1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions public/js/chrome/infocard.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
function updateStats(event, _data) {
var data = _data ? JSON.parse(_data) : JSON.parse(event.data);

jsbin.state.connections = data.connections;

if (data.connections > 0 && viewers === 0) {
$template.addClass('viewers');
}
Expand Down
12 changes: 11 additions & 1 deletion public/js/render/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ var getRenderedCode = function () {

function render(language) {
return new RSVP.Promise(function (resolve, reject) {
editors[language].render().then(resolve, function (error) {
editors[language].render().then(function (data) {
if (jsbin.state.connections > 0 && language === 'css' && editors[language].processor.id !== 'css') {
$.ajax({
method: 'post',
url: jsbin.getURL({ withRevision: true }) + '/spike',
data: data,
language: editors[language].processor.id
});
}
return data;
}, function (error) {
console.warn(editors[language].processor.id + ' processor compilation failed');
if (!error) {
error = {};
Expand Down
10 changes: 7 additions & 3 deletions public/js/spike.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function restore() {
}

// Save (scroll) data about the current state of the page, and reload it.
function reload(event) {
function reload() {
store.set({
y: window.scrollY,
x: window.scrollX
Expand All @@ -155,10 +155,14 @@ function reload(event) {
* Manage the render stream. Wait for processed versions of the author's code,
* and either reload of inject the new code (CSS).
*/
function renderStream() {
function liveReload() {
es.addEventListener('css:processed', function (event) {
// Inject the CSS
var style = document.getElementById('jsbin-css');
if (!style) {
return reload();
}

if (style.styleSheet) {
style.styleSheet.cssText = event.data;
} else {
Expand Down Expand Up @@ -233,7 +237,7 @@ function startStream() {
if (codecasting) {
codecastStream();
} else {
renderStream();
liveReload();
}
if (window.jQuery) {
var $document = $(document);
Expand Down

0 comments on commit 817ebe1

Please sign in to comment.