-
-
Save ddombrow/9763041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (document, $, undefined) { | |
"use strict"; | |
$(document).ready(function () { | |
var tryFS; | |
$.connection.hub.url = 'http://localhost:8081/signalr'; | |
tryFS = $.connection.tryFS; | |
if (tryFS) { | |
// Define the `addMessage` function on the client. | |
tryFS.client.addMessage = function (value) { | |
$('#results').append('<p>' + value + '</p>'); | |
console.log('Server called addMessage(' + value + ')'); | |
}; | |
// Kick off the hub. | |
$.connection.hub.start(). | |
done(function () { | |
$('#submit').on('click', function () { | |
tryFS.server.send($('#source').val()); | |
}); | |
}); | |
} | |
else { | |
console.log('No hub found by the name of tryFS'); | |
} | |
}); | |
})(document, jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace tryfs | |
open System | |
open Owin | |
open Microsoft.AspNet.SignalR | |
open Microsoft.Owin.Hosting | |
// Use ImpromptuInterface for dynamic support in the TryFS.Send method. | |
// Could also use http://fssnip.net/2U or http://fssnip.net/2V | |
open ImpromptuInterface.FSharp | |
// Define a Hub | |
type TryFS() = | |
inherit Hub() | |
member x.Send(message: string) : unit = | |
x.Clients.All?addMessage(message) | |
// Create a Startup class with a Configuration member taking an `Owin.IAppBuilder`. | |
type Startup() = | |
member x.Configuration(app: Owin.IAppBuilder) = | |
let config = new HubConfiguration(EnableCrossDomain = true) | |
app.MapHubs(config) |> ignore | |
module Program = | |
[<EntryPoint>] | |
let main args = | |
let url = "http://localhost:8081/" | |
let disposable = WebApplication.Start<Startup>(url) | |
Console.WriteLine("Server running on " + url) | |
Console.WriteLine("Press Enter to stop.") | |
Console.ReadLine() |> ignore | |
disposable.Dispose() | |
0 // completed successfully |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>SignalR + F#</title> | |
</head> | |
<body> | |
<input type="text" id="source" /> | |
<button type="button" id="submit" value="submit">Send</button> | |
<div id="results"></div> | |
<script src="Scripts/jquery.signalR-1.0.1.min.js"></script> | |
<script src="http://localhost:8081/signalr/hubs" type="text/javascript"></script> | |
<script src="app/app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment