示例#1
0
        /// <summary>
        ///  listen for dispatched messages send by PostMessage
        /// </summary>
        /// <param name="todo"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public async ValueTask <IAsyncDisposable> OnMessage <T>(Func <MessageEvent <T>, ValueTask> todo)
        {
            return(await JsRuntime.AddEventListener(
                       JsObjectRef,
                       "",
                       "message",
                       CallBackInteropWrapper.Create <JsRuntimeObjectRef>(
                           async payload =>
            {
                var eventPayload = new MessageEvent <T>
                {
                    Data = await JsRuntime.GetInstanceProperty <T>(payload, "data").ConfigureAwait(false),
                    Origin = await JsRuntime.GetInstanceProperty <string>(payload, "origin")
                             .ConfigureAwait(false),
                    Source = await JsRuntime.GetInstanceProperty <WindowInterop>(payload, "source",
                                                                                 SerializationSpec).ConfigureAwait(false)
                };
                eventPayload.Source.SetJsRuntime(JsRuntime,
                                                 await JsRuntime.GetInstancePropertyRef(payload, "source").ConfigureAwait(false));

                await todo.Invoke(eventPayload).ConfigureAwait(false);
            },
                           getJsObjectRef: true
                           )).ConfigureAwait(false));
        }
示例#2
0
 /// <summary>
 /// raised when the window is closed
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnContextMenu(Func <CancellableEvent, ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(
                JsObjectRef, "",
                "contextmenu",
                CallBackInteropWrapper.Create <JsRuntimeObjectRef>(
                    async e => { await callback.Invoke(new CancellableEvent(JsRuntime, e)); },
                    getJsObjectRef: true)
                ));
 }
示例#3
0
 /// <summary>
 ///  fire when a window is about to unload its resources. At this point, the document is still visible and the event is still cancelable.
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnBeforeUnload(Func <BeforeUnloadEvent, ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(
                JsObjectRef, "",
                "beforeunload",
                CallBackInteropWrapper.Create <JsRuntimeObjectRef>(
                    async e => { await callback.Invoke(new BeforeUnloadEvent(JsRuntime, e)); },
                    getJsObjectRef: true)
                ));
 }
示例#4
0
 /// <summary>
 /// fires when a window's hash changes
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnHashChange(Func <ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(
                JsObjectRef, "",
                "hashchange",
                CallBackInteropWrapper.Create(
                    async() => { await callback.Invoke(); },
                    getJsObjectRef: false,
                    serializationSpec: false
                    )
                ));
 }
示例#5
0
        private async ValueTask ConfigCallbacks()
        {
            await JsRuntime.AddEventListener(JsObjectRef, "", "onended",
                                             CallBackInteropWrapper.Create(OnEndedCallback, false)).ConfigureAwait(false);

            await JsRuntime.AddEventListener(JsObjectRef, "", "onisolationchange",
                                             CallBackInteropWrapper.Create(OnIsolationChangeCallback, false)).ConfigureAwait(false);

            await JsRuntime.AddEventListener(JsObjectRef, "", "onmute",
                                             CallBackInteropWrapper.Create(OnMuteCallback, false)).ConfigureAwait(false);

            await JsRuntime.AddEventListener(JsObjectRef, "", "onunmute",
                                             CallBackInteropWrapper.Create(OnUnmuteCallback, false)).ConfigureAwait(false);
        }
示例#6
0
 public async ValueTask <IAsyncDisposable> OnStorage(Func <StorageEvent, ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(JsObjectRef, "", "storage",
                                             CallBackInteropWrapper.Create <JsRuntimeObjectRef>(
                                                 async jsObject =>
     {
         var eventContent = await JsRuntime.GetInstanceContent <StorageEvent>(jsObject,
                                                                              new { key = true, oldValue = true, newValue = true, url = true });
         eventContent.Storage = new WindowStorage(JsRuntime,
                                                  await JsRuntime.GetInstancePropertyRef(jsObject, "storageArea"));
         await callback(eventContent);
     },
                                                 getJsObjectRef: true
                                                 )
                                             ));
 }
示例#7
0
 /// <summary>
 /// fired when fresh data is available from an orientation sensor about the current orientation of the device as compared to the Earth coordinate frame. This data is gathered from a magnetometer inside the device
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnDeviceOrientation(Func <DeviceOrientationEvent, ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(
                JsObjectRef, "",
                "deviceorientation",
                CallBackInteropWrapper.Create <DeviceOrientationEvent>(
                    async e => { await callback.Invoke(e); },
                    getJsObjectRef: false,
                    serializationSpec: new
     {
         alpha = "*",
         beta = "*",
         gamma = "*",
         absolute = "*"
     })
                ));
 }
