Getting the PID of a scenic component/scene

Hi,

Quick question, in the Scenic docs it suggests that you can interact with any scene as you would any GenServer:

You are free to send your own messages to scenes just as you would with any other GenServer process. You can use the handle_info/2 , handle_cast/2 and handle_call/3 callbacks as you would normally.

I understand how this would work, but I’m unsure of how to actually get the PID of the scene to send messages to.

I hope I’m not missing anything too obvious.

Thanks for the help

1 Like

Independently started processes most often communicate via names registered in some registry or systems like pubsub rather than using blank pids. There are many options for both for elixir.

Using observer theres a table called _scenic_scenes_table_, but i’m guessing that’s not a public API.

The documentation seems to suggest that being able to send messages to a scene is a recognised pattern, so I was hoping there would be an easy way to do this

You don’t need the PID of the Scene, you can simply use their name, they are usually initialized and registered with a name.

If you are inside a component inside the scene you can use send_event like the default Button component does https://github.com/boydm/scenic/blob/master/lib/scenic/component/button.ex#L280

1 Like

You don’t need scenic specific api here. E.g. you can register scenes within an elixir core Registry instance. The docs seem to suggest you can statically supervise scenes, where you can give names to the scenes. You could subscribe your scene to a phoenix pubsub channel. There are many ways to get messages to your scenes and none are in any way specific to scenic or require some api of scenic.