Advertisement
Guest User

Untitled

a guest
Sep 11th, 2013
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     Meteor.publish("subscriptions", function(ghash) {
  2.         userId = this.userId;
  3.         //console.log(this._session.socket.meteor_session.collectionViews.groups);        
  4.         if(this._session.socket) {
  5.             if(this._session.socket._events.data.length === 1) {
  6.  
  7.                 this._session.socket.on("data", Meteor.bindEnvironment(function(data) {
  8.  
  9.                     //console.log(JSON.parse(data));
  10.  
  11.                     var method = JSON.parse(data).method;
  12.                     var submsg = JSON.parse(data).msg;
  13.                     var subid = JSON.parse(data).id;
  14.  
  15.  
  16.                     if(submsg === 'sub') {
  17.                         if(JSON.parse(data).params && JSON.parse(data).name === 'subscriptions') {
  18.                             console.log('---------------- SUB ----------------');
  19.                             var ghash2 = JSON.parse(data).params[0];
  20.                             if(ghash == ghash2)
  21.                                 Subscriptions.insert({id: subid, ghash: ghash});
  22.                         }
  23.                     }
  24.                     if(submsg === 'unsub') {
  25.                         console.log('--------------- UNSUB ---------------');
  26.                         Subscriptions.remove({id: subid});
  27.                     }
  28.  
  29.                     console.log(Subscriptions.find().fetch());
  30.  
  31.                 }, function(e) {
  32.                     console.log(e);
  33.                 }));
  34.  
  35.                 this._session.socket.on("close", Meteor.bindEnvironment(function(data) {
  36.                     console.log(data);
  37.                 }, function(e) {
  38.                     console.log("close error", e);
  39.                 }));
  40.             }
  41.         }
  42.         console.log(Subscriptions.find().fetch());
  43.         return Subscriptions.find();
  44.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement