Last active
August 30, 2022 07:56
-
-
Save aaron-comyn/c9c44a029c05e866018fd42b412efae2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#r "packages/Owin/lib/net40/Owin.dll" | |
#r "packages/Microsoft.Owin/lib/net45/Microsoft.Owin.dll" | |
#r "packages/Microsoft.Owin.Cors/lib/net45/Microsoft.Owin.Cors.dll" | |
#r "packages/Microsoft.Owin.Hosting/lib/net45/Microsoft.Owin.Hosting.dll" | |
#r "packages/Microsoft.Owin.Security/lib/net45/Microsoft.Owin.Security.dll" | |
#r "packages/Microsoft.AspNet.SignalR.Core/lib/net45/Microsoft.AspNet.SignalR.Core.dll" | |
#r "packages/Microsoft.AspNet.Cors/lib/net45/System.Web.Cors.dll" | |
#r "packages/Newtonsoft.Json/lib/net45/Newtonsoft.Json.dll" | |
#r "packages/Suave/lib/net40/Suave.dll" | |
open Microsoft.Owin | |
open Microsoft.Owin.Builder | |
open Microsoft.Owin.Cors | |
open Microsoft.Owin.Hosting | |
open Microsoft.AspNet.SignalR | |
open Microsoft.AspNet.SignalR.Hubs | |
open Suave | |
open Suave.Owin | |
open Suave.Filters | |
open Suave.Files | |
open Suave.Operators | |
open Suave.Successful | |
open System.Net | |
module SignalServer = | |
type Connection() = | |
inherit PersistentConnection() | |
override x.OnConnected(req, id) = base.OnConnected(req, id) | |
override x.OnReceived(req, id, data) = base.OnReceived(req, id, data) | |
[<HubName("myhub")>] | |
type MyHub() = | |
inherit Hub() | |
override x.OnConnected() = base.OnConnected() | |
// Define a custom functions | |
member x.CustomFunction() = () | |
type Startup() = | |
member x.Configuration(app : Owin.IAppBuilder) = | |
let config = new HubConfiguration(EnableDetailedErrors = true) | |
Owin.CorsExtensions.UseCors(app, CorsOptions.AllowAll) |> ignore | |
Owin.OwinExtensions.MapSignalR<Connection>(app, "/signalrConn") |> ignore | |
Owin.OwinExtensions.MapSignalR(app, "/signalrHub", config) |> ignore | |
() | |
let app = | |
let builder = new AppBuilder() | |
let startup = new Startup() | |
startup.Configuration(builder) | |
builder.Build() | |
let main argv = | |
let app = | |
choose [ | |
GET >=> | |
choose [ | |
path "/demo" >=> file (Files.resolvePath __SOURCE_DIRECTORY__ "test.html") | |
OwinApp.ofAppFunc "/" SignalServer.app | |
] | |
] | |
startWebServer defaultConfig app | |
main () |
This file contains hidden or 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
source https://www.nuget.org/api/v2 | |
nuget Microsoft.AspNet.Cors 5.0.0 | |
nuget Microsoft.AspNet.SignalR | |
nuget Microsoft.AspNet.WebApi.Cors | |
nuget Microsoft.Owin.Cors | |
nuget Microsoft.Owin.Hosting | |
nuget Owin.Extensions | |
nuget Suave |
This file contains hidden or 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 xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>JavascriptTestUI</title> | |
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.min.js"></script> | |
<script src="http://ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-1.1.1.min.js"></script> | |
<script src="/signalrHub/hubs" type="text/javascript"></script> | |
<script type="text/javascript"> | |
$(document).ready(function () { | |
var hub; | |
$.connection.hub.url = '/signalrHub'; | |
console.log('attempting to initialize hub...'); | |
hub = $.connection.myhub; | |
if (hub) { | |
$.connection.hub.start(). | |
done(function () { | |
console.log('hub initialized'); | |
$('#submit').on('click', function () { | |
hub.server.customFunction(); | |
}); | |
}); | |
} | |
else { | |
console.log('hub not found'); | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<button type="button" id="submit" value="submit">Send</button> | |
<div id="results"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An incomplete demo of SignalR in Suave:
http://localhost:8083/signalrHub/hubs <-- confirms that the hub scripts are being generated
http://localhost:8083/demo <-- shows the failing ping calls and lack of hub initialization