-
Notifications
You must be signed in to change notification settings - Fork 0
SignalR JS Client
The SignalR javascript client comes in the form of a jQuery plugin.
Include the following scripts on your page:
<script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR.min.js" type="text/javascript"></script>NOTE: In an MVC application use Url.Content to reference scripts.
Creates a new connection.
- Returns a connection.
- NOTE: There is currently no cross domain support
Example
var connection = $.connection('/echo');-
handler(data) - A function to execute each time data is received.
-
Returns a connection.
-
NOTE: data is a JSON object
Example
connection.received(function(data) {
console.log(data);
});
-
handler(error) - A function to execute each time an error occurs.
-
Returns a connection.
Example
connection.error(function(error) {
console.warn(error);
});
-
handler() - A function to execute each time the connection has successfully reconnected.
-
Returns a connection.
Example
connection.reconnected(function(data) {
console.log(data);
});
- handler - A function to execute before the transport establishes a connection to the server.
Starts the connection using the default settings.
- NOTE: A connection cannot send or receive messages until the start method has been called and the connection successfully established.
Example
connection.start();
Starts the connection using the default settings and executes the passed callback once the connection has been established.
- callback - A callback function to invoke when the connection has been successfully established.**
Example
connection.start(function() {
console.log("connection started!");
});
Starts the connection using the passed settings.
-
settings - A set of key value pairs that configure the connection. All settings are optional.
- transport - Details of the transport to use. Can be a known transport name (that maps to a member on signalR.transports), a transport object, or an array of each. If an array, each transport will be tried until one succeeds or all fail. Defaults to "auto", which will try all transports on signalR.transports until one succeeds or all fail.
- callback - A callback function to invoke when the connection has been successfully established. Defaults to undefined (no callback).
Example
// Only try longPolling, by name
connection.start({ transport: 'longPolling' });
// Only try webSockets, by object
connection.start({ transport: signalR.transports.webSockets });
// Try longPolling then webSockets
connection.start({ transport: ['longPolling','webSockets'] });
Starts the connection using the passed settings, and executes the passed callback once the connection has been established.
-
settings - A set of key value pairs that configure the connection. All settings are optional.
- transport - Details of the transport to use. Can be a known transport name, a transport object, or an array of each. If an array, each transport will be tried until one succeeds or all fail. Defaults to "auto", which will try all transports on signalR.transports until one succeeds or all fail.
- callback - A callback function to invoke when the connection has been successfully established.
- callback A callback function to invoke when the connection has been successfully established.
Example
connection.start({ transport: 'longPolling' }, function() {
console.log('connection started!');
});
- data - data to send over the connection.
Example
connection.send("Hello World");
- Gets or sets the client id for the current connection.
- Gets or sets the message id for the current connection.