{"id":18930828,"url":"https://github.com/onlymisaky/web-camera","last_synced_at":"2026-03-17T01:30:17.787Z","repository":{"id":57133263,"uuid":"138309779","full_name":"onlymisaky/web-camera","owner":"onlymisaky","description":"camera","archived":false,"fork":false,"pushed_at":"2022-02-17T07:46:18.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-31T19:42:50.241Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onlymisaky.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-22T14:06:08.000Z","updated_at":"2022-02-17T07:46:21.000Z","dependencies_parsed_at":"2022-09-03T15:22:08.795Z","dependency_job_id":null,"html_url":"https://github.com/onlymisaky/web-camera","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlymisaky%2Fweb-camera","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlymisaky%2Fweb-camera/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlymisaky%2Fweb-camera/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlymisaky%2Fweb-camera/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onlymisaky","download_url":"https://codeload.github.com/onlymisaky/web-camera/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239927816,"owners_count":19719835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T11:39:07.270Z","updated_at":"2026-03-17T01:30:17.744Z","avatar_url":"https://github.com/onlymisaky.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# Camera\n\n网页版相机\n\n# TODO\n\n- [ ] 打包\n- [ ] 在线用例\n- [ ] 完整的 README\n\n## 用法\n\n1. 需要 `https` 支持，或者 `file` 协议\n2. 同时需要用户同意打开摄像头\n\n```javascript\nconst camera = new Camera(document.querySelector('video'));\n\n(async () =\u003e {\n  try {\n    const cameraList = await camera.getCameraList();\n    if (cameraList) {\n      await camera.open({ video: { deviceId: cameraList[0].deviceId } });\n      const canvas = await camera.md2Canvas();\n      document.querySelector('img').src = canvas.toDataURL('Image/jpeg', 1)\n    }\n  } catch (err) {\n    throw err\n  }\n})();\n```\n\n## API\n\n函数 | 参数 | 返回值 | 说明\n--- | --- | --- | ---\ngetCameraList | --- | Promise\u003cMediaDeviceInfo[]\u003e | 获取摄像头列表\nopen | constraints:MediaStreamConstraints, force: boolean | MediaStream  | 打开相机, force 默认为 false， 传 true 表示重新打开 |\nclose | -- | void| 关闭相机\nmd2Canvas | -- |  HTMLCanvasElement | 截取图片 |\ndestroy | -- | void | 销毁\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonlymisaky%2Fweb-camera","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonlymisaky%2Fweb-camera","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonlymisaky%2Fweb-camera/lists"}