mirror of
https://github.com/openlibrecommunity/olcrtc.git
synced 2026-05-26 15:13:40 +00:00
refactor(provider,logger): clean logging and unify provider interface
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync/atomic"
|
||||
)
|
||||
@@ -20,44 +19,44 @@ func IsVerbose() bool {
|
||||
|
||||
// Info logs an informational message.
|
||||
func Info(v ...any) {
|
||||
log.Print("[INFO] ", fmt.Sprint(v...))
|
||||
log.Print(v...)
|
||||
}
|
||||
|
||||
// Infof logs a formatted informational message.
|
||||
func Infof(format string, v ...any) {
|
||||
log.Printf("[INFO] "+format, v...)
|
||||
log.Printf(format, v...)
|
||||
}
|
||||
|
||||
// Warn logs a warning message.
|
||||
func Warn(v ...any) {
|
||||
log.Print("[WARN] ", fmt.Sprint(v...))
|
||||
log.Print(v...)
|
||||
}
|
||||
|
||||
// Warnf logs a formatted warning message.
|
||||
func Warnf(format string, v ...any) {
|
||||
log.Printf("[WARN] "+format, v...)
|
||||
log.Printf(format, v...)
|
||||
}
|
||||
|
||||
// Error logs an error message.
|
||||
func Error(v ...any) {
|
||||
log.Print("[ERROR] ", fmt.Sprint(v...))
|
||||
log.Print(v...)
|
||||
}
|
||||
|
||||
// Errorf logs a formatted error message.
|
||||
func Errorf(format string, v ...any) {
|
||||
log.Printf("[ERROR] "+format, v...)
|
||||
log.Printf(format, v...)
|
||||
}
|
||||
|
||||
// Verbosef logs a formatted message if verbose logging is enabled.
|
||||
func Verbosef(format string, v ...any) {
|
||||
if verboseEnabled.Load() {
|
||||
log.Printf("[VERBOSE] "+format, v...)
|
||||
log.Printf(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Debugf logs a formatted message if verbose logging is enabled.
|
||||
func Debugf(format string, v ...any) {
|
||||
if verboseEnabled.Load() {
|
||||
log.Printf("[DEBUG] "+format, v...)
|
||||
log.Printf(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
// Package provider defines common errors for WebRTC providers.
|
||||
package provider
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
// ErrProviderNotFound is returned when the requested provider is not registered.
|
||||
ErrProviderNotFound = errors.New("provider not found")
|
||||
// ErrDataChannelTimeout is returned when the DataChannel fails to open in time.
|
||||
ErrDataChannelTimeout = errors.New("datachannel timeout")
|
||||
// ErrDataChannelNotReady is returned when attempting to send data before the DataChannel is open.
|
||||
ErrDataChannelNotReady = errors.New("datachannel not ready")
|
||||
// ErrSendQueueClosed is returned when attempting to send data after the send queue has been closed.
|
||||
ErrSendQueueClosed = errors.New("send queue closed")
|
||||
// ErrSendQueueTimeout is returned when the send queue is full and the timeout is reached.
|
||||
ErrSendQueueTimeout = errors.New("send queue timeout")
|
||||
)
|
||||
@@ -3,10 +3,19 @@ package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/pion/webrtc/v4"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrProviderNotFound = errors.New("provider not found")
|
||||
ErrDataChannelTimeout = errors.New("datachannel timeout")
|
||||
ErrDataChannelNotReady = errors.New("datachannel not ready")
|
||||
ErrSendQueueClosed = errors.New("send queue closed")
|
||||
ErrSendQueueTimeout = errors.New("send queue timeout")
|
||||
)
|
||||
|
||||
// Provider defines the standard interface for WebRTC connection handlers.
|
||||
type Provider interface {
|
||||
Connect(ctx context.Context) error
|
||||
@@ -19,6 +28,9 @@ type Provider interface {
|
||||
CanSend() bool
|
||||
GetSendQueue() chan []byte
|
||||
GetBufferedAmount() uint64
|
||||
|
||||
// AddVideoTrack adds a video track to the connection.
|
||||
AddVideoTrack(track *webrtc.TrackLocalStaticRTP) (*webrtc.RTPSender, error)
|
||||
}
|
||||
|
||||
// Config holds common configuration for all providers.
|
||||
@@ -34,7 +46,7 @@ type Config struct {
|
||||
// Factory is a function that creates a new Provider instance.
|
||||
type Factory func(ctx context.Context, cfg Config) (Provider, error)
|
||||
|
||||
//nolint:gochecknoglobals
|
||||
// registry holds all registered provider factories.
|
||||
var registry = make(map[string]Factory)
|
||||
|
||||
// Register adds a new provider factory to the registry.
|
||||
|
||||
Reference in New Issue
Block a user