How to generate events from the browser using Javascript #2996
PasqualePuzio
announced in
Q&A
Replies: 1 comment 1 reply
-
I haven't seen this done before, but I think it should be possible. Below is the code needed to send an event to the backend import { useCallback, useContext } from "react"
import { EventLoopContext } from "/utils/context"
// In your function where you want to send the event
const [addEvents, connectErrors] = useContext(EventLoopContext);
const send_event = useCallback((_e) => addEvents([Event("state.state_name.event_handler_name", {/* any arguments to pass to the handler */})], (_e), {}), [addEvents, Event])
// Then where appropriate call the function
send_event() I haven't tested this out but wanted to give you some pointers, I may have more time later to build this. I'm a bit unsure on the useCallback part - that's used to bind this to events in Reflex, but you may not need that lambda for your use case. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
we need to integrate with an external service using their Javascript SDK.
The SDK is pretty simple to integrate as it should trigger an event which needs to be handled by the application.
The problem is that we need to send the data contained in the event to the Reflex backend and the ideal why to do that is to trigger an event and deliver the corresponding message to the backend via the websocket.
Is there a way (even undocumented) to achieve that from the browser using Javascript? Can we craft an event and send it over the websocket?
As an alternative, we may just redirect the user to a URL containing in the query the information we need to process, but that wouldn't great from a security point of view.
Beta Was this translation helpful? Give feedback.
All reactions