Skip to content

Commit

Permalink
Add sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof-Cieslak committed Dec 13, 2018
1 parent 74d33df commit c0f9317
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Saturn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Saturn.Extensions.Turbolink
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "TurbolinksSample", "sample\TurbolinksSample\TurbolinksSample.fsproj", "{9FEB1575-C6AE-4746-BAE9-EF458FBCD07E}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ChannelsSample", "sample\ChannelsSample\ChannelsSample.fsproj", "{CE022EB0-A55F-466E-A085-4C328436C8E0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -190,6 +192,18 @@ Global
{9FEB1575-C6AE-4746-BAE9-EF458FBCD07E}.Release|x64.Build.0 = Release|Any CPU
{9FEB1575-C6AE-4746-BAE9-EF458FBCD07E}.Release|x86.ActiveCfg = Release|Any CPU
{9FEB1575-C6AE-4746-BAE9-EF458FBCD07E}.Release|x86.Build.0 = Release|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Debug|x64.ActiveCfg = Debug|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Debug|x64.Build.0 = Debug|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Debug|x86.ActiveCfg = Debug|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Debug|x86.Build.0 = Debug|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Release|Any CPU.Build.0 = Release|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Release|x64.ActiveCfg = Release|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Release|x64.Build.0 = Release|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Release|x86.ActiveCfg = Release|Any CPU
{CE022EB0-A55F-466E-A085-4C328436C8E0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8DBA089A-7C24-4E87-870B-E0774654F376} = {F2C8C347-845F-42E4-A702-7381C4B4087F}
Expand All @@ -204,5 +218,6 @@ Global
{04D58505-239F-44B8-A640-9119134B7A4C} = {F2C8C347-845F-42E4-A702-7381C4B4087F}
{17D976F0-4AC6-47AA-BA6C-E6C90FAFEF62} = {F2C8C347-845F-42E4-A702-7381C4B4087F}
{9FEB1575-C6AE-4746-BAE9-EF458FBCD07E} = {511FB392-5714-4028-97F3-F883F81B43DB}
{CE022EB0-A55F-466E-A085-4C328436C8E0} = {511FB392-5714-4028-97F3-F883F81B43DB}
EndGlobalSection
EndGlobal
13 changes: 13 additions & 0 deletions sample/ChannelsSample/ChannelsSample.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<DebugType>portable</DebugType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Saturn\Saturn.fsproj" />
<Compile Include="Program.fs" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
36 changes: 36 additions & 0 deletions sample/ChannelsSample/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module WindowsAuthSample

open Saturn
open Giraffe.ResponseWriters
open Giraffe.Core
open FSharp.Control.Tasks.V2
open Saturn.Channels



let browserRouter = router {
forward "" (text "Hello world")
}

let sampleChannel = channel {
join (fun ctx -> task {return Ok})

handle "topic" (fun ctx res msg ->
task {
printfn "%A" msg
return ()
}
)
}


let app = application {
use_router browserRouter
url "http://localhost:8085/"
add_channel "/channel" sampleChannel
}

[<EntryPoint>]
let main _ =
run app
0 // return an integer exit code
3 changes: 3 additions & 0 deletions sample/ChannelsSample/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FSharp.Core
Giraffe
Microsoft.AspNetCore
1 change: 1 addition & 0 deletions src/Saturn/Application.fs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ module Application =
{ state with
ServicesConfig = xmlService :: state.ServicesConfig }

///Registers channel for given url.
[<CustomOperation("add_channel")>]
member __.AddChannel (state, url: string, channel: IChannel ) =
{ state with
Expand Down
2 changes: 1 addition & 1 deletion src/Saturn/Channels.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Channels =
abstract member HandleMessage: HttpContext * WebSocketReceiveResult * Message -> Task<unit>
abstract member Terminate: HttpContext -> Task<unit>

type internal SocketMiddleware(next : RequestDelegate, serializer: IJsonSerializer, path: string, channel: IChannel) =
type SocketMiddleware(next : RequestDelegate, serializer: IJsonSerializer, path: string, channel: IChannel) =
do sockets.Add(path, ConcurrentDictionary())

member __.Invoke(ctx : HttpContext) =
Expand Down

0 comments on commit c0f9317

Please sign in to comment.