mirror of
https://github.com/pion/mediadevices.git
synced 2025-09-27 04:46:10 +08:00
comments: var block + interface-less error
This commit is contained in:

committed by
Clyde Bazile

parent
8568b1b20d
commit
2372f55064
@@ -4,22 +4,25 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Error interface {
|
var (
|
||||||
Error() string
|
ErrUnimplemented = NewError("not implemented")
|
||||||
}
|
ErrBusy = NewError("device or resource busy")
|
||||||
|
ErrNoDevice = NewError("no such device")
|
||||||
var ErrUnimplemented Error = errors.New("not implemented")
|
)
|
||||||
var ErrBusy Error = errors.New("device or resource busy")
|
|
||||||
var ErrNoDevice Error = errors.New("no such device")
|
|
||||||
|
|
||||||
type errorString struct {
|
type errorString struct {
|
||||||
s string
|
s string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewError(text string) Error {
|
func NewError(text string) error {
|
||||||
return &errorString{text}
|
return &errorString{text}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsError(err error) bool {
|
||||||
|
var target *errorString
|
||||||
|
return errors.As(err, &target)
|
||||||
|
}
|
||||||
|
|
||||||
func (e *errorString) Error() string {
|
func (e *errorString) Error() string {
|
||||||
return e.s
|
return e.s
|
||||||
}
|
}
|
||||||
|
@@ -353,7 +353,7 @@ func (c *camera) Properties() []prop.Media {
|
|||||||
return properties
|
return properties
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *camera) IsAvailable() (bool, availability.Error) {
|
func (c *camera) IsAvailable() (bool, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// close the opened file descriptor as quickly as possible and in all cases, including panics
|
// close the opened file descriptor as quickly as possible and in all cases, including panics
|
||||||
|
@@ -48,10 +48,10 @@ type Driver interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AvailabilityAdapter interface {
|
type AvailabilityAdapter interface {
|
||||||
IsAvailable() (bool, availability.Error)
|
IsAvailable() (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsAvailable(d Driver) (bool, availability.Error) {
|
func IsAvailable(d Driver) (bool, error) {
|
||||||
if aa, ok := d.(AvailabilityAdapter); ok {
|
if aa, ok := d.(AvailabilityAdapter); ok {
|
||||||
return aa.IsAvailable()
|
return aa.IsAvailable()
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,7 @@ type adapterWrapper struct {
|
|||||||
id string
|
id string
|
||||||
info Info
|
info Info
|
||||||
state State
|
state State
|
||||||
isAvailable func() (bool, availability.Error)
|
isAvailable func() (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *adapterWrapper) ID() string {
|
func (w *adapterWrapper) ID() string {
|
||||||
@@ -113,7 +113,7 @@ func (w *adapterWrapper) AudioRecord(p prop.Media) (r audio.Reader, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *adapterWrapper) IsAvailable() (bool, availability.Error) {
|
func (w *adapterWrapper) IsAvailable() (bool, error) {
|
||||||
if w.isAvailable == nil {
|
if w.isAvailable == nil {
|
||||||
return false, availability.ErrUnimplemented
|
return false, availability.ErrUnimplemented
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user