mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
Bind any collection to SignalR with a single call.
This commit is contained in:
parent
87a5dc7869
commit
a6aba16902
13 changed files with 106 additions and 26 deletions
|
@ -1,7 +1,15 @@
|
|||
"use strict";
|
||||
(function ($) {
|
||||
|
||||
var connection = $.connection('/signalr/series');
|
||||
Backbone.Collection.prototype.BindSignalR = function (options) {
|
||||
|
||||
if (!options || !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) {
|
||||
|
@ -19,18 +27,21 @@
|
|||
|
||||
};
|
||||
|
||||
|
||||
var connection = $.connection(options.url);
|
||||
|
||||
connection.stateChanged(function (change) {
|
||||
|
||||
console.log('signalR [{0}]'.format(_getStatus(change.newState)));
|
||||
console.debug('{0} [{1}]'.format(options.url, _getStatus(change.newState)));
|
||||
});
|
||||
|
||||
connection.received(function (data) {
|
||||
console.log(data);
|
||||
connection.received(function () {
|
||||
self.fetch();
|
||||
});
|
||||
|
||||
connection.error(function (error) {
|
||||
console.warn(error);
|
||||
});
|
||||
connection.start({ transport: ['longPolling'] });
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
connection.start();
|
||||
})(jQuery);
|
Loading…
Add table
Add a link
Reference in a new issue