Skip to content

Commit

Permalink
Emit Participant.PermissionChanged event also for remote participan…
Browse files Browse the repository at this point in the history
…ts (#569)

* emit Participant.PermissionChanged event also for remote participants

* fix typo

* cleanup

* update protocol with source permissions

* better compare

* Create angry-pugs-repair.md
  • Loading branch information
lukasIO committed Feb 3, 2023
1 parent 3370684 commit b53f5c5
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-pugs-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Emit `Participant.PermissionChanged` event also for remote participants
4 changes: 2 additions & 2 deletions src/proto/google/protobuf/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const Timestamp = {
declare var self: any | undefined;
declare var window: any | undefined;
declare var global: any | undefined;
var globalThis: any = (() => {
var tsProtoGlobalThis: any = (() => {
if (typeof globalThis !== "undefined") {
return globalThis;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function longToNumber(long: Long): number {
if (long.gt(Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
return long.toNumber();
}
Expand Down
51 changes: 42 additions & 9 deletions src/proto/livekit_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ export interface ParticipantPermission {
canPublish: boolean;
/** allow participant to publish data */
canPublishData: boolean;
/** sources that are allowed to be published */
canPublishSources: TrackSource[];
/** indicates that it's hidden to others */
hidden: boolean;
/** indicates it's a recorder instance */
Expand Down Expand Up @@ -940,7 +942,14 @@ export const Codec = {
};

function createBaseParticipantPermission(): ParticipantPermission {
return { canSubscribe: false, canPublish: false, canPublishData: false, hidden: false, recorder: false };
return {
canSubscribe: false,
canPublish: false,
canPublishData: false,
canPublishSources: [],
hidden: false,
recorder: false,
};
}

export const ParticipantPermission = {
Expand All @@ -954,6 +963,11 @@ export const ParticipantPermission = {
if (message.canPublishData === true) {
writer.uint32(24).bool(message.canPublishData);
}
writer.uint32(74).fork();
for (const v of message.canPublishSources) {
writer.int32(v);
}
writer.ldelim();
if (message.hidden === true) {
writer.uint32(56).bool(message.hidden);
}
Expand All @@ -979,6 +993,16 @@ export const ParticipantPermission = {
case 3:
message.canPublishData = reader.bool();
break;
case 9:
if ((tag & 7) === 2) {
const end2 = reader.uint32() + reader.pos;
while (reader.pos < end2) {
message.canPublishSources.push(reader.int32() as any);
}
} else {
message.canPublishSources.push(reader.int32() as any);
}
break;
case 7:
message.hidden = reader.bool();
break;
Expand All @@ -998,6 +1022,9 @@ export const ParticipantPermission = {
canSubscribe: isSet(object.canSubscribe) ? Boolean(object.canSubscribe) : false,
canPublish: isSet(object.canPublish) ? Boolean(object.canPublish) : false,
canPublishData: isSet(object.canPublishData) ? Boolean(object.canPublishData) : false,
canPublishSources: Array.isArray(object?.canPublishSources)
? object.canPublishSources.map((e: any) => trackSourceFromJSON(e))
: [],
hidden: isSet(object.hidden) ? Boolean(object.hidden) : false,
recorder: isSet(object.recorder) ? Boolean(object.recorder) : false,
};
Expand All @@ -1008,6 +1035,11 @@ export const ParticipantPermission = {
message.canSubscribe !== undefined && (obj.canSubscribe = message.canSubscribe);
message.canPublish !== undefined && (obj.canPublish = message.canPublish);
message.canPublishData !== undefined && (obj.canPublishData = message.canPublishData);
if (message.canPublishSources) {
obj.canPublishSources = message.canPublishSources.map((e) => trackSourceToJSON(e));
} else {
obj.canPublishSources = [];
}
message.hidden !== undefined && (obj.hidden = message.hidden);
message.recorder !== undefined && (obj.recorder = message.recorder);
return obj;
Expand All @@ -1018,6 +1050,7 @@ export const ParticipantPermission = {
message.canSubscribe = object.canSubscribe ?? false;
message.canPublish = object.canPublish ?? false;
message.canPublishData = object.canPublishData ?? false;
message.canPublishSources = object.canPublishSources?.map((e) => e) || [];
message.hidden = object.hidden ?? false;
message.recorder = object.recorder ?? false;
return message;
Expand Down Expand Up @@ -2940,7 +2973,7 @@ export const TimedVersion = {
declare var self: any | undefined;
declare var window: any | undefined;
declare var global: any | undefined;
var globalThis: any = (() => {
var tsProtoGlobalThis: any = (() => {
if (typeof globalThis !== "undefined") {
return globalThis;
}
Expand All @@ -2957,10 +2990,10 @@ var globalThis: any = (() => {
})();

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
if (tsProtoGlobalThis.Buffer) {
return Uint8Array.from(tsProtoGlobalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
const bin = tsProtoGlobalThis.atob(b64);
const arr = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; ++i) {
arr[i] = bin.charCodeAt(i);
Expand All @@ -2970,14 +3003,14 @@ function bytesFromBase64(b64: string): Uint8Array {
}

function base64FromBytes(arr: Uint8Array): string {
if (globalThis.Buffer) {
return globalThis.Buffer.from(arr).toString("base64");
if (tsProtoGlobalThis.Buffer) {
return tsProtoGlobalThis.Buffer.from(arr).toString("base64");
} else {
const bin: string[] = [];
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
});
return globalThis.btoa(bin.join(""));
return tsProtoGlobalThis.btoa(bin.join(""));
}
}

Expand Down Expand Up @@ -3017,7 +3050,7 @@ function fromJsonTimestamp(o: any): Date {

function longToNumber(long: Long): number {
if (long.gt(Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
return long.toNumber();
}
Expand Down
103 changes: 99 additions & 4 deletions src/proto/livekit_rtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export interface SignalRequest {
| { $case: "subscriptionPermission"; subscriptionPermission: SubscriptionPermission }
| { $case: "syncState"; syncState: SyncState }
| { $case: "simulate"; simulate: SimulateScenario }
| { $case: "ping"; ping: number };
| { $case: "ping"; ping: number }
| { $case: "updateMetadata"; updateMetadata: UpdateParticipantMetadata };
}

export interface SignalResponse {
Expand Down Expand Up @@ -278,6 +279,16 @@ export interface UpdateTrackSettings {
/** for video, height to receive */
height: number;
fps: number;
/**
* subscription priority. 1 being the highest (0 is unset)
* when unset, server sill assign priority based on the order of subscription
* server will use priority in the following ways:
* 1. when subscribed tracks exceed per-participant subscription limit, server will
* pause the lowest priority tracks
* 2. when the network is congested, server will assign available bandwidth to
* higher priority tracks first. lowest priority tracks can be paused
*/
priority: number;
}

export interface LeaveRequest {
Expand All @@ -295,6 +306,10 @@ export interface UpdateVideoLayers {
layers: VideoLayer[];
}

export interface UpdateParticipantMetadata {
metadata: string;
}

export interface ICEServer {
urls: string[];
username: string;
Expand Down Expand Up @@ -434,6 +449,9 @@ export const SignalRequest = {
if (message.message?.$case === "ping") {
writer.uint32(112).int64(message.message.ping);
}
if (message.message?.$case === "updateMetadata") {
UpdateParticipantMetadata.encode(message.message.updateMetadata, writer.uint32(122).fork()).ldelim();
}
return writer;
},

Expand Down Expand Up @@ -489,6 +507,12 @@ export const SignalRequest = {
case 14:
message.message = { $case: "ping", ping: longToNumber(reader.int64() as Long) };
break;
case 15:
message.message = {
$case: "updateMetadata",
updateMetadata: UpdateParticipantMetadata.decode(reader, reader.uint32()),
};
break;
default:
reader.skipType(tag & 7);
break;
Expand Down Expand Up @@ -528,6 +552,8 @@ export const SignalRequest = {
? { $case: "simulate", simulate: SimulateScenario.fromJSON(object.simulate) }
: isSet(object.ping)
? { $case: "ping", ping: Number(object.ping) }
: isSet(object.updateMetadata)
? { $case: "updateMetadata", updateMetadata: UpdateParticipantMetadata.fromJSON(object.updateMetadata) }
: undefined,
};
},
Expand Down Expand Up @@ -564,6 +590,9 @@ export const SignalRequest = {
message.message?.$case === "simulate" &&
(obj.simulate = message.message?.simulate ? SimulateScenario.toJSON(message.message?.simulate) : undefined);
message.message?.$case === "ping" && (obj.ping = Math.round(message.message?.ping));
message.message?.$case === "updateMetadata" && (obj.updateMetadata = message.message?.updateMetadata
? UpdateParticipantMetadata.toJSON(message.message?.updateMetadata)
: undefined);
return obj;
},

Expand Down Expand Up @@ -650,6 +679,16 @@ export const SignalRequest = {
if (object.message?.$case === "ping" && object.message?.ping !== undefined && object.message?.ping !== null) {
message.message = { $case: "ping", ping: object.message.ping };
}
if (
object.message?.$case === "updateMetadata" &&
object.message?.updateMetadata !== undefined &&
object.message?.updateMetadata !== null
) {
message.message = {
$case: "updateMetadata",
updateMetadata: UpdateParticipantMetadata.fromPartial(object.message.updateMetadata),
};
}
return message;
},
};
Expand Down Expand Up @@ -1949,7 +1988,7 @@ export const UpdateSubscription = {
};

function createBaseUpdateTrackSettings(): UpdateTrackSettings {
return { trackSids: [], disabled: false, quality: 0, width: 0, height: 0, fps: 0 };
return { trackSids: [], disabled: false, quality: 0, width: 0, height: 0, fps: 0, priority: 0 };
}

export const UpdateTrackSettings = {
Expand All @@ -1972,6 +2011,9 @@ export const UpdateTrackSettings = {
if (message.fps !== 0) {
writer.uint32(56).uint32(message.fps);
}
if (message.priority !== 0) {
writer.uint32(64).uint32(message.priority);
}
return writer;
},

Expand Down Expand Up @@ -2000,6 +2042,9 @@ export const UpdateTrackSettings = {
case 7:
message.fps = reader.uint32();
break;
case 8:
message.priority = reader.uint32();
break;
default:
reader.skipType(tag & 7);
break;
Expand All @@ -2016,6 +2061,7 @@ export const UpdateTrackSettings = {
width: isSet(object.width) ? Number(object.width) : 0,
height: isSet(object.height) ? Number(object.height) : 0,
fps: isSet(object.fps) ? Number(object.fps) : 0,
priority: isSet(object.priority) ? Number(object.priority) : 0,
};
},

Expand All @@ -2031,6 +2077,7 @@ export const UpdateTrackSettings = {
message.width !== undefined && (obj.width = Math.round(message.width));
message.height !== undefined && (obj.height = Math.round(message.height));
message.fps !== undefined && (obj.fps = Math.round(message.fps));
message.priority !== undefined && (obj.priority = Math.round(message.priority));
return obj;
},

Expand All @@ -2042,6 +2089,7 @@ export const UpdateTrackSettings = {
message.width = object.width ?? 0;
message.height = object.height ?? 0;
message.fps = object.fps ?? 0;
message.priority = object.priority ?? 0;
return message;
},
};
Expand Down Expand Up @@ -2166,6 +2214,53 @@ export const UpdateVideoLayers = {
},
};

function createBaseUpdateParticipantMetadata(): UpdateParticipantMetadata {
return { metadata: "" };
}

export const UpdateParticipantMetadata = {
encode(message: UpdateParticipantMetadata, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.metadata !== "") {
writer.uint32(10).string(message.metadata);
}
return writer;
},

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

fromJSON(object: any): UpdateParticipantMetadata {
return { metadata: isSet(object.metadata) ? String(object.metadata) : "" };
},

toJSON(message: UpdateParticipantMetadata): unknown {
const obj: any = {};
message.metadata !== undefined && (obj.metadata = message.metadata);
return obj;
},

fromPartial<I extends Exact<DeepPartial<UpdateParticipantMetadata>, I>>(object: I): UpdateParticipantMetadata {
const message = createBaseUpdateParticipantMetadata();
message.metadata = object.metadata ?? "";
return message;
},
};

function createBaseICEServer(): ICEServer {
return { urls: [], username: "", credential: "" };
}
Expand Down Expand Up @@ -3296,7 +3391,7 @@ export const SimulateScenario = {
declare var self: any | undefined;
declare var window: any | undefined;
declare var global: any | undefined;
var globalThis: any = (() => {
var tsProtoGlobalThis: any = (() => {
if (typeof globalThis !== "undefined") {
return globalThis;
}
Expand Down Expand Up @@ -3326,7 +3421,7 @@ export type Exact<P, I extends P> = P extends Builtin ? P

function longToNumber(long: Long): number {
if (long.gt(Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
return long.toNumber();
}
Expand Down
Loading

0 comments on commit b53f5c5

Please sign in to comment.