awv3
Version:
⚡ AWV3 embedded CAD
70 lines (60 loc) • 2.41 kB
JavaScript
import $ from 'jquery';
// Thank you very much, Microsoft ...
window.jQuery = $;
require('ms-signalr-client');
export default function(scope) {
var signalR = $.signalR;
function makeProxyCallback(hub, callback) {
return function() {
callback.apply(hub, $.makeArray(arguments));
};
}
function registerHubProxies(instance, shouldSubscribe) {
var key, hub, memberKey, memberValue, subscriptionMethod;
for (key in instance) {
if (instance.hasOwnProperty(key)) {
hub = instance[key];
if (!hub.hubName) continue;
if (shouldSubscribe) {
subscriptionMethod = hub.on;
} else {
subscriptionMethod = hub.off;
}
for (memberKey in hub.client) {
if (hub.client.hasOwnProperty(memberKey)) {
memberValue = hub.client[memberKey];
if (!$.isFunction(memberValue)) continue;
subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue));
}
}
}
}
}
$.hubConnection.prototype.createHubProxies = function() {
var proxies = {};
this
.starting(function() {
registerHubProxies(proxies, true);
this._registerSubscribedHubs();
})
.disconnected(function() {
registerHubProxies(proxies, false);
});
proxies.clientHub = this.createHubProxy('clientHub');
proxies.clientHub.client = {};
proxies.clientHub.server = {
init: function(debugging, PauseAllowed, TimeOut, Rebuild) {
return proxies.clientHub.invoke.apply(proxies.clientHub, $.merge(['Init'], $.makeArray(arguments)));
},
ping: function() {
return proxies.clientHub.invoke.apply(proxies.clientHub, $.merge(['Ping'], $.makeArray(arguments)));
},
send: function(data) {
return proxies.clientHub.invoke.apply(proxies.clientHub, $.merge(['Send'], $.makeArray(arguments)));
}
};
return proxies;
};
scope._hub = $.hubConnection('/signalr', { useDefaultPath: false });
scope._proxy = scope._hub.createHubProxies();
}