vue-chatvideo-layer

A Nuxt layer with the DM video calls of the SummerCMS chatvideo plugin on LiveKit: a call button for the chat, a minimal call page and an incoming-call prompt.

export default defineNuxtConfig({ extends: ['vue-chat-layer', 'vue-chatvideo-layer'] })

Overview

golem15.chatvideo answers a JSON API under /_chatvideo/api/v1, behind the user's frontend JWT. For a conversation participant it creates a LiveKit room and mints a short-lived join token; it rings the other participants on their realtime user channel and publishes the call's events on video:session:{id}. The layer turns that into three components:

  • <ChatvideoCallButton>: starts the call and opens the app's call route. It is meant for vue-chat-layer's conversation-actions slot, which renders for DMs only;
  • <ChatvideoCall>: the call page. Own camera, remote tiles, Mute, Camera on/off and Leave, the call's state and its failures. It turns the camera and microphone on only after a click: on the call button or Accept, or on its own Start call / Join call confirmation;
  • <ChatvideoIncomingCall>: a prompt with the caller's name, Accept and Decline, on any page.

The server sets the limits (maximum duration, participants per room, the start rate limit); the page shows their effect (the call ends, a full room refuses the connection) and adds no limits of its own. Screen share is not offered.

Built on vue-chat-layer

The layer is a companion of vue-chat-layer (a peer dependency, ^0.1.0) and does not extend it; the app extends both, chat first:

  • the token comes from the app's $chatAuth hook (token, refresh, unauthorized);
  • the ring (video:call:incoming) arrives on the user's channel user:{me}, which the chat store holds; the layer listens through onUserEvent and never subscribes to user:{me} itself. The prompt therefore needs the chat store running on the page (vue-chat-layer's ChatFloatingPanel or ChatPage starts it);
  • the session channel video:session:{id} is subscribed through the chat's shared realtime client.

livekit-client is loaded with a dynamic import when a call starts, so pages without a call do not load it.

Installation

Add both layers as git dependencies pinned to tags, next to the Nuxt and Vue versions they are built for:

{
  "dependencies": {
    "nuxt": "4.4.8",
    "vue": "3.5.35",
    "vue-chat-layer": "git+https://git.golem15.com/golem15/vue-chat-layer.git#v0.1.1",
    "vue-chatvideo-layer": "git+https://git.golem15.com/golem15/vue-chatvideo-layer.git#v0.1.2"
  }
}

The layer declares @nuxtjs/i18n (10.4.0) and livekit-client (2.23.0, exact). It registers its chatvideo.* copy only for the locales the app enables (en, pl). The browser calls /_chatvideo on the site's own origin (a dev proxy locally, the web server in production) and connects to the livekit_url the server answers.

Runtime config

Key Env Default Purpose
public.chatvideo.apiBase NUXT_PUBLIC_CHATVIDEO_API_BASE /_chatvideo/api/v1 Browser base of golem15.chatvideo

Usage

Every component runs in the browser only; render them inside <ClientOnly>:

<!-- pages/chat.vue: the call button in DM headers -->
<ClientOnly>
  <ChatPage>
    <template #conversation-actions="{ conversation }">
      <ChatvideoCallButton :conversation-id="conversation.id" :call-path="(id) => `/call/${id}?start=1`" />
    </template>
  </ChatPage>
</ClientOnly>

?start=1 on the call route only picks Start call over Join call on the page's confirmation; it does not start anything by itself.

<!-- pages/call/[conversation].vue -->
<ClientOnly>
  <ChatvideoCall :conversation-id="String(route.params.conversation)" :start="route.query.start === '1'" back-path="/chat" />
</ClientOnly>
<!-- layouts/default.vue: the ring on every page, for signed-in users -->
<ClientOnly>
  <ChatvideoIncomingCall v-if="loggedIn" :call-path="(id) => `/call/${id}`" />
</ClientOnly>

Components

Component Props Purpose
ChatvideoCallButton conversationId, callPath(id) Starts the call (video/start) and navigates to callPath; the start answer is handed to the call page in memory, never in the URL
ChatvideoCall conversationId, start?, backPath? Starts (with start) or joins the call, connects to LiveKit and shows the tiles and controls; emits left. It begins on mount only right after the call button or Accept; otherwise it shows a confirmation (chatvideo-confirm) whose button (chatvideo-confirm__go, Start call with start, else Join call) begins the call
ChatvideoTile tile One participant's camera, name and muted mark; plays remote audio
ChatvideoIncomingCall callPath(id) The ringing call's prompt: Accept leaves an accept marker and navigates to callPath, Decline posts video/leave

