Compare commits

...

3 Commits

Author SHA1 Message Date
github-actions[bot]
f2f36d399c Version Packages (#917) 2024-12-09 18:27:56 +01:00
lukasIO
fdd99d3d25 Add version declaration file (#916) 2024-12-09 18:25:59 +01:00
Paul Wells
5a1aa9f902 use events library for config observer (#912) 2024-12-04 23:58:46 -08:00
7 changed files with 24 additions and 30 deletions

View File

@@ -1,5 +1,7 @@
# github.com/livekit/protocol
## 1.29.4
## 1.29.3
## 1.29.2

View File

@@ -1,7 +1,7 @@
{
"name": "github.com/livekit/protocol",
"private": true,
"version": "1.29.3",
"version": "1.29.4",
"scripts": {
"changeset": "changeset",
"ci:publish": "pnpm --filter @livekit/protocol run build && changeset publish"

View File

@@ -1,4 +1,5 @@
node_modules/
dist
src/gen/*
!src/gen/version.d.ts

View File

@@ -1,5 +1,11 @@
# @livekit/protocol
## 1.29.4
### Patch Changes
- Add version declaration file - [#916](https://github.com/livekit/protocol/pull/916) ([@lukasIO](https://github.com/lukasIO))
## 1.29.3
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@livekit/protocol",
"version": "1.29.3",
"version": "1.29.4",
"description": "",
"type": "module",
"require": "dist/index.cjs",

View File

@@ -0,0 +1 @@
export declare const version: string;

View File

@@ -15,15 +15,15 @@
package utils
import (
"container/list"
"fmt"
"os"
"sync"
"github.com/fsnotify/fsnotify"
"go.uber.org/atomic"
"gopkg.in/yaml.v3"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/utils/events"
)
type ConfigBuilder[T any] interface {
@@ -35,16 +35,16 @@ type ConfigDefaulter[T any] interface {
}
type ConfigObserver[T any] struct {
builder ConfigBuilder[T]
watcher *fsnotify.Watcher
mu sync.Mutex
cbs list.List
conf *T
builder ConfigBuilder[T]
watcher *fsnotify.Watcher
observers *events.ObserverList[*T]
conf atomic.Pointer[T]
}
func NewConfigObserver[T any](path string, builder ConfigBuilder[T]) (*ConfigObserver[T], *T, error) {
c := &ConfigObserver[T]{
builder: builder,
builder: builder,
observers: events.NewObserverList[*T](events.WithBlocking()),
}
conf, err := c.load(path)
@@ -74,32 +74,18 @@ func (c *ConfigObserver[T]) Close() {
}
func (c *ConfigObserver[T]) EmitConfigUpdate(conf *T) {
c.mu.Lock()
defer c.mu.Unlock()
for e := c.cbs.Front(); e != nil; e = e.Next() {
e.Value.(func(*T))(conf)
}
c.observers.Emit(conf)
}
func (c *ConfigObserver[T]) Observe(cb func(*T)) func() {
if c == nil {
return func() {}
}
c.mu.Lock()
e := c.cbs.PushBack(cb)
c.mu.Unlock()
return func() {
c.mu.Lock()
c.cbs.Remove(e)
c.mu.Unlock()
}
return c.observers.On(cb)
}
func (c *ConfigObserver[T]) Load() *T {
c.mu.Lock()
defer c.mu.Unlock()
return c.conf
return c.conf.Load()
}
func (c *ConfigObserver[T]) watch() {
@@ -165,9 +151,7 @@ func (c *ConfigObserver[T]) load(path string) (*T, error) {
d.InitDefaults(conf)
}
c.mu.Lock()
c.conf = conf
c.mu.Unlock()
c.conf.Store(conf)
return conf, err
}