1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-25 01:11:43 +00:00
Radarr/UI/Shared/SignalRBroadcaster.js
2013-09-11 17:42:53 -07:00

51 lines
1.5 KiB
JavaScript

'use strict';
define(
[
'app',
'signalR'
], function () {
return {
appInitializer: function () {
console.log('starting signalR');
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("/signalr");
this.signalRconnection.stateChanged(function (change) {
console.debug('SignalR: [{0}]'.format(getStatus(change.newState)));
});
this.signalRconnection.received(function (message) {
require(
[
'app'
], function (app) {
app.vent.trigger('server:' + message.name, message.body);
})
});
this.signalRconnection.start({ transport:
[
'longPolling'
] });
return this;
}
};
});