Implement Live Data protocol: 'connect' and 'connected'.

For now, high-level behavior is the same.  When the transport
disconnects, client doesn't attempt to reuse previous session.

Server always establishes a new Live Data session with each connect.
Server does not support method reply cache, and won't honor a client's
attempt to reuse a previous Live Data session id.
This commit is contained in:
Nick Martin
2012-02-07 15:57:17 -08:00
committed by matt debergalis
parent acd3e24eec
commit 08fa853fca
2 changed files with 18 additions and 6 deletions

View File

@@ -38,6 +38,7 @@ if (typeof Meteor === "undefined") Meteor = {};
});
var livedata_connected = function (msg) {
Meteor._debug("CONNECTED", msg);
};
var livedata_data = function (msg) {
@@ -87,13 +88,17 @@ if (typeof Meteor === "undefined") Meteor = {};
});
Meteor._stream.reset(function (msg_list) {
// remove existing subscribe and unsubscribe
msg_list = _.reject(msg_list, function (elem) {
return (!elem
|| (elem[0] === "livedata" && elem[1]
&& (elem[1].msg === "sub" || elem[1].msg === "unsub")));
// remove all 'livedata' message except 'method'
msg_list = _.filter(msg_list, function (elem) {
return (elem && (elem[0] !== "livedata" ||
(elem[1] && elem[1].msg === "method")));
});
// Send a connect message at the beginning of the stream.
// NOTE: reset is called even on the first connection, so this is
// the only place we send this message.
msg_list.unshift(['livedata', {msg: 'connect'}]);
// add new subscriptions at the end. this way they take effect after
// the handlers and we don't see flicker.
subs.find().forEach(function (sub) {

View File

@@ -119,6 +119,11 @@ if (typeof Meteor === "undefined") Meteor = {};
}).run();
};
var livedata_connect = function (socket, msg) {
// Always start a new session. We don't support any reconnection.
socket.emit('livedata', {msg: 'connected', session: Meteor.uuid()});
};
var livedata_sub = function (socket, msg) {
if (!publishes[msg.name]) {
// can't sub to unknown publish name
@@ -195,7 +200,9 @@ if (typeof Meteor === "undefined") Meteor = {};
return;
}
if (msg.msg === 'sub')
if (msg.msg === 'connect')
livedata_connect(socket, msg);
else if (msg.msg === 'sub')
livedata_sub(socket, msg);
else if (msg.msg === 'unsub')
livedata_unsub(socket, msg);