mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 02:37:08 -07:00
removed leak from signalr
This commit is contained in:
parent
5327068557
commit
66ce8e8b27
3 changed files with 61 additions and 56 deletions
|
@ -4,62 +4,62 @@ define(
|
|||
'signalR'
|
||||
], function () {
|
||||
|
||||
_.extend(Backbone.Collection.prototype, {BindSignalR: function (options) {
|
||||
_.extend(Backbone.Collection.prototype, {
|
||||
bindSignalR: function (options) {
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (!options.url) {
|
||||
console.assert(this.url, 'url must be provided or collection must have url');
|
||||
options['url'] = this.url.replace('api', 'signalr');
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
var _getStatus = function (status) {
|
||||
switch (status) {
|
||||
case 0:
|
||||
return 'connecting';
|
||||
case 1:
|
||||
return 'connected';
|
||||
case 2:
|
||||
return 'reconnecting';
|
||||
case 4:
|
||||
return 'disconnected';
|
||||
default:
|
||||
throw 'invalid status ' + status;
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var connection = $.connection(options.url);
|
||||
|
||||
connection.stateChanged(function (change) {
|
||||
console.debug('{0} [{1}]'.format(options.url, _getStatus(change.newState)));
|
||||
});
|
||||
|
||||
connection.received(function (message) {
|
||||
console.debug(message);
|
||||
|
||||
if (options.onReceived) {
|
||||
var context = options.context || self;
|
||||
|
||||
options.onReceived.call(context, message);
|
||||
if (!options.url) {
|
||||
console.assert(this.url, 'url must be provided or collection must have url');
|
||||
options.url = this.url.replace('api', 'signalr');
|
||||
}
|
||||
|
||||
else {
|
||||
var self = this;
|
||||
|
||||
var _getStatus = function (status) {
|
||||
switch (status) {
|
||||
case 0:
|
||||
return 'connecting';
|
||||
case 1:
|
||||
return 'connected';
|
||||
case 2:
|
||||
return 'reconnecting';
|
||||
case 4:
|
||||
return 'disconnected';
|
||||
default:
|
||||
throw 'invalid status ' + status;
|
||||
}
|
||||
};
|
||||
|
||||
this.signalRconnection = $.connection(options.url);
|
||||
|
||||
this.signalRconnection.stateChanged(function (change) {
|
||||
console.debug('{0} [{1}]'.format(options.url, _getStatus(change.newState)));
|
||||
});
|
||||
|
||||
this.signalRconnection.received(function (message) {
|
||||
console.debug(message);
|
||||
self.fetch();
|
||||
});
|
||||
|
||||
this.signalRconnection.start({ transport:
|
||||
[
|
||||
'longPolling'
|
||||
] });
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
unbindSignalR: function () {
|
||||
|
||||
if(this.signalRconnection){
|
||||
this.signalRconnection.stop();
|
||||
delete this.signalRconnection;
|
||||
}
|
||||
});
|
||||
|
||||
connection.start({ transport:
|
||||
[
|
||||
'longPolling'
|
||||
] });
|
||||
|
||||
return this;
|
||||
}});
|
||||
}});
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue