diff --git a/support/aphlict/client/src/Aphlict.as b/support/aphlict/client/src/Aphlict.as index d61ad04b0a..592bbd4e54 100644 --- a/support/aphlict/client/src/Aphlict.as +++ b/support/aphlict/client/src/Aphlict.as @@ -31,6 +31,10 @@ package { ExternalInterface.call('JX.Aphlict.didReceiveEvent', type, object); } + protected function error(error:Error):void { + this.externalInvoke('error', error.toString()); + } + protected function log(message:String):void { this.externalInvoke('log', message); } diff --git a/support/aphlict/client/src/AphlictMaster.as b/support/aphlict/client/src/AphlictMaster.as index 1991ab48bd..ee07fe53e6 100644 --- a/support/aphlict/client/src/AphlictMaster.as +++ b/support/aphlict/client/src/AphlictMaster.as @@ -131,34 +131,38 @@ package { } private function didReceiveSocket(event:Event):void { - var b:ByteArray = this.readBuffer; - this.socket.readBytes(b, b.length); + try { + var b:ByteArray = this.readBuffer; + this.socket.readBytes(b, b.length); - do { - b = this.readBuffer; - b.position = 0; + do { + b = this.readBuffer; + b.position = 0; - if (b.length <= 8) { - break; - } - - var msg_len:Number = parseInt(b.readUTFBytes(8), 10); - if (b.length >= msg_len + 8) { - var bytes:String = b.readUTFBytes(msg_len); - var data:Object = vegas.strings.JSON.deserialize(bytes); - var t:ByteArray = new ByteArray(); - t.writeBytes(b, msg_len + 8); - this.readBuffer = t; - - // Send the message to all clients. - for (var client:String in this.clients) { - this.log('Sending message to client: ' + client); - this.send.send(client, 'receiveMessage', data); + if (b.length <= 8) { + break; } - } else { - break; - } - } while (true); + + var msg_len:Number = parseInt(b.readUTFBytes(8), 10); + if (b.length >= msg_len + 8) { + var bytes:String = b.readUTFBytes(msg_len); + var data:Object = vegas.strings.JSON.deserialize(bytes); + var t:ByteArray = new ByteArray(); + t.writeBytes(b, msg_len + 8); + this.readBuffer = t; + + // Send the message to all clients. + for (var client:String in this.clients) { + this.log('Sending message to client: ' + client); + this.send.send(client, 'receiveMessage', data); + } + } else { + break; + } + } while (true); + } catch (err:Error) { + this.error(err); + } } } diff --git a/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js b/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js index 5fc15968d1..0f40d2c13f 100644 --- a/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js +++ b/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js @@ -24,25 +24,39 @@ JX.behavior('aphlict-listen', function(config) { // Respond to a notification from the Aphlict notification server. We send // a request to Phabricator to get notification details. function onaphlictmessage(type, message) { - if (type == 'receive') { - var routable = new JX.Request('/notification/individual/', onnotification) - .addData({key: message.key}) - .getRoutable(); - - routable - .setType('notification') - .setPriority(250); - - JX.Router.getInstance().queue(routable); - } else if (__DEV__) { - if (config.debug) { - var details = message ? JX.JSON.stringify(message) : ''; - + switch (type) { + case 'error': new JX.Notification() - .setContent('(Aphlict) [' + type + '] ' + details) - .alterClassName('jx-notification-debug', true) + .setContent('(Aphlict) ' + message) + .alterClassName('jx-notification-error', true) .show(); - } + break; + + case 'receive': + var routable = new JX.Request( + '/notification/individual/', + onnotification); + + routable + .addData({key: message.key}) + .getRoutable(); + + routable + .setType('notification') + .setPriority(250); + + JX.Router.getInstance().queue(routable); + break; + + default: + if (__DEV__ && config.debug) { + var details = message ? JX.JSON.stringify(message) : ''; + + new JX.Notification() + .setContent('(Aphlict) [' + type + '] ' + details) + .alterClassName('jx-notification-debug', true) + .show(); + } } } @@ -63,8 +77,7 @@ JX.behavior('aphlict-listen', function(config) { // If the notification affected an object on this page, show a // permanent reload notification if we aren't already. - if ((response.primaryObjectPHID in config.pageObjects) && - !showing_reload) { + if ((response.primaryObjectPHID in config.pageObjects) && !showing_reload) { var reload = new JX.Notification() .setContent('Page updated, click to reload.') .alterClassName('jx-notification-alert', true) diff --git a/webroot/rsrc/swf/aphlict.swf b/webroot/rsrc/swf/aphlict.swf index cee18c7dc6..c6ffcdbd32 100644 Binary files a/webroot/rsrc/swf/aphlict.swf and b/webroot/rsrc/swf/aphlict.swf differ