diff --git a/.changeset/gorgeous-cooks-matter.md b/.changeset/gorgeous-cooks-matter.md new file mode 100644 index 000000000..6b0fa99de --- /dev/null +++ b/.changeset/gorgeous-cooks-matter.md @@ -0,0 +1,5 @@ +--- +"github.com/livekit/protocol": patch +--- + +Implement a custom YAML unmarshaller for RoomConfiguration diff --git a/livekit/types.go b/livekit/types.go index 5759c6dee..a07cfbe87 100644 --- a/livekit/types.go +++ b/livekit/types.go @@ -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) diff --git a/livekit/types_test.go b/livekit/types_test.go index 28b23a323..c0984732d 100644 --- a/livekit/types_test.go +++ b/livekit/types_test.go @@ -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: