rvms-backend
v0.1.5
Published
RVMS (Video-MS) Node.js backend integration — auth, alarm WS, stream proxy
Readme
rvms-backend
Express middleware that proxies RVMS (Video-MS) — handles JWT auth, streams video, and relays alarms to your frontend without exposing credentials.
Install
npm install rvms-backendUsage
import express from 'express';
import http from 'http';
import { createRvmsRouter } from 'rvms-backend';
const app = express();
const server = http.createServer(app);
const { router, handleUpgrade } = await createRvmsRouter({
rvmsUrl: 'http://192.168.1.100:4000',
username: 'admin',
password: 'admin123',
onAlarm: (event) => console.log('alarm', event.type),
});
app.use('/api', router);
server.on('upgrade', handleUpgrade);
server.listen(3000);When a frontend connects to /ws/stream?nvrId=...&deviceId=..., the backend opens a WebSocket to RVMS with the JWT token and pipes the fMP4 video back. The frontend never touches the RVMS URL or the token.
Authentication
These routes are unauthenticated by default. Protect them with your own Express middleware:
import express from 'express';
import { createRvmsRouter } from 'rvms-backend';
const app = express();
function requireAuth(req, res, next) {
const token = req.headers.authorization?.split(' ')[1];
if (!token || !validateYourToken(token)) {
return res.status(401).json({ error: 'unauthorized' });
}
next();
}
const { router } = await createRvmsRouter({
rvmsUrl: 'http://localhost:4000',
username: 'admin',
password: 'secret',
});
// Mount behind your auth middleware
app.use('/api', requireAuth, router);For WebSocket endpoints, pass the token as a query parameter from the frontend:
// Frontend (rvms-vue components)
<RvmsVideoPlayer token="your-jwt-token" ... />
// Backend reads it from the URL
// The token is passed as ?token=... in WS URLsAPI
createRvmsRouter(options)
| Option | Type | Description |
|--------|------|-------------|
| rvmsUrl | string | RVMS backend URL (e.g. http://localhost:4000) |
| username | string | RVMS login username |
| password | string | RVMS login password |
| onAlarm | (event) => void | Optional callback for received alarms |
Returns { router, handleUpgrade, auth, api, alarmClient }.
Proxied endpoints
| Endpoint | Method | Description |
|----------|--------|-------------|
| /api/nvrs | GET | List NVRs |
| /api/nvrs/:id/devices | GET | List cameras |
| /api/playback/search | GET | Search recordings |
| /api/alarms/recent | GET | Recent alarms |
| /api/alarms/snapshots/:id | GET | Snapshot image (proxied with auth) |
| /ws/stream?nvrId&deviceId&mode&profile | WS | Video stream (proxied to RVMS) |
| /ws/alarms | WS | Real-time alarm events |
RvmsAuthManager
const auth = new RvmsAuthManager('http://localhost:4000');
await auth.login('admin', 'password');
auth.getAccessToken(); // current JWTRvmsApiClient
const api = new RvmsApiClient('http://localhost:4000', auth);
await api.listNvrs();
await api.listDevices(nvrId);
await api.searchPlayback(nvrId, deviceId, from, to);
await api.recentAlarms();
api.buildStreamWsUrl(wsBase, nvrId, deviceId, { mode, profile });RvmsAlarmClient
const alarms = new RvmsAlarmClient(auth, 'ws://localhost:4000');
alarms.onAlarmEvent((event) => console.log(event));
alarms.onInitialSnapshot((events) => console.log('snapshot', events.length));
alarms.onConnectionStatus((connected) => console.log(connected));
alarms.connect();Full example
This package IS the example — browse src/index.ts for the complete implementation.
For a ready-to-run demo with a Vue 3 frontend, see the rvms-vue package:
npm install rvms-vueThe full example frontend (with RvmsVideoPlayer, RvmsVideo, demo pages) is included in rvms-vue/src/.
