Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 4x 4x 4x 4x 4x 1x 1x 1x 5x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 5x 5x 1x 1x 5x 5x 1x 1x 1x | // @ts-check // SPDX-License-Identifier: Zlib // SPDX-FileCopyrightText: 2024 CERN (home.cern) // SPDX-FileContributor: Author: Sylvain Fargier <sylvain.fargier@cern.ch> import bodyParser from "body-parser"; import AxisPTZ from "./AxisPTZ.js"; /** * @typedef {import('./PTZDevice')} PTZDevice * @typedef {import('express').Request} Request * @typedef {import('express').Response} Response * * @typedef {import('express').IRouter} expressIRouter * @typedef {import('express-ws').WithWebsocketMethod & expressIRouter} IRouter */ const registry = { axis: AxisPTZ }; const JsonParser = bodyParser.json({ strict: false }); class PTZService { /** * @param {CamExpress.InternalGroupConfig} groups * @param {CamExpress.Credentials} credentials */ constructor(groups, credentials) { this.groups = groups; this.creds = credentials; /** @type {{ [id: string]: PTZDevice }} */ this._ptz = {}; } /** * @param {IRouter} router */ register(router) { /** * @swagger * /cameras/{group}/{camera}/ptz/limits: * get: * tags: ['ptz'] * summary: get PTZ limits configuration * description: | * Exposes to PTZ limits to clients * parameters: * - in: path * name: group * schema: * type: string * description: name of the group defined in the config * required: true * - in: path * name: camera * schema: * type: string * description: name of the camera defined in the config * required: true * produces: * - application/json * responses: * 200: * description: PTZ limits configuration * 500: * description: error message */ router.get("/cameras/:group/:camera/ptz/limits", this._call.bind(this, (ptz) => ptz.getLimits())); /** * @swagger * /cameras/{group}/{camera}/ptz: * get: * tags: ['ptz'] * summary: get PTZ current position * description: | * Exposes to clients PTZ position * parameters: * - in: path * name: group * schema: * type: string * description: name of the group defined in the config * required: true * - in: path * name: camera * schema: * type: string * description: name of the camera defined in the config * required: true * produces: * - application/json * responses: * 200: * description: PTZ limits position * 500: * description: error message */ router.get("/cameras/:group/:camera/ptz", this._call.bind(this, (ptz) => ptz.getPosition())); /** * @swagger * /cameras/{group}/{camera}/ptz: * put: * tags: ['ptz'] * summary: execute an absolute PTZ motion * description: | * Sends an absolute motion command to PTZ * parameters: * - in: path * name: group * schema: * type: string * description: name of the group defined in the config * required: true * - in: path * name: camera * schema: * type: string * description: name of the camera defined in the config * required: true * - in: body * name: motion parameters * description: 'PTZ absolute motion values' * required: true * example: * pan: 0 * tilt: 0 * zoom: 200 * iris: 6248 * focus: 9854 * brightness: 4999 * autofocus: true * autoiris: true * produces: * - application/json * responses: * 200: * description: PTZ absolute movement ongoing * 500: * description: error message */ router.put("/cameras/:group/:camera/ptz", JsonParser, this._call.bind(this, (ptz, req) => ptz.putPosition(req.body))); /** * @swagger * /cameras/{group}/{camera}/ptz: * post: * tags: ['ptz'] * summary: execute an relative PTZ motion * description: | * Sends a relative motion command to PTZ * parameters: * - in: path * name: group * schema: * type: string * description: name of the group defined in the config * required: true * - in: path * name: camera * schema: * type: string * description: name of the camera defined in the config * required: true * - in: body * name: motion parameters * description: 'PTZ relative motion values' * required: true * example: * pan: -10 * tilt: -10 * zoom: -20 * iris: -10 * focus: -100 * brightness: -10 * produces: * - application/json * responses: * 200: * description: PTZ relative movement ongoing * 500: * description: error message */ router.post("/cameras/:group/:camera/ptz", JsonParser, this._call.bind(this, (ptz, req) => ptz.postPosition(req.body))); } /** * @param {Request} req * @param {Response} res * @param {(ptz: PTZDevice, req: Request, res: Response) => Promise<any>} cb * @returns */ async _call(cb, req, res) { const ptz = this.getPTZ(this.getCamera(req)); if (ptz) { try { return res.json(await cb(ptz, req, res)); } catch (err) { return res.status(500).send(err?.message ?? "internal error"); } } else { return res.status(404).send("PTZ Camera not found"); } } /** * @param {Request} req * @return {CamExpress.CameraConfig&{id:string|number}|undefined} */ getCamera(req) { const group = req?.params?.group; const camera = req?.params?.camera; return this.groups?.[group]?.cameras?.[camera]; } /** * @param {CamExpress.CameraConfig&{id:string|number}|undefined} cam * @return {PTZDevice|null} */ getPTZ(cam) { if (!cam) { return null; } let ptz = this._ptz[cam.id]; if (!ptz && cam.ptz) { const Ctrl = registry[(cam.ptz?.type ?? "").toLowerCase()]; if (Ctrl) { ptz = new Ctrl({ src: cam.ptz.url, auth: this.creds?.[cam.name] }); this._ptz[cam.id] = ptz; } } return ptz; } release() { this._ptz = {}; } } export default PTZService; |