The call flow

  1. The caller's button posts video/start; the server creates the room and publishes video:call:incoming to the other participants.
  2. The call page connects with the answered livekit_url and token (adaptive stream and dynacast on) and publishes the camera and microphone.
  3. The callee's prompt Accept opens the call page, which posts video/join; Decline posts video/leave, which marks the callee left and publishes video:participant:left on the session channel. The caller's page shows a "did not answer" note for a participant who left without joining (the server has no separate decline route).
  4. Leave posts video/leave, or video/end when nobody else is in the room (the last one out ends the call, so the next call rings again), and disconnects, which stops the local tracks. Leaving the page (unmount or pagehide) leaves too. Leave works at any moment, also while the call is still starting or connecting. Before the call connects, the caller posts video/end and the callee video/leave, once the start or join answer has arrived; an answer that arrives after the leave closes the session it created the same way. No LiveKit room connects after a leave, a room already created is disconnected, and the camera and microphone are not turned on (a leave between the two leaves the microphone off). A failed LiveKit connect reads video/status: when nobody but this user has joined, it posts video/end, so the session stops ringing and the next start rings again; otherwise video/leave. When the status cannot be read, the caller ends and the callee leaves.
  5. video:call:ended on the session channel, or LiveKit closing the room (the server's maximum duration), ends the call on every page.

The call page begins by itself only after a click elsewhere: the call button's start answer and Accept's marker are kept in memory for a minute and taken once, and a link cannot create either. A direct load of the call route, or a link to it from a chat message, with or without ?start=1, shows the confirmation and posts neither video/start nor video/join, and opens no LiveKit connection, until Start call or Join call is clicked.

API reference

  • app/lib/callMachine.ts: initialCallState(), transition(state, event), isLive(state) and failureReason(code, message?). States idle, starting, connecting, connected, ended and failed; events start, joined, connected, participantJoined, participantLeft, mute, unmute, cameraOff, cameraOn, leave, ended and error. Reason keys (chatvideo.reason.*): left, ended, unauthorized, forbidden, notFound, tooMany, alreadyEnded, notConfigured, rateLimited, roomFull, connect, network and generic.
  • app/lib/videoClient.ts: createVideoClient({ base, auth, fetch? }) with start, join, leave, end and status; VideoApiError; videoSessionChannel(id) (the only way the layer names a session channel); videoPath, videoEvent, parseIncomingCall, rememberStart and takeStart; the click handoffs hasStart(id) (a start answer is waiting, not taken), rememberAccept(id) and takeAccept(id) (Accept's marker, a minute, taken once) and callAutostart(id, start) (whether the call page may begin on mount).
  • useCall(conversationId): state, tiles, declined, audioBlocked, reconnecting, mediaError, begin(start), leave(), toggleMute(), toggleCamera() and startAudio(). useVideoClient(): the client bound to runtime config and $chatAuth.
  • useIncomingCalls(): pending, accept(), decline() and dismiss(); the ring hides itself when the caller hangs up or after RING_MS (45 s), and a newer ring or a dismiss closes a session subscription that is still opening, so at most one session handle stays open.

Styling

app/assets/css/chatvideo-base.css uses --chatvideo-* variables with defaults. The call button also carries vue-chat-layer's chat-icon-btn class, so it matches the chat header's buttons. Class names carry the chatvideo- prefix.

Testing

pnpm install
pnpm test              # vitest: the call machine, the client, the event parsers, useCall and useIncomingCalls
pnpm build:playground  # builds .playground (vue-chat-layer at its tag plus this layer)
  • tests/callMachine.test.ts: every event in every state and the failure reason keys.
  • tests/videoClient.test.ts: every route's path, method, Bearer header and keepalive, the 401 refresh, refusals, the start handoff, the autostart rule (callAutostart after the call button or Accept only, a minute, per conversation, hasStart not taking the answer), videoSessionChannel and the event parsers.
  • tests/useCall.test.ts: useCall with vi.mock('livekit-client') (a minimal Room), a fake session channel and a stub client: start and join, tiles from remote tracks, mute and camera, leave and the last one out ending the call, the server ending it, declines, a 422 start, a failed connect (end or leave from the session status, and an unreadable status), blocked audio, unmount and pagehide. Leaving at every moment of an attempt: while start is pending, unmounting while join is pending, while livekit-client loads (the mocked module's import waits on a gate), while connect is pending or fails, between camera and microphone, and a second begin while the first join is pending. The real SDK runs in the consuming app's browser check with fake media.
  • tests/useIncomingCalls.test.ts: useIncomingCalls with a fake realtime client whose subscribes resolve by hand: two rings for one session in both resolve orders, rings for two sessions, a subscribe resolving after a dismiss, the kept handle closed by dismiss, accept, decline, the session's video:call:ended and the ring timeout (fake timers).

vitest.config.ts runs the tests in Node and defines import.meta.client as true, so the client-only registration in useIncomingCalls runs under vitest.

Description
No description provided
Readme 231 KiB
Languages
TypeScript 84%
Vue 12.2%
CSS 3.8%