Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward leave reason of disconnected events #304

Merged
merged 7 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-camels-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Forward reason of disconnected event
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LogLevel, setLogExtension, setLogLevel } from './logger';
import { DataPacket_Kind, VideoQuality } from './proto/livekit_models';
import { DataPacket_Kind, VideoQuality, DisconnectReason } from './proto/livekit_models';
import LocalParticipant from './room/participant/LocalParticipant';
import Participant, { ConnectionQuality } from './room/participant/Participant';
import { ParticipantTrackPermission } from './room/participant/ParticipantTrackPermission';
Expand Down Expand Up @@ -34,6 +34,7 @@ export {
ConnectionState,
RoomState,
DataPacket_Kind,
DisconnectReason,
Participant,
RemoteParticipant,
LocalParticipant,
Expand Down
183 changes: 179 additions & 4 deletions src/proto/livekit_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,68 @@ export function clientConfigSettingToJSON(object: ClientConfigSetting): string {
}
}

export enum DisconnectReason {
UNKNOWN_REASON = 0,
CLIENT_INITIATED = 1,
DUPLICATE_IDENTITY = 2,
SERVER_SHUTDOWN = 3,
PARTICIPANT_REMOVED = 4,
ROOM_DELETED = 5,
STATE_MISMATCH = 6,
UNRECOGNIZED = -1,
}

export function disconnectReasonFromJSON(object: any): DisconnectReason {
switch (object) {
case 0:
case 'UNKNOWN_REASON':
return DisconnectReason.UNKNOWN_REASON;
case 1:
case 'CLIENT_INITIATED':
return DisconnectReason.CLIENT_INITIATED;
case 2:
case 'DUPLICATE_IDENTITY':
return DisconnectReason.DUPLICATE_IDENTITY;
case 3:
case 'SERVER_SHUTDOWN':
return DisconnectReason.SERVER_SHUTDOWN;
case 4:
case 'PARTICIPANT_REMOVED':
return DisconnectReason.PARTICIPANT_REMOVED;
case 5:
case 'ROOM_DELETED':
return DisconnectReason.ROOM_DELETED;
case 6:
case 'STATE_MISMATCH':
return DisconnectReason.STATE_MISMATCH;
case -1:
case 'UNRECOGNIZED':
default:
return DisconnectReason.UNRECOGNIZED;
}
}

export function disconnectReasonToJSON(object: DisconnectReason): string {
switch (object) {
case DisconnectReason.UNKNOWN_REASON:
return 'UNKNOWN_REASON';
case DisconnectReason.CLIENT_INITIATED:
return 'CLIENT_INITIATED';
case DisconnectReason.DUPLICATE_IDENTITY:
return 'DUPLICATE_IDENTITY';
case DisconnectReason.SERVER_SHUTDOWN:
return 'SERVER_SHUTDOWN';
case DisconnectReason.PARTICIPANT_REMOVED:
return 'PARTICIPANT_REMOVED';
case DisconnectReason.ROOM_DELETED:
return 'ROOM_DELETED';
case DisconnectReason.STATE_MISMATCH:
return 'STATE_MISMATCH';
default:
return 'UNKNOWN';
}
}

