Skip to content
cjbhaines edited this page Apr 15, 2013 · 8 revisions

Introduction

SignalRProxyGenerator is inspired by the tool David Fowler created inside the SignalR examples to generate hub proxies. This is useful for generating your proxies at build time so you can include them in your minification process. I found his tool difficult to use and it didn't fully suit my needs due to requiring meta data and having confusing command line arguments. Hopefully you will find this easier to use.

Parameters

  • -p --path Location of the bin folder that contains the dll's containing your hubs
  • -o --output The location of the JavaScript output file
  • -u --url The URL path of your application to the SignalR address
  • -m --meta CSV list of any meta data you would like printint at the top of the output

Path The generator will inspect any DLL's in this path and look for classes inheriting from Hub. Typical usage would be a bin folder.

Output The output location of the JavaScript file produced by the generator.

URL This is the path to the magic signalr address. It must include your application directory on the server it will be installed on. For example, if you application runs at http://yourdomain.com/YourApp/signalr, the url would be "/YourApp/signalr.

Meta If you are using a framework like Cassette, then you will will need to specify any dependencies as // reference tags. The meta data allows you to specify anything at the top of your output file as a CSV list. Each item in the list will be output on a separate line.

Example Usage

As a post build event:

PathToGenerator\SignalRProxyGenerator.exe -u "/YourApp/signalr" -p $(ProjectDir)\bin -o $(ProjectDir)\SampleOutput.js -m "// @reference ~/jquery,// @reference ~/SignalR"

URL Tips

Specifying the URL as part of the hub proxy generation isn't always ideal, especially if your development environment uses a different installation path to your production servers. This is easily overwritten inside you applications though. Here is a nice little AngularJS module you could use to do that:

angular .module('YourNameSpace.SignalRLocator', []) .factory('signalRLocator', ['$location', function ($location) { return { getSignalRAddress: function () { var absUrl = $location.absUrl(); var split = absUrl.split('/'); var baseUrl = split[0] + '//' + split[2] + '/' + split[3] + '/'; return baseUrl + "signalr"; } }; } ])

Controller usage:

(function (namespace) { namespace.Controller = function ($scope, signalRLocator) { $.connection.hub.url = signalRLocator.getSignalRAddress(); })

Clone this wiki locally