Skip to content

Commit f60990a

Browse files
committed
Remove unused toRid helper and pin proto enum conversions with tests
toRid had no callers and mapped VideoQuality.OFF to the low quality rid, which would be wrong if it ever gained one. The new test pins the value count of every converted protobuf enum, so a proto regen that adds a value fails the test and points at the conversion, since the wildcard arms mean the analyzer can no longer flag it.
1 parent 1f30bfd commit f60990a

2 files changed

Lines changed: 109 additions & 7 deletions

File tree

lib/src/extensions.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,6 @@ extension VideoQualityExt on lk_models.VideoQuality {
156156
lk_models.VideoQuality.LOW => VideoQuality.LOW,
157157
_ => VideoQuality.LOW,
158158
};
159-
160-
String toRid() => switch (this) {
161-
lk_models.VideoQuality.HIGH => 'f',
162-
lk_models.VideoQuality.MEDIUM => 'h',
163-
lk_models.VideoQuality.LOW => 'q',
164-
_ => 'q',
165-
};
166159
}
167160

168161
extension PBVideoQualityExt on VideoQuality {
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright 2026 LiveKit, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import 'package:flutter_test/flutter_test.dart';
16+
17+
import 'package:livekit_client/src/e2ee/options.dart';
18+
import 'package:livekit_client/src/extensions.dart';
19+
import 'package:livekit_client/src/proto/livekit_models.pb.dart' as lk_models;
20+
import 'package:livekit_client/src/proto/livekit_rtc.pb.dart' as lk_rtc;
21+
import 'package:livekit_client/src/types/other.dart';
22+
23+
// The switches converting protobuf enums in extensions.dart cannot be compile
24+
// time exhaustive, protobuf enums are classes rather than Dart enums, so new
25+
// proto values silently take the wildcard arm. These tests pin the value count
26+
// of each converted proto enum. When a count assertion fails after a proto
27+
// regen, decide how the new value should convert in extensions.dart, then
28+
// update the count and expectations here.
29+
const countHint = 'proto enum gained a value, update the conversion in extensions.dart';
30+
31+
void main() {
32+
group('protobuf enum conversions cover every proto value', () {
33+
test('DataPacket_Kind', () {
34+
expect(lk_models.DataPacket_Kind.values, hasLength(2), reason: countHint);
35+
expect(lk_models.DataPacket_Kind.RELIABLE.toSDKType(), Reliability.reliable);
36+
expect(lk_models.DataPacket_Kind.LOSSY.toSDKType(), Reliability.lossy);
37+
});
38+
39+
test('ConnectionQuality', () {
40+
expect(lk_models.ConnectionQuality.values, hasLength(4), reason: countHint);
41+
expect(lk_models.ConnectionQuality.LOST.toLKType(), ConnectionQuality.lost);
42+
expect(lk_models.ConnectionQuality.POOR.toLKType(), ConnectionQuality.poor);
43+
expect(lk_models.ConnectionQuality.GOOD.toLKType(), ConnectionQuality.good);
44+
expect(lk_models.ConnectionQuality.EXCELLENT.toLKType(), ConnectionQuality.excellent);
45+
});
46+
47+
test('VideoQuality', () {
48+
expect(lk_models.VideoQuality.values, hasLength(4), reason: countHint);
49+
expect(lk_models.VideoQuality.LOW.toLKType(), VideoQuality.LOW);
50+
expect(lk_models.VideoQuality.MEDIUM.toLKType(), VideoQuality.MEDIUM);
51+
expect(lk_models.VideoQuality.HIGH.toLKType(), VideoQuality.HIGH);
52+
// the SDK enum has no OFF member, collapsing to LOW is intentional
53+
expect(lk_models.VideoQuality.OFF.toLKType(), VideoQuality.LOW);
54+
});
55+
56+
test('TrackType', () {
57+
expect(lk_models.TrackType.values, hasLength(3), reason: countHint);
58+
expect(lk_models.TrackType.AUDIO.toLKType(), TrackType.AUDIO);
59+
expect(lk_models.TrackType.VIDEO.toLKType(), TrackType.VIDEO);
60+
expect(lk_models.TrackType.DATA.toLKType(), TrackType.DATA);
61+
});
62+
63+
test('TrackSource', () {
64+
expect(lk_models.TrackSource.values, hasLength(5), reason: countHint);
65+
expect(lk_models.TrackSource.UNKNOWN.toLKType(), TrackSource.unknown);
66+
expect(lk_models.TrackSource.CAMERA.toLKType(), TrackSource.camera);
67+
expect(lk_models.TrackSource.MICROPHONE.toLKType(), TrackSource.microphone);
68+
expect(lk_models.TrackSource.SCREEN_SHARE.toLKType(), TrackSource.screenShareVideo);
69+
expect(lk_models.TrackSource.SCREEN_SHARE_AUDIO.toLKType(), TrackSource.screenShareAudio);
70+
});
71+
72+
test('StreamState', () {
73+
expect(lk_rtc.StreamState.values, hasLength(2), reason: countHint);
74+
expect(lk_rtc.StreamState.ACTIVE.toLKType(), StreamState.active);
75+
expect(lk_rtc.StreamState.PAUSED.toLKType(), StreamState.paused);
76+
});
77+
78+
test('Encryption_Type', () {
79+
expect(lk_models.Encryption_Type.values, hasLength(3), reason: countHint);
80+
expect(lk_models.Encryption_Type.NONE.toLkType(), EncryptionType.kNone);
81+
expect(lk_models.Encryption_Type.GCM.toLkType(), EncryptionType.kGcm);
82+
expect(lk_models.Encryption_Type.CUSTOM.toLkType(), EncryptionType.kCustom);
83+
});
84+
85+
test('ParticipantInfo_Kind', () {
86+
expect(lk_models.ParticipantInfo_Kind.values, hasLength(7), reason: countHint);
87+
expect(lk_models.ParticipantInfo_Kind.STANDARD.toLKType(), ParticipantKind.STANDARD);
88+
expect(lk_models.ParticipantInfo_Kind.INGRESS.toLKType(), ParticipantKind.INGRESS);
89+
expect(lk_models.ParticipantInfo_Kind.EGRESS.toLKType(), ParticipantKind.EGRESS);
90+
expect(lk_models.ParticipantInfo_Kind.SIP.toLKType(), ParticipantKind.SIP);
91+
expect(lk_models.ParticipantInfo_Kind.AGENT.toLKType(), ParticipantKind.AGENT);
92+
// the SDK enum has no members for these yet, they collapse to STANDARD
93+
expect(lk_models.ParticipantInfo_Kind.CONNECTOR.toLKType(), ParticipantKind.STANDARD);
94+
expect(lk_models.ParticipantInfo_Kind.BRIDGE.toLKType(), ParticipantKind.STANDARD);
95+
});
96+
97+
test('DisconnectReason', () {
98+
expect(lk_models.DisconnectReason.values, hasLength(17), reason: countHint);
99+
expect(lk_models.DisconnectReason.UNKNOWN_REASON.toSDKType(), DisconnectReason.unknown);
100+
expect(lk_models.DisconnectReason.CLIENT_INITIATED.toSDKType(), DisconnectReason.clientInitiated);
101+
expect(lk_models.DisconnectReason.DUPLICATE_IDENTITY.toSDKType(), DisconnectReason.duplicateIdentity);
102+
expect(lk_models.DisconnectReason.SERVER_SHUTDOWN.toSDKType(), DisconnectReason.serverShutdown);
103+
expect(lk_models.DisconnectReason.PARTICIPANT_REMOVED.toSDKType(), DisconnectReason.participantRemoved);
104+
expect(lk_models.DisconnectReason.ROOM_DELETED.toSDKType(), DisconnectReason.roomDeleted);
105+
expect(lk_models.DisconnectReason.STATE_MISMATCH.toSDKType(), DisconnectReason.stateMismatch);
106+
expect(lk_models.DisconnectReason.JOIN_FAILURE.toSDKType(), DisconnectReason.joinFailure);
107+
});
108+
});
109+
}

0 commit comments

Comments
 (0)