Skip to content

Commit

Permalink
Logout
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo mathieu committed Jan 20, 2016
1 parent 66a3fa2 commit cedd931
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ Login to meteor server via a token
- `token` **string** *required*
- `callback(err, result)` **method**

### logout(callback)

Logout from meteor server

#### Warning

You can only do one subscription on a same collection at one time
34 changes: 32 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var queue = require('./queue');
var ddp;
var subscriptions = [];

var logoutId,
logoutCb;
var loginWithEmailId,
loginWithEmailCb;
var loginWithUsernameId,
Expand All @@ -16,6 +18,10 @@ var methods = [];

module.exports = {
on: queue.on,
logout: function (callback) {
logoutCb = callback;
logoutId = ddp.method("logout");
},
loginWithToken: function (token, callback) {
loginWithTokenCb = callback;
loginWithTokenId = ddp.method("login", [{ resume: token }]);
Expand All @@ -39,6 +45,11 @@ module.exports = {
}]);
},
method: function (event, param, callback) {
if(callback===undefined) {
callback = param;
param = [];
}

var id = ddp.method(event, param);
methods.push({
id: id,
Expand Down Expand Up @@ -110,7 +121,15 @@ module.exports = {
}

},

disconnect: function () {
//ddp.disconnect();
},
reconnect: function () {
ddp = new DDP({
endpoint: endpoint,

This comment has been minimized.

Copy link
@aleclarson

aleclarson Feb 23, 2016

Should this be endpointSaved?

This comment has been minimized.

Copy link
@Mokto

Mokto Feb 23, 2016

Contributor

Absolutely right @aleclarson => It is now fixed in master.

SocketConstructor: WebSocket
});
},
connect: function (endpoint) {
ddp = new DDP({
endpoint: endpoint,
Expand All @@ -123,7 +142,17 @@ module.exports = {
queue.emit('disconnected');
});

ddp.on("result", function (message) {
ddp.on("result", (message) => {

if (message.id === logoutId && typeof logoutCb == 'function') {
if(message.error) {
return logoutCb(message.error);
}
logoutCb();
this.connect(endpoint);
return;
}

if (message.id === loginWithEmailId && typeof loginWithEmailCb == 'function') {
if(message.error) {
return loginWithEmailCb(message.error);
Expand All @@ -145,6 +174,7 @@ module.exports = {
loginWithTokenCb(null, message.result);
return;
}
//console.log('RESULT FROM METEOR METHOD');
var index;
for(var i in methods) {
var method = methods[i];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-meteor",
"version": "0.3.1",
"version": "0.3.2",
"description": "DDP React-native Client",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit cedd931

Please sign in to comment.