mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-31 04:00:18 -07:00
signalr cleanup
This commit is contained in:
parent
feda4a9b67
commit
25e2c98c45
219 changed files with 2035 additions and 1495 deletions
|
@ -5,59 +5,29 @@ define(
|
|||
], function () {
|
||||
|
||||
_.extend(Backbone.Collection.prototype, {
|
||||
bindSignalR: function (options) {
|
||||
bindSignalR: function () {
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var collection = this;
|
||||
|
||||
if (!options.url) {
|
||||
console.assert(this.url, 'url must be provided or collection must have url');
|
||||
options.url = this.url.replace('api', 'signalr');
|
||||
}
|
||||
var processMessage = function (options) {
|
||||
|
||||
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;
|
||||
}
|
||||
var model = new collection.model(options.resource, {parse: true});
|
||||
collection.add(model, {merge: true});
|
||||
console.log(options.action + ": %O", options.resource);
|
||||
};
|
||||
|
||||
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:
|
||||
require(
|
||||
[
|
||||
'longPolling'
|
||||
] });
|
||||
'app'
|
||||
], function (app) {
|
||||
collection.listenTo(app.vent, 'server:' + collection.url.replace('/api/', ''), processMessage)
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
unbindSignalR: function () {
|
||||
|
||||
if(this.signalRconnection){
|
||||
this.signalRconnection.stop();
|
||||
delete this.signalRconnection;
|
||||
}
|
||||
|
||||
}});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue