Skip to content

ChrisDobby/Chrisjdobson.Websharper.SignalR

Repository files navigation

Chrisjdobson.Websharper.SignalR

Build status

A SignalR extension for WebSharper.

NuGet

Usage

Create a SignalR connection (to a hub called chatHub) like this:

let s = SignalR.New "chatHub"

Add functions to receive like this:

s |> SignalR.Receive<Msg> "broadcastMessage" (fun m -> messageList.Add m)
  |> SignalR.Receive<Msg> "broadcastMessage" (fun m -> JavaScript.Alert "Message Received")

And send like this:

s |> SignalR.Send<Msg> 
		"chat" 
		{User = "User1"; Message = "Hello"}
        (fun _ -> ()) // called when successfully sent
        (fun e -> JavaScript.Alert e.Message) // called when error sending

Configure connection:

let startup = StartupConfig()
// To make a cross domain connection use Connection.New("www.abc.com")
Connection.New() 
    |> Connection.WithLogging
    |> Connection.ConnectionError (fun e -> JavaScript.Alert e)
    |> Connection.Starting (fun _ -> JavaScript.Alert "Starting")
    |> Connection.Received (fun _ -> JavaScript.Alert "Received")
    |> Connection.ConnectionSlow (fun _ -> JavaScript.Alert "Slow connection")
    |> Connection.Reconnecting (fun _ -> JavaScript.Alert "Reconnecting")
    |> Connection.Reconnected (fun _ -> JavaScript.Alert "Reconnected")
    |> Connection.Disconnected (fun _ -> JavaScript.Alert "Disconnected")
	|> Connection.StateChanged (fun s -> JavaScript.Alert ("from " + StateText s.OldState + " to " + StateText s.NewState))
    |> Connection.Start startup (fun _ -> ()) (fun e -> JavaScript.Alert ("connection error: " + e.Message))

Samples

See the ChatSample and ProcessSample applications in the solution for simple examples

About

SignalR extension for WebSharper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published