Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gitter-realtime-client

Package Overview
Dependencies
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitter-realtime-client - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

75

lib/live-collection.js

@@ -5,5 +5,5 @@ "use strict";

var Backbone = require('backbone');
var log = require('loglevel');
var backboneUrlResolver = require('backbone-url-resolver');
var defaultContextModel = require('./default-context-model');
var debug = require('debug-proxy')('gtc:live-collection');

@@ -35,5 +35,5 @@ var PATCH_TIMEOUT = 2000; // 2000ms before a patch gives up

this.once('sync', this._onInitialLoad, this);
this.on('sync', this._onSync, this);
this.on('request', this._onRequest, this);
this.listenToOnce(this, 'sync', this._onInitialLoad);
this.listenTo(this, 'sync', this._onSync);
this.listenTo(this, 'request', this._onRequest);

@@ -47,3 +47,3 @@ if(options && options.listen) {

addWaiter: function(id, callback, timeout) {
log.info('coll: Waiting for id', id);
debug('Waiting for id %s in collection', id);

@@ -59,3 +59,2 @@ if(!id) return;

clearTimeout(timeoutRef);
log.info('coll: Waitor completed with model', model);

@@ -65,4 +64,5 @@ self.off('add', check, id);

/* This check is probably not strictly neccessary */
if(actionPerformed) {
log.info('coll: Warning: waitor function called twice.');
debug('Warning: waiter function called twice.');
return;

@@ -94,14 +94,20 @@ }

_onSync: function() {
this._loading = false;
this._loadStateChange(false);
},
_onRequest: function() {
this._loading = true;
this._loadStateChange(true);
},
_onInitialLoad: function() {
if(this._initialLoadCalled) return;
this._initialLoadCalled = true;
_loadStateChange: function(newState) {
newState = !!newState;
var current = !!this._loading;
this._loading = newState;
if (newState !== current) {
this.trigger('loadingStateChange', newState);
}
},
this.trigger('loaded');
isLoading: function() {
return this._loading;
},

@@ -119,5 +125,15 @@

this.listenTo(this.templateSubscription, 'resubscribe unsubscribe', function() {
this.listenTo(this.templateSubscription, 'resubscribe', function() {
debug('Resetting collection on resubscribe: %s', this.url());
this.trigger('request');
this.reset();
this._loadStateChange(true);
});
this.listenTo(this.templateSubscription, 'unsubscribe', function() {
debug('Resetting collection on unsubscribe: %s', this.url());
this.reset();
this._loadStateChange(true);
});
},

@@ -152,4 +168,2 @@

handleSnapshot: function(snapshot) {
this.trigger('request');
/**

@@ -170,8 +184,6 @@ * Don't remove items from the collections, as there is a greater

if(this.length > 0) {
/* Remove any presnapshot stuff (cached from previous time) */
var forKeeping = this.where({ presnapshot: undefined });
// add one by one
this.set(forKeeping.concat(snapshot), options);
debug('Performing merge on snapshot (current length is %s)', this.length);
this.set(snapshot, options);
} else {
debug('Performing reset on snapshot');
// trash it and add all in one go

@@ -181,3 +193,2 @@ this.reset(snapshot, options);

this._onInitialLoad();
this.trigger('sync');

@@ -187,10 +198,2 @@ this.trigger('snapshot');

isLoading: function() {
return this._loading;
},
hasLoaded: function() {
return this._initialLoadCalled;
},
findExistingModel: function(id, newModel) {

@@ -230,3 +233,3 @@ var existing = this.get(id);

if(this.operationIsUpToDate(operation, existingModel, newAttributes)) {
log.info('coll: Performing ' + operation, newAttributes);
debug('Performing %s: %j', operation, newAttributes);
if (!options) options = {};

@@ -237,3 +240,3 @@

} else {
log.info('coll: Ignoring out-of-date update', existingModel.toJSON(), newAttributes);
debug('Ignoring out-of-date update. existing=%j, new=%j', existingModel.attributes, newAttributes);
}

@@ -243,3 +246,3 @@ },

patch: function(id, newModel, options) {
log.info('coll: Request to patch ' + id + ' with ', newModel, options);
debug('Request to patch %s with %j', id, newModel);

@@ -259,3 +262,3 @@ var self = this;

if(!existing) {
log.info('coll: Unable to find model ' + id);
debug('Unable to find model %s', id);
return;

@@ -297,3 +300,3 @@ }

if(!existing) {
log.info('coll: Unable to find model ' + id);
debug('Unable to find model id=%s', id);
return;

@@ -320,3 +323,3 @@ }

default:
log.info("coll: Unknown operation " + operation + ", ignoring");
debug("Unknown operation %s, ignoring", operation);

@@ -323,0 +326,0 @@ }

@@ -8,2 +8,4 @@ "use strict";

var TemplateSubscription = require('./template-subscription');
var fayeDebug = require('debug-proxy')('gtc:faye');
var debug = require('debug-proxy')('gtc:client');

@@ -15,10 +17,12 @@ /* @const */

Faye.logger = {};
var logLevels = ['fatal', 'error', 'warn', 'info', 'debug'];
Faye.logger = {
fatal: log.error.bind(log),
error: log.error.bind(log),
warn: log.warn.bind(log)
};
/* TODO: Add an option to add faye debug logging */
logLevels.forEach(function(level) {
var llevel = level == 'fatal' ? 'error' : level;
Faye.logger[level] = log[llevel].bind(log);
});
if (fayeDebug.enabled) {
Faye.logger.info = fayeDebug;
Faye.logger.debug = fayeDebug;
}

@@ -28,3 +32,3 @@ var ErrorLogger = function() {};

if(message.error) {
log.error('rtc: Bayeux error', message);
debug('Bayeux error: %j', message);
}

@@ -50,3 +54,3 @@

this.client.clientId = null;
log.info("rtc: Rehandshaking realtime connection");
debug("Rehandshaking realtime connection");

@@ -68,3 +72,3 @@ this.authProvider(function(authInfo) {

this.client.clientId = message.clientId;
log.info("rtc: Realtime reestablished. New id is " + this.client.clientId);
debug("Realtime reestablished. New id is %s", this.client.clientId);
this.client.trigger('newConnectionEstablished');

@@ -204,3 +208,3 @@ }

log.info('rtc: Subscription to ' + message.subscription + ' took ' + totalTime + 'ms');
debug('Subscription to %s took %sms', message.subscription, totalTime);
}

@@ -290,3 +294,3 @@ }

client.on('transport:down', function() {
log.info('rtc: transport down');
debug('Transport down');
self._transportDown();

@@ -296,3 +300,3 @@ });

client.on('transport:up', function() {
log.info('rtc: transport up');
debug('Transport up');
self._transportUp();

@@ -309,7 +313,7 @@ });

if(clientIdOnPing === this.clientId) {
log.info("rtc: Client reset requested");
debug("Client reset requested");
this.clientId = null;
this.client.reset();
} else {
log.info("rtc: Ignoring reset request as clientId has changed.");
debug("Ignoring reset request as clientId has changed.");
}

@@ -320,3 +324,3 @@ },

var fayeChannel = FAYE_PREFIX + channel;
log.info('rtc: Subscribing to ' + channel);
debug('Subscribing to %s', channel);

@@ -355,3 +359,3 @@ return this.client.subscribe(fayeChannel, callback, context);

this.trigger('testConnection', reason);
log.info('rtc: Testing connection due to ' + reason);
debug('Testing connection due to %s', reason);
}

@@ -374,7 +378,7 @@

delete self._pingOutstanding;
log.info('rtc: Server ping succeeded');
debug('Server ping succeeded');
}, function(error) {
delete self._pingOutstanding;
log.warn('rtc: Server ping failed: ', error);
debug('Server ping failed: %j', error);
self.reset(originalClientId);

@@ -401,3 +405,3 @@ });

self._persistentOutage = true;
log.info('rtc: persistent outage');
debug('Persistent outage');
self.trigger('connectionFailure');

@@ -421,3 +425,3 @@ }

log.info('rtc: persistent outage restored');
debug('Persistent outage restored');
this.trigger('connectionRestored');

@@ -424,0 +428,0 @@ }

@@ -79,4 +79,5 @@ 'use strict';

_resubscribe: function(channel) {
this._unsubscribe();
this.trigger('resubscribe', channel);
this._unsubscribe();
var self = this;

@@ -83,0 +84,0 @@ this.subscription = this.client.subscribe(channel, this.options.onMessage);

{
"name": "gitter-realtime-client",
"version": "0.3.4",
"version": "0.3.5",
"description": "Gitter Realtime Client",

@@ -21,2 +21,3 @@ "main": "lib/index.js",

"backbone-url-resolver": "^0.1.1",
"debug-proxy": "^0.1.2",
"gitter-faye": "1.1.0-h",

@@ -23,0 +24,0 @@ "loglevel": "^1.2.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc