Skip to main content

Plugin Lifecycle

A SurfacePlugin has a simple top-level lifecycle built around two methods:

  • init() — called once when the plugin is loaded, before any surfaces or events are used. Set up whatever your plugin needs to begin discovering surfaces. Don't block on hardware that may not be present — report surfaces as they appear instead.
  • destroy() — called once when the plugin is about to be unloaded. Reset and close any open surfaces and release everything you created in init(). As with connection modules, leaking timers or handles here causes problems that accumulate over time.
Don't emit discovery events before init()

If your plugin uses the detection or remote mechanisms (both are EventEmitters), it must not emit any events until after init() has returned — anything emitted earlier is lost.

The lifecycle of an individual connected device is separate from the plugin lifecycle and is described in The Surface Instance.

The build → release → maintain lifecycle of the module repository (packaging, versioning, releasing) is shared with connection modules — see Module Development 101.