From be1ef7abe32c42a9048f4afae8d1cbf7f1eee872 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 22 Apr 2016 10:04:54 +0200 Subject: [PATCH] migrate canvas to netflux --- www/canvas/main.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/www/canvas/main.js b/www/canvas/main.js index f25b64ecb..1a52213ff 100644 --- a/www/canvas/main.js +++ b/www/canvas/main.js @@ -4,7 +4,7 @@ require.config({ paths: { define([ '/api/config?cb=' + Math.random().toString(16).substring(2), - '/common/RealtimeTextarea.js', + '/common/realtime-input.js', '/common/messages.js', '/common/crypto.js', '/common/TextPatcher.js', @@ -17,12 +17,15 @@ define([ var $ = module.$ = window.jQuery; var Fabric = module.Fabric = window.fabric; - $(window).on('hashchange', function() { - window.location.reload(); - }); - if (window.location.href.indexOf('#') === -1) { - window.location.href = window.location.href + '#' + Crypto.genKey(); - return; + + var key; + var channel = ''; + if (!/#/.test(window.location.href)) { + key = Crypto.genKey(); + } else { + var hash = window.location.hash.slice(1); + channel = hash.slice(0, 32); + key = hash.slice(32); } /* Initialize Fabric */ @@ -56,17 +59,22 @@ define([ $canvas.css('border-color', bool? 'black': 'red'); }; - var key = Crypto.parseKey(window.location.hash.substring(1)); var initializing = true; var config = module.config = { - websocketURL: Config.websocketURL + '_old', + // TODO initialState ? + websocketURL: Config.websocketURL, userName: Crypto.rand64(8), - channel: key.channel, - cryptKey: key.cryptKey + channel: channel, + cryptKey: key, }; - var onInit = config.onInit = function (info) { }; + var onInit = config.onInit = function (info) { + window.location.hash = info.channel + key; + $(window).on('hashchange', function() { + window.location.reload(); + }); + }; var onRemote = config.onRemote = function () { if (initializing) { return; }