You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
52 lines
1.5 KiB
11 years ago
|
'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;
|
||
|
}
|
||
|
};
|
||
|
});
|
||
|
|