diff --git a/www/js/ts.js b/www/js/ts.js index a59d091..18acb66 100644 --- a/www/js/ts.js +++ b/www/js/ts.js @@ -584,7 +584,19 @@ $(document).ready(function(){ // render views this.user.view.render(); this.timelines.view.render(); - this.entries.view.render(); }, + this.entries.view.render(); + + // create our WebSocket for receiving push notifications of changed + // content. + if (false) { // (Modernizr.websockets) + TS.updateConnection = new WebSocket('wss://' + + window.location.hostname + + (window.location.port ? ":" window.location.port : "") + + '/ts_api/update_service?user_id=' + + this.user.model.get("id")); + TS.updateConnection.onopen = this.syncConnected; + TS.updateConnection.onmessage = this.syncUpdate; + TS.updateConnection.onclose = this.syncDisconnected; } }, loadInitialData: function() { // assume we are authenticated @@ -653,7 +665,32 @@ $(document).ready(function(){ this.timelines.view.render(); // fetch the new EntryList records - this.entries.collection.fetch() } } }); + this.entries.collection.fetch() } }, + + syncConnected: function() { }, + + syncDisconnected: function() {err) { + // TODO: reconnect. Possibly display a button for the user to + // manually reconnect if we've already tried and failed too many + // times. + }, + + syncUpdate: function(message) { + if (!message.data) return; + + var data = JSON.parse(message.data); + + if (data.record_type == "ts_entry") { + // Check to see if the record is for the same timeline we are + // currently using. + + // + } + + if (data.record_type == "ts_timeline") { + + } + } }); TS.LoginView = Backbone.View.extend({ el: $("#login")[0],