示例#8
0
 /// <summary>
 /// fired at a regular interval and indicates the amount of physical force of acceleration the device is receiving at that time. It also provides information about the rate of rotation, if available.
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnDeviceMotion(Func <DeviceMotionEvent, ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(
                JsObjectRef, "",
                "devicemotion",
                CallBackInteropWrapper.Create <DeviceMotionEvent>(
                    async e => { await callback.Invoke(e); },
                    getJsObjectRef: false,
                    serializationSpec: new
     {
         acceleration = "*",
         accelerationIncludingGravity = "*",
         rotationRate = "*",
         interval = "*"
     })
                ));
 }
示例#9
0
 /// <summary>
 /// dispatched on devices when a user is about to be prompted to "install" a web application. Its associated event may be saved for later and used to prompt the user at a more suitable time.
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnBeforeInstallPrompt(
     Func <BeforeInstallPromptEvent, ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(
                JsObjectRef, "",
                "beforeinstallprompt",
                CallBackInteropWrapper.Create <JsRuntimeObjectRef>(
                    async jsObjectRef =>
     {
         var beforeInstallPromptEvent = new BeforeInstallPromptEvent
         {
             Platforms = await JsRuntime.GetInstanceProperty <string[]>(jsObjectRef, "platforms")
         };
         beforeInstallPromptEvent.SetJsRuntime(JsRuntime, jsObjectRef);
         await callback.Invoke(beforeInstallPromptEvent);
     },
                    getJsObjectRef: true,
                    serializationSpec: false
                    )
                ));
 }
示例#10
0
 /// <summary>
 /// Fired when the visual viewport is scrolled.
 /// </summary>
 /// <param name="todo"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnScroll(Func <ValueTask> todo)
 {
     return(await JsRuntime.AddEventListener(JsObjectRef, "", "scroll", CallBackInteropWrapper.Create(todo)));
 }
 /// <summary>
 /// Fired when the visual viewport is resized.
 /// </summary>
 /// <param name="todo"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnResize(Func <ValueTask> todo)
 {
     return(await JsRuntime.AddEventListener(JsObjectRef, "", "resize", CallBackInteropWrapper.Create(todo)).ConfigureAwait(false));
 }
示例#12
0
 /// <summary>
 /// The unload event is fired when the document or a child resource is being unloaded.
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnUnload(Func <ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(JsObjectRef, "", "unload",
                                             CallBackInteropWrapper.Create(callback, false)));
 }
示例#13
0
 /// <summary>
 /// The scroll event fires when the document view or an element has been scrolled, whether by the user, a Web API, or the user agent.
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnWheel(Func <WheelEvent, ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(JsObjectRef, "", "wheel",
                                             CallBackInteropWrapper.Create(callback,
                                                                           new { deltaX = true, deltaY = true, deltaZ = true, deltaMode = true })));
 }
示例#14
0
 /// <summary>
 /// A popstate event is dispatched to the window every time the active history entry changes between two history entries for the same document. If the history entry being activated was created by a call to history.pushState() or was affected by a call to history.replaceState(), the popstate event's state property contains a copy of the history entry's state object.
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnPopState <T>(Func <T, ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(JsObjectRef, "", "popstate",
                                             CallBackInteropWrapper.Create <PopStateEvent <T> >(async p => await callback(p.State), new { state = "*" })));
 }
示例#15
0
 /// <summary>
 /// The pageshow event is sent to a Window when the browser displays the window's document due to navigation
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnPageShow(Func <PageTransitionEvent, ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(JsObjectRef, "", "pageshow",
                                             CallBackInteropWrapper.Create(callback, new { persisted = true })));
 }
示例#16
0
 /// <summary>
 /// The scroll event fires when the document view or an element has been scrolled, whether by the user, a Web API, or the user agent.
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnScroll(Func <ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(JsObjectRef, "", "scroll",
                                             CallBackInteropWrapper.Create(callback, false)).ConfigureAwait(false));
 }
示例#17
0
 /// <summary>
 /// The orientationchange event is fired when the orientation of the device has changed.
 /// </summary>
 /// <param name="callback"></param>
 /// <returns></returns>
 public async ValueTask <IAsyncDisposable> OnOrientationChange(Func <ValueTask> callback)
 {
     return(await JsRuntime.AddEventListener(JsObjectRef, "", "orientationchange",
                                             CallBackInteropWrapper.Create(callback, false)));
 }