What about defining the hub globally so you can use anywhere?
var srhub = $.connection.chatHub;
$(function () {
$.connection.hub.url = 'url here';
$.connection.hub.start().done(function () {});
/more code here removed
};
Pergunta
I am banging my head against a wall trying to separate signalr from the $(function () event. I want to be able to start my signalr connection on demand from an external script (this is currently in a requirejs module). Here is my code:
main.js
uiShow = function (show, inFullpage) {
//Start SignalR here
//more code here removed
sr.js
$(function () {
var srhub = $.connection.chatHub;
$.connection.hub.url = 'url here';
$.connection.hub.start().done(function () {});
/more code here removed
};
The problem is that I have been unable to find a way to access the connection object from within main.js or anyway to trigger the connection of signalr from main.js.
What I want is something like this:
main.js
uiShow = function (show, inFullpage) {
chatconnect();
//more code here removed
sr.js
$(function () {
var srhub = $.connection.chatHub;
$.connection.hub.url = 'url here';
}
function chatconnect() {
$.connection.hub.start().done(function () {});
}
The $.connection object is not accessible anywhere other than during the load of the script though so I cannot get it to work. Thanks in advance
Solução
What about defining the hub globally so you can use anywhere?
var srhub = $.connection.chatHub;
$(function () {
$.connection.hub.url = 'url here';
$.connection.hub.start().done(function () {});
/more code here removed
};