Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not detect change in state #2

Open
tradiff opened this issue May 2, 2021 · 1 comment
Open

Does not detect change in state #2

tradiff opened this issue May 2, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@tradiff
Copy link

tradiff commented May 2, 2021

This module doesn't detect a change in camera state. Here is an example program which polls the module every 1 second. While the program is running, if I start or stop using the camera, the output never reflects the new state. Terminating my program and starting it again does reflect the new state.

package main

import (
	"log"
	"time"

	mediaDevices "github.com/antonfisher/go-media-devices-state"
)

func main() {
	for {
		isCameraOn, err := mediaDevices.IsCameraOn()
		if err != nil {
			log.Println("Error:", err)
		} else {
			log.Println("Is camera on:", isCameraOn)
		}

		time.Sleep(1 * time.Second)
	}
}
@antonfisher
Copy link
Owner

Hi @travistx,

Yes, can confirm i see the same. Interesting that if i run it like:

while sleep 1; do go run ./cmd/demo.go; done;

it detects the camera properly. One workaround can be spawning a process for each check:

./cmd/demo.go:

package main

import (
	"fmt"
	"os/exec"
	"time"
)

func main() {
	for {
		checkCmd := exec.Command("bash", "-c", "go run /tmp/check.go")
		checkOut, _ := checkCmd.Output()
		fmt.Printf("Is camera on: %v", string(checkOut))
		time.Sleep(1 * time.Second)
	}
}

/tmp/check.go:

package main

import (
	"fmt"

	mediaDevices "github.com/antonfisher/go-media-devices-state"
)

func main() {
	isCameraOn, _ := mediaDevices.IsCameraOn()
	fmt.Println(isCameraOn)
}

and run it like:

go run ./cmd/demo.go

There seem to be some kind of caching for running in the same process 🤔

@antonfisher antonfisher added the bug Something isn't working label May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants