Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gorgeous-cooks-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"github.com/livekit/protocol": patch
---

Implement a custom YAML unmarshaller for RoomConfiguration
10 changes: 10 additions & 0 deletions livekit/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ type Guid interface {

type GuidBlock [9]byte

func (r *RoomConfiguration) UnmarshalYAML(value *yaml.Node) error {
// Marshall the Node back to yaml to pass it to the protobuf specific unmarshaller
str, err := yaml.Marshal(value)
if err != nil {
return err
}

return protoyaml.Unmarshal(str, r)
}

func (r *RoomEgress) UnmarshalYAML(value *yaml.Node) error {
// Marshall the Node back to yaml to pass it to the protobuf specific unmarshaller
str, err := yaml.Marshal(value)
Expand Down
32 changes: 32 additions & 0 deletions livekit/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,38 @@ import (
"gopkg.in/yaml.v3"
)

func TestUnmarshallRoomConfiguration(t *testing.T) {
y := `
a:
name: room_name
egress:
room:
room_name: room_name
agent:
dispatches:
- {}
- agent_name: ag
metadata: mm
min_playout_delay: 42
`

obj := make(map[string]*RoomConfiguration)

err := yaml.Unmarshal([]byte(y), &obj)
require.NoError(t, err)
require.Equal(t, 1, len(obj))

re := obj["a"]
require.NotNil(t, re)
require.Equal(t, re.Name, "room_name")
require.Equal(t, re.MinPlayoutDelay, uint32(42))
require.Equal(t, re.Egress.Room.RoomName, "room_name")
require.Equal(t, len(re.Agent.Dispatches), 2)
require.Equal(t, "ag", re.Agent.Dispatches[1].AgentName)
require.Equal(t, "mm", re.Agent.Dispatches[1].Metadata)

}

func TestUnmarshallRoomEgress(t *testing.T) {
y := `
a:
Expand Down