Skip to content

Commit d4bca8a

Browse files
kkxkxArgoZhang
andauthored
fix(Camera): add last device id support switch device (#8262)
* Track last used video device in camera component Added lastUsedDeviceId property to camera object for tracking the last used video device. Signed-off-by: kkxkx <63846879+kkxkx@users.noreply.github.com> * chore: 更改文件编码 * chore: bump version 10.8.2-beta04 --------- Signed-off-by: kkxkx <63846879+kkxkx@users.noreply.github.com> Co-authored-by: Argo Zhang <argo@live.ca>
1 parent b30c523 commit d4bca8a

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎src/BootstrapBlazor/BootstrapBlazor.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.8.2-beta03</Version>
4+
<Version>10.8.2-beta04</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

‎src/BootstrapBlazor/Components/Camera/Camera.razor.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Data from "../../modules/data.js"
1+
import Data from "../../modules/data.js"
22

33
const openDevice = camera => {
44
if (camera.video) {
@@ -45,6 +45,7 @@ const play = (camera, option = {}) => {
4545
camera.video.element.srcObject = stream
4646
camera.video.element.play()
4747
camera.video.track = stream.getVideoTracks()[0]
48+
camera.lastUsedDeviceId = option.video.deviceId.exact ?? option.video.deviceId;
4849
camera.invoke.invokeMethodAsync("TriggerOpen")
4950
}).catch(err => {
5051
delete camera.video
@@ -57,7 +58,7 @@ export function init(id, invoke) {
5758
if (el === null) {
5859
return
5960
}
60-
const camera = { el, invoke }
61+
const camera = { el, invoke, lastUsedDeviceId: null }
6162
Data.set(id, camera)
6263

6364
navigator.mediaDevices.getUserMedia({ video: true, audio: false }).then(s => {
@@ -81,6 +82,7 @@ export function update(id) {
8182
// handler switch device
8283
if (camera.video) {
8384
const deviceId = camera.el.getAttribute("data-device-id")
85+
if (camera.lastUsedDeviceId === deviceId) return;
8486
if (camera.video.deviceId !== deviceId) {
8587
stopDevice(camera)
8688
openDevice(camera)

0 commit comments

Comments
 (0)