|
14 | 14 |
|
15 | 15 | package livekit |
16 | 16 |
|
17 | | -// ---------------------------------------------------------------- |
18 | | - |
19 | 17 | type TrackID string |
20 | | - |
21 | | -func StringsAsTrackIDs(trackIDs []string) []TrackID { |
22 | | - asTrackID := make([]TrackID, 0, len(trackIDs)) |
23 | | - for _, trackID := range trackIDs { |
24 | | - asTrackID = append(asTrackID, TrackID(trackID)) |
25 | | - } |
26 | | - |
27 | | - return asTrackID |
28 | | -} |
29 | | - |
30 | | -// ---------------------------------------------------------------- |
31 | | - |
32 | 18 | type ParticipantID string |
33 | | - |
34 | | -func ParticipantIDsAsStrings(ids []ParticipantID) []string { |
35 | | - strs := make([]string, 0, len(ids)) |
36 | | - for _, id := range ids { |
37 | | - strs = append(strs, string(id)) |
38 | | - } |
39 | | - return strs |
40 | | -} |
41 | | - |
42 | | -// ---------------------------------------------------------------- |
43 | | - |
44 | 19 | type ParticipantIdentity string |
45 | 20 | type ParticipantName string |
46 | | - |
47 | 21 | type RoomID string |
48 | | - |
49 | | -// ---------------------------------------------------------------- |
50 | | - |
51 | 22 | type RoomName string |
52 | | - |
53 | | -func RoomNamesAsStrings(roomNames []RoomName) []string { |
54 | | - asString := make([]string, 0, len(roomNames)) |
55 | | - for _, roomName := range roomNames { |
56 | | - asString = append(asString, string(roomName)) |
57 | | - } |
58 | | - |
59 | | - return asString |
60 | | -} |
61 | | - |
62 | | -func StringsAsRoomNames(roomNames []string) []RoomName { |
63 | | - asRoomName := make([]RoomName, 0, len(roomNames)) |
64 | | - for _, roomName := range roomNames { |
65 | | - asRoomName = append(asRoomName, RoomName(roomName)) |
66 | | - } |
67 | | - |
68 | | - return asRoomName |
69 | | -} |
70 | | - |
71 | | -// ---------------------------------------------------------------- |
72 | | - |
73 | 23 | type ConnectionID string |
74 | | - |
75 | | -// ---------------------------------------------------------------- |
76 | | - |
77 | 24 | type NodeID string |
| 25 | +type ParticipantKey string |
| 26 | + |
| 27 | +type stringTypes interface { |
| 28 | + ParticipantID | RoomID | TrackID | ParticipantIdentity | ParticipantName | RoomName | ConnectionID | NodeID | ParticipantKey |
| 29 | +} |
78 | 30 |
|
79 | | -func NodeIDsAsStrings(ids []NodeID) []string { |
| 31 | +func IDsAsStrings[T stringTypes](ids []T) []string { |
80 | 32 | strs := make([]string, 0, len(ids)) |
81 | 33 | for _, id := range ids { |
82 | 34 | strs = append(strs, string(id)) |
83 | 35 | } |
84 | 36 | return strs |
85 | 37 | } |
86 | 38 |
|
87 | | -// ---------------------------------------------------------------- |
88 | | -type ParticipantKey string |
| 39 | +func StringsAsIDs[T stringTypes](ids []string) []T { |
| 40 | + asID := make([]T, 0, len(ids)) |
| 41 | + for _, id := range ids { |
| 42 | + asID = append(asID, T(id)) |
| 43 | + } |
89 | 44 |
|
90 | | -// ---------------------------------------------------------------- |
| 45 | + return asID |
| 46 | +} |
91 | 47 |
|
92 | 48 | type Guid interface { |
93 | 49 | TrackID | ParticipantID | RoomID |
|
0 commit comments