From da901998b4498f9eb4c749f2b39a0ac9d0648823 Mon Sep 17 00:00:00 2001 From: Gabriel Mendoza Date: Wed, 14 Feb 2024 20:07:56 -0500 Subject: [PATCH] Add EventSource API support --- Browser.sln | 15 +++++++ build.fsx | 3 +- src/EventSource/Browser.EventSource.fs | 50 ++++++++++++++++++++++ src/EventSource/Browser.EventSource.fsproj | 17 ++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/EventSource/Browser.EventSource.fs create mode 100644 src/EventSource/Browser.EventSource.fsproj diff --git a/Browser.sln b/Browser.sln index 966fe6d..e141435 100644 --- a/Browser.sln +++ b/Browser.sln @@ -51,6 +51,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Browser.IntersectionObserve EndProject Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Browser.ResizeObserver", "src\ResizeObserver\Browser.ResizeObserver.fsproj", "{CFEB63B4-8CDC-4FD2-B0C5-4D09BE37D00B}" EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Browser.EventSource", "src\EventSource\Browser.EventSource.fsproj", "{D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -337,6 +339,18 @@ Global {CFEB63B4-8CDC-4FD2-B0C5-4D09BE37D00B}.Release|x64.Build.0 = Release|Any CPU {CFEB63B4-8CDC-4FD2-B0C5-4D09BE37D00B}.Release|x86.ActiveCfg = Release|Any CPU {CFEB63B4-8CDC-4FD2-B0C5-4D09BE37D00B}.Release|x86.Build.0 = Release|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Debug|x64.ActiveCfg = Debug|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Debug|x64.Build.0 = Debug|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Debug|x86.ActiveCfg = Debug|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Debug|x86.Build.0 = Debug|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Release|Any CPU.Build.0 = Release|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Release|x64.ActiveCfg = Release|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Release|x64.Build.0 = Release|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Release|x86.ActiveCfg = Release|Any CPU + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -364,6 +378,7 @@ Global {937E046F-818B-47E1-930F-3B0A0068D83B} = {D9506C1D-DF7A-4975-B4A9-80B2EF4ADA2E} {B74AA790-1B29-448A-8D75-8399C6C86C71} = {D9506C1D-DF7A-4975-B4A9-80B2EF4ADA2E} {CFEB63B4-8CDC-4FD2-B0C5-4D09BE37D00B} = {D9506C1D-DF7A-4975-B4A9-80B2EF4ADA2E} + {D79F73C5-8BE4-4D57-8CCD-28CC99B1A9A1} = {D9506C1D-DF7A-4975-B4A9-80B2EF4ADA2E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F62BBD2A-9074-44FF-8208-43DA064745DE} diff --git a/build.fsx b/build.fsx index 9d56376..9e65cb8 100644 --- a/build.fsx +++ b/build.fsx @@ -29,6 +29,7 @@ let packages = "IndexedDB" "IntersectionObserver" "ResizeObserver" + "EventSource" ] let ignoreCaseEquals (str1: string) (str2: string) = @@ -54,4 +55,4 @@ match args with if publish then pushFableNuget (projDir file) [] doNothing | _ -> () - \ No newline at end of file + diff --git a/src/EventSource/Browser.EventSource.fs b/src/EventSource/Browser.EventSource.fs new file mode 100644 index 0000000..517140a --- /dev/null +++ b/src/EventSource/Browser.EventSource.fs @@ -0,0 +1,50 @@ +namespace rec Browser.Types + +open System +open Fable.Core + +type EventSourceState = + | CONNECTING = 0 + | OPEN = 1 + | CLOSED = 2 + +[] +type EventSource = + inherit EventTarget + abstract readyState: EventSourceState + abstract url: string + abstract withCredentials: bool + + abstract close: unit -> unit + + abstract onerror: (Event -> unit) with get, set + abstract onmessage: (MessageEvent -> unit) with get, set + abstract onopen: (Event -> unit) with get, set + + [] + abstract addEventListener_error: listener: (Event -> unit) * ?useCapture: bool -> unit + + [] + abstract addEventListener_message: listener: (MessageEvent -> unit) * ?useCapture: bool -> unit + + [] + abstract addEventListener_open: listener: (Event -> unit) * ?useCapture: bool -> unit + +[] +type EventSourceOptions = + abstract withCredentials: bool with get, set + +[] +type EventSourceType = + [] + abstract Create: url: string * ?options: EventSourceOptions -> EventSource + +namespace Browser + +open Fable.Core +open Browser.Types + +[] +module EventSource = + [] + let EventSource: EventSourceType = jsNative diff --git a/src/EventSource/Browser.EventSource.fsproj b/src/EventSource/Browser.EventSource.fsproj new file mode 100644 index 0000000..01d5a93 --- /dev/null +++ b/src/EventSource/Browser.EventSource.fsproj @@ -0,0 +1,17 @@ + + + Fable.Browser.EventSource + netstandard2.0 + true + fable;fable-binding;fable-javascript + + + + + + + + + + + \ No newline at end of file