Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Sorry if my terminology fails me, here. I pretty sure it's the reason I can't find an answer (or didn't recognize a valid answer when I had fount it)

I am writing a web based application using SignalR. There will be many (around 350) operators using the system and I need to communicate data changes, as well as data locks (no two operators can have the same record open for edit for eg).

I have several controls that require the connection, so I'm trying to manage a single shared connection script I can include with the script manager.

The startup is simple enough:
JavaScript
var hubPromise, connection, signalrStartDoneFunctions = [];

// function in StartupFunctions are called on doc.ready (and after partial postbacks)
StartupFunctions.push(function () {

	connection = $.connection.adminServicesHub;

	//Used to confirm that the connection is open
    hubPromise = connection.hub;

    hubPromise.start().done(function () {
    	//signalrStartDoneFunctions contains function that, unlike StartupFunctions, require the singlar connection to be started
		$.each(signalrStartDoneFunctions, function () {
			this();
		});
	});
});


The way I have declared client-side functions is with jQuery.extend:

JavaScript
$.extend(connection.client, {
    pulseNewUserPanel: pulseNewUserPanelClient,
    pulseExistingUserPanel: pulseExistingUserPanelClient
}


I want to be able to declare these per control too. Each instance of the controls should have it's own functions to add.

What is the best way to manage this? Ideally I would like to ensure that they are there before connection.hub.start(). That way I can perform some checks on startup and alert the client if I need to.

Can I set these up via an array as I do with the startup functions? Any advice would be helpful. Up until this point I've pretty much got all my answers from google :S

Thanks ^_^
Andy
Posted
Comments
kellyapt1 13-Aug-15 15:06pm    
One approach would be to have a function that each of the controls calls which would keep a count of the number of controls that have called it. Once that number has been reached and the document is ready then the call would be made to connection.hub.start().

See an example here: http://jsfiddle.net/kellyapt1/o1puf0u6/
Andy Lanng 14-Aug-15 4:02am    
The left side of the extend definition should be an anonymous function set up by signalr, but it should work the same. I'll give it a go :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900