Med Fabric Preview logo

Med Fabric Preview

GitHub source MIT license

mf_preview is the optional isolated live-monitoring service in Med Fabric. It runs in a separate BEAM process with med_ex, med_ex_opus, and med_ex_rtc so native Opus encoding and WebRTC peer failures can never corrupt or interrupt authoritative clinical capture in mf_exam.

Installation

Add mf_preview to your list of dependencies in mix.exs:

def deps do
  [
    {:mf_preview, "~> 0.1.0"}
  ]
end

Requires Elixir ~> 1.20 (OTP 29) and native build tools / libopus support for med_ex_opus.

How It Works

  • Loopback feed (POST /feed): Authenticated with a dedicated bearer credential (MF_PREVIEW_CREDENTIAL_FILE) and x-acquisition header. Accepts valid 48 kHz mono PCM16LE (MedEx.Wire.FrameV1, stream 3, 960 samples / 1,920 bytes) and stores only the latest frame per acquisition in ETS.
  • Signed viewer signaling (POST /offer, /status, /close): Validates HMAC-SHA256 viewer tokens minted by mf_exam with short expiration windows, applies the server's ICE/TURN transport policy, and manages one MedFabric.Preview.Peer per acquisition.
  • Bounded latency & clean teardown: Drops frames older than 200 ms, keeps at most one Opus encoding operation in flight per peer, closes superseded peers, and terminates idle peers after 65 seconds.

Configuration

Set the listener port and shared secret file before starting:

export MF_PREVIEW_PORT=4090
export MF_PREVIEW_CREDENTIAL_FILE=/etc/med_fabric/preview.secret
mix run --no-halt

Guides

  • Getting Started — Environment variables, credentials, and Mix release startup.
  • Isolation Model — Process, credential, and failure isolation from mf_exam.

License

Released under the MIT License.