diff --git a/go.mod b/go.mod index d1e6884a7..501094499 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/jxskiss/base62 v1.1.0 github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 github.com/livekit/mediatransportutil v0.0.0-20231213075826-cccbf2b93d3f - github.com/livekit/protocol v1.9.5-0.20240117112816-6dc023d7edcc + github.com/livekit/protocol v1.9.5-0.20240118112540-cf33ad3861d8 github.com/livekit/psrpc v0.5.3-0.20231214055026-06ce27a934c9 github.com/mackerelio/go-osstat v0.2.4 github.com/magefile/mage v1.15.0 diff --git a/go.sum b/go.sum index 344743c09..48fed3d29 100644 --- a/go.sum +++ b/go.sum @@ -126,8 +126,8 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mediatransportutil v0.0.0-20231213075826-cccbf2b93d3f h1:XHrwGwLNGQB3ZqolH1YdMH/22hgXKr4vm+2M7JKMMGg= github.com/livekit/mediatransportutil v0.0.0-20231213075826-cccbf2b93d3f/go.mod h1:GBzn9xL+mivI1pW+tyExcKgbc0VOc29I9yJsNcAVaAc= -github.com/livekit/protocol v1.9.5-0.20240117112816-6dc023d7edcc h1:Tq5M+BJstua3RfFHyiBXwGzsJU8LcxoDjQzjjTQo7xQ= -github.com/livekit/protocol v1.9.5-0.20240117112816-6dc023d7edcc/go.mod h1:Qv55+z0kD0NYp/G0qAaFA4Mjalxt7tsOJwrvV3HymsA= +github.com/livekit/protocol v1.9.5-0.20240118112540-cf33ad3861d8 h1:E9s9KFCuKgYWYgaKz0ZmC7K3cPr8Iij77HbnwhQ4JZw= +github.com/livekit/protocol v1.9.5-0.20240118112540-cf33ad3861d8/go.mod h1:Qv55+z0kD0NYp/G0qAaFA4Mjalxt7tsOJwrvV3HymsA= github.com/livekit/psrpc v0.5.3-0.20231214055026-06ce27a934c9 h1:kXXV/NLVDHZ+Gn7xrR+UPpdwbH48n7WReBjLHAzqzhY= github.com/livekit/psrpc v0.5.3-0.20231214055026-06ce27a934c9/go.mod h1:cQjxg1oCxYHhxxv6KJH1gSvdtCHQoRZCHgPdm5N8v2g= github.com/mackerelio/go-osstat v0.2.4 h1:qxGbdPkFo65PXOb/F/nhDKpF2nGmGaCFDLXoZjJTtUs= diff --git a/pkg/routing/utils.go b/pkg/routing/utils.go deleted file mode 100644 index 2e11fdbe2..000000000 --- a/pkg/routing/utils.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2023 LiveKit, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package routing - -import ( - "fmt" - "strings" - - "github.com/jxskiss/base62" - - "github.com/livekit/protocol/livekit" -) - -func ParticipantKeyLegacy(roomName livekit.RoomName, identity livekit.ParticipantIdentity) livekit.ParticipantKey { - return livekit.ParticipantKey(string(roomName) + "|" + string(identity)) -} - -func parseParticipantKeyLegacy(pkey livekit.ParticipantKey) (roomName livekit.RoomName, identity livekit.ParticipantIdentity, err error) { - parts := strings.Split(string(pkey), "|") - if len(parts) == 2 { - roomName = livekit.RoomName(parts[0]) - identity = livekit.ParticipantIdentity(parts[1]) - return - } - - err = fmt.Errorf("invalid participant key: %s", pkey) - return -} - -func ParticipantKey(roomName livekit.RoomName, identity livekit.ParticipantIdentity) livekit.ParticipantKey { - return livekit.ParticipantKey(encode(string(roomName), string(identity))) -} - -func parseParticipantKey(pkey livekit.ParticipantKey) (roomName livekit.RoomName, identity livekit.ParticipantIdentity, err error) { - parts, err := decode(string(pkey)) - if err != nil { - return - } - if len(parts) == 2 { - roomName = livekit.RoomName(parts[0]) - identity = livekit.ParticipantIdentity(parts[1]) - return - } - - err = fmt.Errorf("invalid participant key: %s", pkey) - return -} - -func encode(str ...string) string { - encoded := make([]string, 0, len(str)) - for _, s := range str { - encoded = append(encoded, base62.EncodeToString([]byte(s))) - } - return strings.Join(encoded, "|") -} - -func decode(encoded string) ([]string, error) { - split := strings.Split(encoded, "|") - decoded := make([]string, 0, len(split)) - for _, s := range split { - part, err := base62.DecodeString(s) - if err != nil { - return nil, err - } - decoded = append(decoded, string(part)) - } - return decoded, nil -} diff --git a/pkg/routing/utils_test.go b/pkg/routing/utils_test.go deleted file mode 100644 index 8ae1e9b4c..000000000 --- a/pkg/routing/utils_test.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2023 LiveKit, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package routing - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/livekit/protocol/livekit" -) - -func TestUtils_ParticipantKey(t *testing.T) { - // encode/decode empty - encoded := ParticipantKey("", "") - roomName, identity, err := parseParticipantKey(encoded) - require.NoError(t, err) - require.Equal(t, livekit.RoomName(""), roomName) - require.Equal(t, livekit.ParticipantIdentity(""), identity) - - // decode invalid - _, _, err = parseParticipantKey("abcd") - require.Error(t, err) - - // encode/decode without delimiter - encoded = ParticipantKey("room1", "identity1") - roomName, identity, err = parseParticipantKey(encoded) - require.NoError(t, err) - require.Equal(t, livekit.RoomName("room1"), roomName) - require.Equal(t, livekit.ParticipantIdentity("identity1"), identity) - - // encode/decode with delimiter in roomName - encoded = ParticipantKey("room1|alter_room1", "identity1") - roomName, identity, err = parseParticipantKey(encoded) - require.NoError(t, err) - require.Equal(t, livekit.RoomName("room1|alter_room1"), roomName) - require.Equal(t, livekit.ParticipantIdentity("identity1"), identity) - - // encode/decode with delimiter in identity - encoded = ParticipantKey("room1", "identity1|alter-identity1") - roomName, identity, err = parseParticipantKey(encoded) - require.NoError(t, err) - require.Equal(t, livekit.RoomName("room1"), roomName) - require.Equal(t, livekit.ParticipantIdentity("identity1|alter-identity1"), identity) - - // encode/decode with delimiter in both and multiple delimiters in both - encoded = ParticipantKey("room1|alter_room1|again_room1", "identity1|alter-identity1|again-identity1") - roomName, identity, err = parseParticipantKey(encoded) - require.NoError(t, err) - require.Equal(t, livekit.RoomName("room1|alter_room1|again_room1"), roomName) - require.Equal(t, livekit.ParticipantIdentity("identity1|alter-identity1|again-identity1"), identity) -}