2012-03-07 05:14:03 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-aphlict
|
|
|
|
* @requires javelin-install
|
|
|
|
* javelin-util
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
* javelin-websocket
|
|
|
|
* javelin-leader
|
|
|
|
* javelin-json
|
2012-03-07 05:14:03 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
* Client for the notification server. Example usage:
|
2012-03-07 05:14:03 +01:00
|
|
|
*
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
* var aphlict = new JX.Aphlict('ws://localhost:22280', subscriptions)
|
|
|
|
* .setHandler(function(message) {
|
|
|
|
* // ...
|
2012-03-07 05:14:03 +01:00
|
|
|
* })
|
|
|
|
* .start();
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
JX.install('Aphlict', {
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
construct: function(uri, subscriptions) {
|
2012-03-07 05:14:03 +01:00
|
|
|
if (__DEV__) {
|
|
|
|
if (JX.Aphlict._instance) {
|
2014-06-24 01:26:16 +02:00
|
|
|
JX.$E('Aphlict object is a singleton.');
|
2012-03-07 05:14:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
this._uri = uri;
|
2014-06-11 21:17:18 +02:00
|
|
|
this._subscriptions = subscriptions;
|
2014-06-24 01:26:16 +02:00
|
|
|
this._setStatus('setup');
|
Fix several duplication/replay behaviors in Aphlict
Summary:
Ref T12566. Ref T12563. This fixes three bugs with Aphlict replay stuff:
First, Conphernece would try to repaint the UI even if no thread was open. Only repaint when a thread is open.
Second, although we deduplicate JX.Leader messages, we didn't deduplicate actual notification messages. If you browsed the leader window, then it re-elected itelf as a leader and replayed history, it could rebroadcast notifications and other windows could show doubles. Deduplicate notifications to prevent this.
Third, we always replayed the last 60 seconds of history. When you browsed the leader window, whichever window became the new leader (possibly the one you just browsed) could replay messages from before it had opened, leading to duplicate messages. Particularly, after receiving a message and then browsing you could see that message again. Instead, only replay history as far back as when the window first opened.
Test Plan:
- Clicked "Repaint" with a thread open, saw a repaint. Clicked "Repaint" with Conpherence open but no thread, no repaint and no 404 request to `/update/null/`.
- In browser A, opened three windows. In browser B, sent a notification. In browser A, browsed the leader window away twice in a row. Observed that the window which never became a leader doesn't duplicate notifications.
- In browser A, opened three windows. In browser B, sent a notification. In browser A, browsed the leader window away over and over again. Observed that replay requests issued with appropriate history windows.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12566, T12563
Differential Revision: https://secure.phabricator.com/D17722
2017-04-18 20:14:37 +02:00
|
|
|
this._startTime = new Date().getTime();
|
2012-03-07 05:14:03 +01:00
|
|
|
|
2014-06-24 00:19:34 +02:00
|
|
|
JX.Aphlict._instance = this;
|
2012-03-07 05:14:03 +01:00
|
|
|
},
|
|
|
|
|
2014-06-24 01:26:16 +02:00
|
|
|
events: ['didChangeStatus'],
|
|
|
|
|
2014-06-24 00:19:34 +02:00
|
|
|
members: {
|
2015-01-14 22:08:08 +01:00
|
|
|
_uri: null,
|
|
|
|
_socket: null,
|
2014-06-24 00:19:34 +02:00
|
|
|
_subscriptions: null,
|
2014-06-24 01:26:16 +02:00
|
|
|
_status: null,
|
2017-04-17 23:05:29 +02:00
|
|
|
_isReconnect: false,
|
2017-04-18 02:00:46 +02:00
|
|
|
_keepaliveInterval: false,
|
Fix several duplication/replay behaviors in Aphlict
Summary:
Ref T12566. Ref T12563. This fixes three bugs with Aphlict replay stuff:
First, Conphernece would try to repaint the UI even if no thread was open. Only repaint when a thread is open.
Second, although we deduplicate JX.Leader messages, we didn't deduplicate actual notification messages. If you browsed the leader window, then it re-elected itelf as a leader and replayed history, it could rebroadcast notifications and other windows could show doubles. Deduplicate notifications to prevent this.
Third, we always replayed the last 60 seconds of history. When you browsed the leader window, whichever window became the new leader (possibly the one you just browsed) could replay messages from before it had opened, leading to duplicate messages. Particularly, after receiving a message and then browsing you could see that message again. Instead, only replay history as far back as when the window first opened.
Test Plan:
- Clicked "Repaint" with a thread open, saw a repaint. Clicked "Repaint" with Conpherence open but no thread, no repaint and no 404 request to `/update/null/`.
- In browser A, opened three windows. In browser B, sent a notification. In browser A, browsed the leader window away twice in a row. Observed that the window which never became a leader doesn't duplicate notifications.
- In browser A, opened three windows. In browser B, sent a notification. In browser A, browsed the leader window away over and over again. Observed that replay requests issued with appropriate history windows.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12566, T12563
Differential Revision: https://secure.phabricator.com/D17722
2017-04-18 20:14:37 +02:00
|
|
|
_startTime: null,
|
2014-06-24 00:19:34 +02:00
|
|
|
|
2015-01-14 22:08:08 +01:00
|
|
|
start: function() {
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
JX.Leader.listen('onBecomeLeader', JX.bind(this, this._lead));
|
|
|
|
JX.Leader.listen('onReceiveBroadcast', JX.bind(this, this._receive));
|
|
|
|
JX.Leader.start();
|
|
|
|
|
|
|
|
JX.Leader.call(JX.bind(this, this._begin));
|
|
|
|
},
|
|
|
|
|
2015-05-07 21:47:49 +02:00
|
|
|
getSubscriptions: function() {
|
|
|
|
return this._subscriptions;
|
|
|
|
},
|
|
|
|
|
2015-04-21 01:43:32 +02:00
|
|
|
setSubscriptions: function(subscriptions) {
|
|
|
|
this._subscriptions = subscriptions;
|
|
|
|
JX.Leader.broadcast(
|
|
|
|
null,
|
|
|
|
{type: 'aphlict.subscribe', data: this._subscriptions});
|
|
|
|
},
|
|
|
|
|
|
|
|
clearSubscriptions: function(subscriptions) {
|
|
|
|
this._subscriptions = null;
|
|
|
|
JX.Leader.broadcast(
|
|
|
|
null,
|
|
|
|
{type: 'aphlict.unsubscribe', data: subscriptions});
|
|
|
|
},
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
getStatus: function() {
|
|
|
|
return this._status;
|
2014-06-24 00:19:34 +02:00
|
|
|
},
|
|
|
|
|
2017-04-17 21:59:16 +02:00
|
|
|
getWebsocket: function() {
|
|
|
|
return this._socket;
|
|
|
|
},
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
_begin: function() {
|
|
|
|
JX.Leader.broadcast(
|
|
|
|
null,
|
|
|
|
{type: 'aphlict.getstatus'});
|
|
|
|
JX.Leader.broadcast(
|
|
|
|
null,
|
|
|
|
{type: 'aphlict.subscribe', data: this._subscriptions});
|
|
|
|
},
|
|
|
|
|
|
|
|
_lead: function() {
|
2015-01-14 22:08:08 +01:00
|
|
|
this._socket = new JX.WebSocket(this._uri);
|
|
|
|
this._socket.setOpenHandler(JX.bind(this, this._open));
|
|
|
|
this._socket.setMessageHandler(JX.bind(this, this._message));
|
|
|
|
this._socket.setCloseHandler(JX.bind(this, this._close));
|
2014-06-24 00:19:34 +02:00
|
|
|
|
2015-01-14 22:08:08 +01:00
|
|
|
this._socket.open();
|
2014-06-24 01:26:16 +02:00
|
|
|
},
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
_open: function() {
|
2017-04-17 23:05:29 +02:00
|
|
|
// If this is a reconnect, ask the server to replay recent messages
|
|
|
|
// after other tabs have had a chance to subscribe. Do this before we
|
|
|
|
// broadcast that the connection status is now open.
|
|
|
|
if (this._isReconnect) {
|
2017-04-18 00:08:51 +02:00
|
|
|
setTimeout(JX.bind(this, this._didReconnect), 100);
|
2017-04-17 23:05:29 +02:00
|
|
|
}
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
this._broadcastStatus('open');
|
|
|
|
JX.Leader.broadcast(null, {type: 'aphlict.getsubscribers'});
|
2017-04-18 02:00:46 +02:00
|
|
|
|
|
|
|
// By default, ELBs terminate connections after 60 seconds with no
|
|
|
|
// traffic. Other load balancers may have similar configuration. Send
|
|
|
|
// a keepalive message every 15 seconds to prevent load balancers from
|
|
|
|
// deciding they can reap this connection.
|
|
|
|
|
|
|
|
var keepalive = JX.bind(this, this._keepalive);
|
|
|
|
this._keepaliveInterval = setInterval(keepalive, 15000);
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
},
|
|
|
|
|
2017-04-18 00:08:51 +02:00
|
|
|
_didReconnect: function() {
|
2017-04-17 23:05:29 +02:00
|
|
|
this.replay();
|
2017-04-18 00:08:51 +02:00
|
|
|
this.reconnect();
|
2017-04-17 23:05:29 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
replay: function() {
|
Fix several duplication/replay behaviors in Aphlict
Summary:
Ref T12566. Ref T12563. This fixes three bugs with Aphlict replay stuff:
First, Conphernece would try to repaint the UI even if no thread was open. Only repaint when a thread is open.
Second, although we deduplicate JX.Leader messages, we didn't deduplicate actual notification messages. If you browsed the leader window, then it re-elected itelf as a leader and replayed history, it could rebroadcast notifications and other windows could show doubles. Deduplicate notifications to prevent this.
Third, we always replayed the last 60 seconds of history. When you browsed the leader window, whichever window became the new leader (possibly the one you just browsed) could replay messages from before it had opened, leading to duplicate messages. Particularly, after receiving a message and then browsing you could see that message again. Instead, only replay history as far back as when the window first opened.
Test Plan:
- Clicked "Repaint" with a thread open, saw a repaint. Clicked "Repaint" with Conpherence open but no thread, no repaint and no 404 request to `/update/null/`.
- In browser A, opened three windows. In browser B, sent a notification. In browser A, browsed the leader window away twice in a row. Observed that the window which never became a leader doesn't duplicate notifications.
- In browser A, opened three windows. In browser B, sent a notification. In browser A, browsed the leader window away over and over again. Observed that replay requests issued with appropriate history windows.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12566, T12563
Differential Revision: https://secure.phabricator.com/D17722
2017-04-18 20:14:37 +02:00
|
|
|
var age = 60000;
|
|
|
|
|
|
|
|
// If the page was loaded a few moments ago, only query for recent
|
|
|
|
// history. This keeps us from replaying events over and over again as
|
|
|
|
// a user browses normally.
|
|
|
|
|
|
|
|
// Allow a small margin of error for the actual page load time. It's
|
|
|
|
// also fine to replay a notification which the user saw for a brief
|
|
|
|
// moment on the previous page.
|
|
|
|
var extra_time = 500;
|
|
|
|
var now = new Date().getTime();
|
|
|
|
|
|
|
|
age = Math.min(extra_time + (now - this._startTime), age);
|
|
|
|
|
2017-04-17 23:05:29 +02:00
|
|
|
var replay = {
|
Fix several duplication/replay behaviors in Aphlict
Summary:
Ref T12566. Ref T12563. This fixes three bugs with Aphlict replay stuff:
First, Conphernece would try to repaint the UI even if no thread was open. Only repaint when a thread is open.
Second, although we deduplicate JX.Leader messages, we didn't deduplicate actual notification messages. If you browsed the leader window, then it re-elected itelf as a leader and replayed history, it could rebroadcast notifications and other windows could show doubles. Deduplicate notifications to prevent this.
Third, we always replayed the last 60 seconds of history. When you browsed the leader window, whichever window became the new leader (possibly the one you just browsed) could replay messages from before it had opened, leading to duplicate messages. Particularly, after receiving a message and then browsing you could see that message again. Instead, only replay history as far back as when the window first opened.
Test Plan:
- Clicked "Repaint" with a thread open, saw a repaint. Clicked "Repaint" with Conpherence open but no thread, no repaint and no 404 request to `/update/null/`.
- In browser A, opened three windows. In browser B, sent a notification. In browser A, browsed the leader window away twice in a row. Observed that the window which never became a leader doesn't duplicate notifications.
- In browser A, opened three windows. In browser B, sent a notification. In browser A, browsed the leader window away over and over again. Observed that replay requests issued with appropriate history windows.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12566, T12563
Differential Revision: https://secure.phabricator.com/D17722
2017-04-18 20:14:37 +02:00
|
|
|
age: age
|
2017-04-17 23:05:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
JX.Leader.broadcast(null, {type: 'aphlict.replay', data: replay});
|
|
|
|
},
|
|
|
|
|
2017-04-18 00:08:51 +02:00
|
|
|
reconnect: function() {
|
|
|
|
JX.Leader.broadcast(null, {type: 'aphlict.reconnect', data: null});
|
|
|
|
},
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
_close: function() {
|
2017-04-18 02:00:46 +02:00
|
|
|
if (this._keepaliveInterval) {
|
|
|
|
clearInterval(this._keepaliveInterval);
|
|
|
|
this._keepaliveInterval = null;
|
|
|
|
}
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
this._broadcastStatus('closed');
|
|
|
|
},
|
|
|
|
|
|
|
|
_broadcastStatus: function(status) {
|
|
|
|
JX.Leader.broadcast(null, {type: 'aphlict.status', data: status});
|
|
|
|
},
|
|
|
|
|
|
|
|
_message: function(raw) {
|
|
|
|
var message = JX.JSON.parse(raw);
|
2017-04-17 23:42:54 +02:00
|
|
|
var id = message.uniqueID || null;
|
|
|
|
|
2017-04-18 02:00:46 +02:00
|
|
|
// If this is just a keepalive response, don't bother broadcasting it.
|
|
|
|
if (message.type == 'pong') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-17 23:42:54 +02:00
|
|
|
JX.Leader.broadcast(id, {type: 'aphlict.server', data: message});
|
2014-06-24 01:26:16 +02:00
|
|
|
},
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
_receive: function(message, is_leader) {
|
|
|
|
switch (message.type) {
|
|
|
|
case 'aphlict.status':
|
|
|
|
this._setStatus(message.data);
|
|
|
|
break;
|
2015-01-14 22:08:08 +01:00
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
case 'aphlict.getstatus':
|
|
|
|
if (is_leader) {
|
|
|
|
this._broadcastStatus(this.getStatus());
|
|
|
|
}
|
|
|
|
break;
|
2015-01-14 22:08:08 +01:00
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
case 'aphlict.getsubscribers':
|
|
|
|
JX.Leader.broadcast(
|
|
|
|
null,
|
|
|
|
{type: 'aphlict.subscribe', data: this._subscriptions});
|
|
|
|
break;
|
2015-01-14 22:08:08 +01:00
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
case 'aphlict.subscribe':
|
|
|
|
if (is_leader) {
|
2017-04-17 23:05:29 +02:00
|
|
|
this._writeCommand('subscribe', message.data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'aphlict.replay':
|
|
|
|
if (is_leader) {
|
|
|
|
this._writeCommand('replay', message.data);
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
}
|
|
|
|
break;
|
2015-01-14 22:08:08 +01:00
|
|
|
|
Multiplex AJAX calls
Summary: Fixes T5344. Essentially, we only make the AJAX request to `/notification/individual/` if we are the leader tab (i.e. only one tab will make this request). Once a response has been received from the server (containing the contents of the notification), we broadcast the message contents back to all other tabs for rendering.
Test Plan:
Opened two tabs on `/notification/status/` and clicked "Send Test Notification".
**Before**
```lang=bash, name=tail -f /var/log/phabricator-access.log | grep /notification/individual/
[Tue, 13 Jan 2015 20:10:37 +1100] 17033 phabricator 10.0.0.1 josh PhabricatorNotificationIndividualController - /notification/individual/-200 236036
[Tue, 13 Jan 2015 20:10:37 +1100] 17657 phabricator 10.0.0.1 josh PhabricatorNotificationIndividualController - /notification/individual/-200 24130
```
**After**
```lang=bash, name=tail -f /var/log/phabricator-access.log | grep /notification/individual/
[Tue, 13 Jan 2015 20:11:15 +1100] 17657 phabricator 10.0.0.1 josh PhabricatorNotificationIndividualController - /notification/individual/-200 180217
```
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T5344
Differential Revision: https://secure.phabricator.com/D11360
2015-01-15 21:05:31 +01:00
|
|
|
default:
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
var handler = this.getHandler();
|
Multiplex AJAX calls
Summary: Fixes T5344. Essentially, we only make the AJAX request to `/notification/individual/` if we are the leader tab (i.e. only one tab will make this request). Once a response has been received from the server (containing the contents of the notification), we broadcast the message contents back to all other tabs for rendering.
Test Plan:
Opened two tabs on `/notification/status/` and clicked "Send Test Notification".
**Before**
```lang=bash, name=tail -f /var/log/phabricator-access.log | grep /notification/individual/
[Tue, 13 Jan 2015 20:10:37 +1100] 17033 phabricator 10.0.0.1 josh PhabricatorNotificationIndividualController - /notification/individual/-200 236036
[Tue, 13 Jan 2015 20:10:37 +1100] 17657 phabricator 10.0.0.1 josh PhabricatorNotificationIndividualController - /notification/individual/-200 24130
```
**After**
```lang=bash, name=tail -f /var/log/phabricator-access.log | grep /notification/individual/
[Tue, 13 Jan 2015 20:11:15 +1100] 17657 phabricator 10.0.0.1 josh PhabricatorNotificationIndividualController - /notification/individual/-200 180217
```
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T5344
Differential Revision: https://secure.phabricator.com/D11360
2015-01-15 21:05:31 +01:00
|
|
|
handler && handler(message);
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-06-24 01:26:16 +02:00
|
|
|
},
|
|
|
|
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
_setStatus: function(status) {
|
2014-06-24 01:26:16 +02:00
|
|
|
this._status = status;
|
2017-04-17 23:05:29 +02:00
|
|
|
|
|
|
|
// If we've ever seen an open connection, any new connection we make
|
|
|
|
// is a reconnect and should replay history.
|
|
|
|
if (status == 'open') {
|
|
|
|
this._isReconnect = true;
|
|
|
|
}
|
|
|
|
|
2014-06-24 01:26:16 +02:00
|
|
|
this.invoke('didChangeStatus');
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
_write: function(message) {
|
|
|
|
this._socket.send(JX.JSON.stringify(message));
|
2017-04-17 23:05:29 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
_writeCommand: function(command, message) {
|
|
|
|
var frame = {
|
|
|
|
command: command,
|
|
|
|
data: message
|
|
|
|
};
|
|
|
|
|
|
|
|
return this._write(frame);
|
2017-04-18 02:00:46 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
_keepalive: function() {
|
|
|
|
this._writeCommand('ping', null);
|
2012-03-07 05:14:03 +01:00
|
|
|
}
|
2014-06-24 00:19:34 +02:00
|
|
|
|
2012-03-07 05:14:03 +01:00
|
|
|
},
|
|
|
|
|
2014-06-24 00:19:34 +02:00
|
|
|
properties: {
|
|
|
|
handler: null
|
2012-03-07 05:14:03 +01:00
|
|
|
},
|
|
|
|
|
2014-06-24 00:19:34 +02:00
|
|
|
statics: {
|
|
|
|
_instance: null,
|
|
|
|
|
|
|
|
getInstance: function() {
|
|
|
|
var self = JX.Aphlict;
|
|
|
|
if (!self._instance) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return self._instance;
|
2012-03-07 05:14:03 +01:00
|
|
|
}
|
Rewrite Aphlict to use Websockets
Summary:
Fixes T6559. No more flash, use Websockets. This is less aggressive than the earlier version, and retains more server logic.
- Support "wss".
- Make the client work.
- Remove "notification.user" entirely.
- Seems ok?
Test Plan:
In Safari, Firefox and Chrome, saw the browsers connect. Made a bunch of comments/updates and saw notifications.
Notable holes in the test plan:
- Haven't tested "wss" yet. I'll do this on secure.
- Notifications are //too fast// now, locally. I get them after I hit submit but before the page reloads.
- There are probably some other rough edges, this is a fairly big patch.
Reviewers: joshuaspence, btrahan
Reviewed By: joshuaspence, btrahan
Subscribers: fabe, btrahan, epriestley
Maniphest Tasks: T6713, T6559
Differential Revision: https://secure.phabricator.com/D11143
2015-01-08 19:03:00 +01:00
|
|
|
|
2012-03-07 05:14:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|