export interface Room {
sid: string;
name: string;
Expand Down Expand Up @@ -315,6 +377,7 @@ export interface SimulcastCodecInfo {
mimeType: string;
mid: string;
cid: string;
layers: VideoLayer[];
}

export interface TrackInfo {
Expand Down Expand Up @@ -499,12 +562,17 @@ export interface ClientConfiguration {
video?: VideoConfiguration;
screen?: VideoConfiguration;
resumeConnection: ClientConfigSetting;
disabledCodecs?: DisabledCodecs;
}

export interface VideoConfiguration {
hardwareEncoder: ClientConfigSetting;
}

export interface DisabledCodecs {
codecs: Codec[];
}

export interface RTPStats {
startTime?: Date;
endTime?: Date;
Expand All @@ -531,7 +599,9 @@ export interface RTPStats {
jitterMax: number;
gapHistogram: { [key: number]: number };
nacks: number;
nackAcks: number;
nackMisses: number;
nackRepeated: number;
plis: number;
lastPli?: Date;
firs: number;
Expand Down Expand Up @@ -1015,7 +1085,7 @@ export const ParticipantInfo = {
};

function createBaseSimulcastCodecInfo(): SimulcastCodecInfo {
return { mimeType: '', mid: '', cid: '' };
return { mimeType: '', mid: '', cid: '', layers: [] };
}

export const SimulcastCodecInfo = {
Expand All @@ -1029,6 +1099,9 @@ export const SimulcastCodecInfo = {
if (message.cid !== '') {
writer.uint32(26).string(message.cid);
}
for (const v of message.layers) {
VideoLayer.encode(v!, writer.uint32(34).fork()).ldelim();
}
return writer;
},

Expand All @@ -1048,6 +1121,9 @@ export const SimulcastCodecInfo = {
case 3:
message.cid = reader.string();
break;
case 4:
message.layers.push(VideoLayer.decode(reader, reader.uint32()));
break;
default:
reader.skipType(tag & 7);
break;
Expand All @@ -1061,6 +1137,9 @@ export const SimulcastCodecInfo = {
mimeType: isSet(object.mimeType) ? String(object.mimeType) : '',
mid: isSet(object.mid) ? String(object.mid) : '',
cid: isSet(object.cid) ? String(object.cid) : '',
layers: Array.isArray(object?.layers)
? object.layers.map((e: any) => VideoLayer.fromJSON(e))
: [],
};
},

Expand All @@ -1069,6 +1148,11 @@ export const SimulcastCodecInfo = {
message.mimeType !== undefined && (obj.mimeType = message.mimeType);
message.mid !== undefined && (obj.mid = message.mid);
message.cid !== undefined && (obj.cid = message.cid);
if (message.layers) {
obj.layers = message.layers.map((e) => (e ? VideoLayer.toJSON(e) : undefined));
} else {
obj.layers = [];
}
return obj;
},

Expand All @@ -1077,6 +1161,7 @@ export const SimulcastCodecInfo = {
message.mimeType = object.mimeType ?? '';
message.mid = object.mid ?? '';
message.cid = object.cid ?? '';
message.layers = object.layers?.map((e) => VideoLayer.fromPartial(e)) || [];
return message;
},
};
Expand Down Expand Up @@ -1820,7 +1905,7 @@ export const ClientInfo = {
};

function createBaseClientConfiguration(): ClientConfiguration {
return { video: undefined, screen: undefined, resumeConnection: 0 };
return { video: undefined, screen: undefined, resumeConnection: 0, disabledCodecs: undefined };
}

export const ClientConfiguration = {
Expand All @@ -1834,6 +1919,9 @@ export const ClientConfiguration = {
if (message.resumeConnection !== 0) {
writer.uint32(24).int32(message.resumeConnection);
}
if (message.disabledCodecs !== undefined) {
DisabledCodecs.encode(message.disabledCodecs, writer.uint32(34).fork()).ldelim();
}
return writer;
},

Expand All @@ -1853,6 +1941,9 @@ export const ClientConfiguration = {
case 3:
message.resumeConnection = reader.int32() as any;
break;
case 4:
message.disabledCodecs = DisabledCodecs.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
Expand All @@ -1868,6 +1959,9 @@ export const ClientConfiguration = {
resumeConnection: isSet(object.resumeConnection)
? clientConfigSettingFromJSON(object.resumeConnection)
: 0,
disabledCodecs: isSet(object.disabledCodecs)
? DisabledCodecs.fromJSON(object.disabledCodecs)
: undefined,
};
},

Expand All @@ -1879,6 +1973,10 @@ export const ClientConfiguration = {
(obj.screen = message.screen ? VideoConfiguration.toJSON(message.screen) : undefined);
message.resumeConnection !== undefined &&
(obj.resumeConnection = clientConfigSettingToJSON(message.resumeConnection));
message.disabledCodecs !== undefined &&
(obj.disabledCodecs = message.disabledCodecs
? DisabledCodecs.toJSON(message.disabledCodecs)
: undefined);
return obj;
},

Expand All @@ -1895,6 +1993,10 @@ export const ClientConfiguration = {
? VideoConfiguration.fromPartial(object.screen)
: undefined;
message.resumeConnection = object.resumeConnection ?? 0;
message.disabledCodecs =
object.disabledCodecs !== undefined && object.disabledCodecs !== null
? DisabledCodecs.fromPartial(object.disabledCodecs)
: undefined;
return message;
},
};
Expand Down Expand Up @@ -1951,6 +2053,59 @@ export const VideoConfiguration = {
},
};

function createBaseDisabledCodecs(): DisabledCodecs {
return { codecs: [] };
}

export const DisabledCodecs = {
encode(message: DisabledCodecs, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
for (const v of message.codecs) {
Codec.encode(v!, writer.uint32(10).fork()).ldelim();
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): DisabledCodecs {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseDisabledCodecs();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.codecs.push(Codec.decode(reader, reader.uint32()));
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(object: any): DisabledCodecs {
return {
codecs: Array.isArray(object?.codecs) ? object.codecs.map((e: any) => Codec.fromJSON(e)) : [],
};
},

toJSON(message: DisabledCodecs): unknown {
const obj: any = {};
if (message.codecs) {
obj.codecs = message.codecs.map((e) => (e ? Codec.toJSON(e) : undefined));
} else {
obj.codecs = [];
}
return obj;
},

fromPartial<I extends Exact<DeepPartial<DisabledCodecs>, I>>(object: I): DisabledCodecs {
const message = createBaseDisabledCodecs();
message.codecs = object.codecs?.map((e) => Codec.fromPartial(e)) || [];
return message;
},
};

function createBaseRTPStats(): RTPStats {
return {
startTime: undefined,
Expand Down Expand Up @@ -1978,7 +2133,9 @@ function createBaseRTPStats(): RTPStats {
jitterMax: 0,
gapHistogram: {},
nacks: 0,
nackAcks: 0,
nackMisses: 0,
nackRepeated: 0,
plis: 0,
lastPli: undefined,
firs: 0,
Expand Down Expand Up @@ -2072,9 +2229,15 @@ export const RTPStats = {
if (message.nacks !== 0) {
writer.uint32(200).uint32(message.nacks);
}
if (message.nackAcks !== 0) {
writer.uint32(296).uint32(message.nackAcks);
}
if (message.nackMisses !== 0) {
writer.uint32(208).uint32(message.nackMisses);
}
if (message.nackRepeated !== 0) {
writer.uint32(304).uint32(message.nackRepeated);
}
if (message.plis !== 0) {
writer.uint32(216).uint32(message.plis);
}
Expand Down Expand Up @@ -2193,9 +2356,15 @@ export const RTPStats = {
case 25:
message.nacks = reader.uint32();
break;
case 37:
message.nackAcks = reader.uint32();
break;
case 26:
message.nackMisses = reader.uint32();
break;
case 38:
message.nackRepeated = reader.uint32();
break;
case 27:
message.plis = reader.uint32();
break;
Expand Down Expand Up @@ -2273,7 +2442,9 @@ export const RTPStats = {
)
: {},
nacks: isSet(object.nacks) ? Number(object.nacks) : 0,
nackAcks: isSet(object.nackAcks) ? Number(object.nackAcks) : 0,
nackMisses: isSet(object.nackMisses) ? Number(object.nackMisses) : 0,
nackRepeated: isSet(object.nackRepeated) ? Number(object.nackRepeated) : 0,
plis: isSet(object.plis) ? Number(object.plis) : 0,
lastPli: isSet(object.lastPli) ? fromJsonTimestamp(object.lastPli) : undefined,
firs: isSet(object.firs) ? Number(object.firs) : 0,
Expand Down Expand Up @@ -2327,7 +2498,9 @@ export const RTPStats = {
});
}
message.nacks !== undefined && (obj.nacks = Math.round(message.nacks));
message.nackAcks !== undefined && (obj.nackAcks = Math.round(message.nackAcks));
message.nackMisses !== undefined && (obj.nackMisses = Math.round(message.nackMisses));
message.nackRepeated !== undefined && (obj.nackRepeated = Math.round(message.nackRepeated));
message.plis !== undefined && (obj.plis = Math.round(message.plis));
message.lastPli !== undefined && (obj.lastPli = message.lastPli.toISOString());
message.firs !== undefined && (obj.firs = Math.round(message.firs));
Expand Down Expand Up @@ -2376,7 +2549,9 @@ export const RTPStats = {
return acc;
}, {});
message.nacks = object.nacks ?? 0;
message.nackAcks = object.nackAcks ?? 0;
message.nackMisses = object.nackMisses ?? 0;
message.nackRepeated = object.nackRepeated ?? 0;
message.plis = object.plis ?? 0;
message.lastPli = object.lastPli ?? undefined;
message.firs = object.firs ?? 0;
Expand Down Expand Up @@ -2480,9 +2655,9 @@ const btoa: (bin: string) => string =
globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'));
function base64FromBytes(arr: Uint8Array): string {
const bin: string[] = [];
arr.forEach((byte) => {
for (const byte of arr) {
bin.push(String.fromCharCode(byte));
});
}
return btoa(bin.join(''));
}

Expand Down
Loading