Skip to content

Commit e5851ea

Browse files
authored
Log consolidated server info when connected (#391)
* log consolidated server info when connected * formatting * changeset
1 parent b9ca04f commit e5851ea

File tree

6 files changed

+193
-19
lines changed

6 files changed

+193
-19
lines changed

.changeset/eleven-chefs-swim.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'livekit-client': patch
3+
---
4+
5+
Log consolidated serverinfo on connect

src/proto/google/protobuf/timestamp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export type DeepPartial<T> = T extends Builtin
199199
type KeysOfUnion<T> = T extends T ? keyof T : never;
200200
export type Exact<P, I extends P> = P extends Builtin
201201
? P
202-
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
202+
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
203203

204204
function longToNumber(long: Long): number {
205205
if (long.gt(Number.MAX_SAFE_INTEGER)) {

src/proto/livekit_models.ts

+157-15
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,50 @@ export interface ParticipantTracks {
495495
trackSids: string[];
496496
}
497497

498+
/** details about the server */
499+
export interface ServerInfo {
500+
edition: ServerInfo_Edition;
501+
version: string;
502+
protocol: number;
503+
region: string;
504+
nodeId: string;
505+
/** additional debugging information. sent only if server is in development mode */
506+
debugInfo: string;
507+
}
508+
509+
export enum ServerInfo_Edition {
510+
Standard = 0,
511+
Cloud = 1,
512+
UNRECOGNIZED = -1,
513+
}
514+
515+
export function serverInfo_EditionFromJSON(object: any): ServerInfo_Edition {
516+
switch (object) {
517+
case 0:
518+
case 'Standard':
519+
return ServerInfo_Edition.Standard;
520+
case 1:
521+
case 'Cloud':
522+
return ServerInfo_Edition.Cloud;
523+
case -1:
524+
case 'UNRECOGNIZED':
525+
default:
526+
return ServerInfo_Edition.UNRECOGNIZED;
527+
}
528+
}
529+
530+
export function serverInfo_EditionToJSON(object: ServerInfo_Edition): string {
531+
switch (object) {
532+
case ServerInfo_Edition.Standard:
533+
return 'Standard';
534+
case ServerInfo_Edition.Cloud:
535+
return 'Cloud';
536+
case ServerInfo_Edition.UNRECOGNIZED:
537+
default:
538+
return 'UNRECOGNIZED';
539+
}
540+
}
541+
498542
/** details about the client */
499543
export interface ClientInfo {
500544
sdk: ClientInfo_SDK;
@@ -1809,6 +1853,100 @@ export const ParticipantTracks = {
18091853
},
18101854
};
18111855

1856+
function createBaseServerInfo(): ServerInfo {
1857+
return { edition: 0, version: '', protocol: 0, region: '', nodeId: '', debugInfo: '' };
1858+
}
1859+
1860+
export const ServerInfo = {
1861+
encode(message: ServerInfo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
1862+
if (message.edition !== 0) {
1863+
writer.uint32(8).int32(message.edition);
1864+
}
1865+
if (message.version !== '') {
1866+
writer.uint32(18).string(message.version);
1867+
}
1868+
if (message.protocol !== 0) {
1869+
writer.uint32(24).int32(message.protocol);
1870+
}
1871+
if (message.region !== '') {
1872+
writer.uint32(34).string(message.region);
1873+
}
1874+
if (message.nodeId !== '') {
1875+
writer.uint32(42).string(message.nodeId);
1876+
}
1877+
if (message.debugInfo !== '') {
1878+
writer.uint32(50).string(message.debugInfo);
1879+
}
1880+
return writer;
1881+
},
1882+
1883+
decode(input: _m0.Reader | Uint8Array, length?: number): ServerInfo {
1884+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
1885+
let end = length === undefined ? reader.len : reader.pos + length;
1886+
const message = createBaseServerInfo();
1887+
while (reader.pos < end) {
1888+
const tag = reader.uint32();
1889+
switch (tag >>> 3) {
1890+
case 1:
1891+
message.edition = reader.int32() as any;
1892+
break;
1893+
case 2:
1894+
message.version = reader.string();
1895+
break;
1896+
case 3:
1897+
message.protocol = reader.int32();
1898+
break;
1899+
case 4:
1900+
message.region = reader.string();
1901+
break;
1902+
case 5:
1903+
message.nodeId = reader.string();
1904+
break;
1905+
case 6:
1906+
message.debugInfo = reader.string();
1907+
break;
1908+
default:
1909+
reader.skipType(tag & 7);
1910+
break;
1911+
}
1912+
}
1913+
return message;
1914+
},
1915+
1916+
fromJSON(object: any): ServerInfo {
1917+
return {
1918+
edition: isSet(object.edition) ? serverInfo_EditionFromJSON(object.edition) : 0,
1919+
version: isSet(object.version) ? String(object.version) : '',
1920+
protocol: isSet(object.protocol) ? Number(object.protocol) : 0,
1921+
region: isSet(object.region) ? String(object.region) : '',
1922+
nodeId: isSet(object.nodeId) ? String(object.nodeId) : '',
1923+
debugInfo: isSet(object.debugInfo) ? String(object.debugInfo) : '',
1924+
};
1925+
},
1926+
1927+
toJSON(message: ServerInfo): unknown {
1928+
const obj: any = {};
1929+
message.edition !== undefined && (obj.edition = serverInfo_EditionToJSON(message.edition));
1930+
message.version !== undefined && (obj.version = message.version);
1931+
message.protocol !== undefined && (obj.protocol = Math.round(message.protocol));
1932+
message.region !== undefined && (obj.region = message.region);
1933+
message.nodeId !== undefined && (obj.nodeId = message.nodeId);
1934+
message.debugInfo !== undefined && (obj.debugInfo = message.debugInfo);
1935+
return obj;
1936+
},
1937+
1938+
fromPartial<I extends Exact<DeepPartial<ServerInfo>, I>>(object: I): ServerInfo {
1939+
const message = createBaseServerInfo();
1940+
message.edition = object.edition ?? 0;
1941+
message.version = object.version ?? '';
1942+
message.protocol = object.protocol ?? 0;
1943+
message.region = object.region ?? '';
1944+
message.nodeId = object.nodeId ?? '';
1945+
message.debugInfo = object.debugInfo ?? '';
1946+
return message;
1947+
},
1948+
};
1949+
18121950
function createBaseClientInfo(): ClientInfo {
18131951
return {
18141952
sdk: 0,
@@ -2734,25 +2872,29 @@ var globalThis: any = (() => {
27342872
throw 'Unable to locate global object';
27352873
})();
27362874

2737-
const atob: (b64: string) => string =
2738-
globalThis.atob || ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'));
27392875
function bytesFromBase64(b64: string): Uint8Array {
2740-
const bin = atob(b64);
2741-
const arr = new Uint8Array(bin.length);
2742-
for (let i = 0; i < bin.length; ++i) {
2743-
arr[i] = bin.charCodeAt(i);
2876+
if (globalThis.Buffer) {
2877+
return Uint8Array.from(globalThis.Buffer.from(b64, 'base64'));
2878+
} else {
2879+
const bin = globalThis.atob(b64);
2880+
const arr = new Uint8Array(bin.length);
2881+
for (let i = 0; i < bin.length; ++i) {
2882+
arr[i] = bin.charCodeAt(i);
2883+
}
2884+
return arr;
27442885
}
2745-
return arr;
27462886
}
27472887

2748-
const btoa: (bin: string) => string =
2749-
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
27502888
function base64FromBytes(arr: Uint8Array): string {
2751-
const bin: string[] = [];
2752-
arr.forEach((byte) => {
2753-
bin.push(String.fromCharCode(byte));
2754-
});
2755-
return btoa(bin.join(''));
2889+
if (globalThis.Buffer) {
2890+
return globalThis.Buffer.from(arr).toString('base64');
2891+
} else {
2892+
const bin: string[] = [];
2893+
arr.forEach((byte) => {
2894+
bin.push(String.fromCharCode(byte));
2895+
});
2896+
return globalThis.btoa(bin.join(''));
2897+
}
27562898
}
27572899

27582900
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
@@ -2772,7 +2914,7 @@ export type DeepPartial<T> = T extends Builtin
27722914
type KeysOfUnion<T> = T extends T ? keyof T : never;
27732915
export type Exact<P, I extends P> = P extends Builtin
27742916
? P
2775-
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
2917+
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
27762918

27772919
function toTimestamp(date: Date): Timestamp {
27782920
const seconds = date.getTime() / 1_000;

src/proto/livekit_rtc.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Room,
66
ParticipantInfo,
77
ClientConfiguration,
8+
ServerInfo,
89
TrackInfo,
910
VideoQuality,
1011
DisconnectReason,
@@ -207,6 +208,7 @@ export interface JoinResponse {
207208
room?: Room;
208209
participant?: ParticipantInfo;
209210
otherParticipants: ParticipantInfo[];
211+
/** deprecated. use server_info.version instead. */
210212
serverVersion: string;
211213
iceServers: ICEServer[];
212214
/** use subscriber as the primary PeerConnection */
@@ -217,9 +219,11 @@ export interface JoinResponse {
217219
*/
218220
alternativeUrl: string;
219221
clientConfiguration?: ClientConfiguration;
222+
/** deprecated. use server_info.region instead. */
220223
serverRegion: string;
221224
pingTimeout: number;
222225
pingInterval: number;
226+
serverInfo?: ServerInfo;
223227
}
224228

225229
export interface TrackPublishedResponse {
@@ -1567,6 +1571,7 @@ function createBaseJoinResponse(): JoinResponse {
15671571
serverRegion: '',
15681572
pingTimeout: 0,
15691573
pingInterval: 0,
1574+
serverInfo: undefined,
15701575
};
15711576
}
15721577

@@ -1605,6 +1610,9 @@ export const JoinResponse = {
16051610
if (message.pingInterval !== 0) {
16061611
writer.uint32(88).int32(message.pingInterval);
16071612
}
1613+
if (message.serverInfo !== undefined) {
1614+
ServerInfo.encode(message.serverInfo, writer.uint32(98).fork()).ldelim();
1615+
}
16081616
return writer;
16091617
},
16101618

@@ -1648,6 +1656,9 @@ export const JoinResponse = {
16481656
case 11:
16491657
message.pingInterval = reader.int32();
16501658
break;
1659+
case 12:
1660+
message.serverInfo = ServerInfo.decode(reader, reader.uint32());
1661+
break;
16511662
default:
16521663
reader.skipType(tag & 7);
16531664
break;
@@ -1679,6 +1690,7 @@ export const JoinResponse = {
16791690
serverRegion: isSet(object.serverRegion) ? String(object.serverRegion) : '',
16801691
pingTimeout: isSet(object.pingTimeout) ? Number(object.pingTimeout) : 0,
16811692
pingInterval: isSet(object.pingInterval) ? Number(object.pingInterval) : 0,
1693+
serverInfo: isSet(object.serverInfo) ? ServerInfo.fromJSON(object.serverInfo) : undefined,
16821694
};
16831695
},
16841696

@@ -1711,6 +1723,8 @@ export const JoinResponse = {
17111723
message.serverRegion !== undefined && (obj.serverRegion = message.serverRegion);
17121724
message.pingTimeout !== undefined && (obj.pingTimeout = Math.round(message.pingTimeout));
17131725
message.pingInterval !== undefined && (obj.pingInterval = Math.round(message.pingInterval));
1726+
message.serverInfo !== undefined &&
1727+
(obj.serverInfo = message.serverInfo ? ServerInfo.toJSON(message.serverInfo) : undefined);
17141728
return obj;
17151729
},
17161730

@@ -1735,6 +1749,10 @@ export const JoinResponse = {
17351749
message.serverRegion = object.serverRegion ?? '';
17361750
message.pingTimeout = object.pingTimeout ?? 0;
17371751
message.pingInterval = object.pingInterval ?? 0;
1752+
message.serverInfo =
1753+
object.serverInfo !== undefined && object.serverInfo !== null
1754+
? ServerInfo.fromPartial(object.serverInfo)
1755+
: undefined;
17381756
return message;
17391757
},
17401758
};
@@ -3462,7 +3480,7 @@ export type DeepPartial<T> = T extends Builtin
34623480
type KeysOfUnion<T> = T extends T ? keyof T : never;
34633481
export type Exact<P, I extends P> = P extends Builtin
34643482
? P
3465-
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;
3483+
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
34663484

34673485
function longToNumber(long: Long): number {
34683486
if (long.gt(Number.MAX_SAFE_INTEGER)) {

src/room/Room.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ParticipantInfo_State,
1111
ParticipantPermission,
1212
Room as RoomModel,
13+
ServerInfo,
1314
SpeakerInfo,
1415
UserPacket,
1516
} from '../proto/livekit_models';
@@ -247,8 +248,16 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
247248
},
248249
this.abortController.signal,
249250
);
251+
252+
let serverInfo: Partial<ServerInfo> | undefined = joinResponse.serverInfo;
253+
if (!serverInfo) {
254+
serverInfo = { version: joinResponse.serverVersion, region: joinResponse.serverRegion };
255+
}
256+
250257
log.debug(
251-
`connected to Livekit Server version: ${joinResponse.serverVersion}, region: ${joinResponse.serverRegion}`,
258+
`connected to Livekit Server ${Object.entries(serverInfo)
259+
.map(([key, value]) => `${key}: ${value}`)
260+
.join(', ')}`,
252261
);
253262

254263
if (!joinResponse.serverVersion) {

0 commit comments

Comments
 (0)