mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
fix(voice): send screen shares at the quality the user picked (#2840)
This commit is contained in:
@@ -23,10 +23,6 @@ import {
|
||||
ExperimentDeliveryConfigResponse,
|
||||
ExperimentDeliveryConfigUpdateRequest,
|
||||
} from '@fluxer/schema/src/domains/experiment/ExperimentSchemas';
|
||||
import {
|
||||
ScreenShareDeliveryConfigResponse,
|
||||
ScreenShareDeliveryConfigUpdateRequest,
|
||||
} from '@fluxer/schema/src/domains/experiment/ScreenShareDeliverySchemas';
|
||||
import {GuildMemberResponse} from '@fluxer/schema/src/domains/guild/GuildMemberSchemas';
|
||||
import {
|
||||
InstanceCaptchaProviderSchema,
|
||||
@@ -648,7 +644,6 @@ export const InstanceConfigResponse = z.object({
|
||||
sso: SsoConfigResponse,
|
||||
gateway_rollout: GatewayRolloutConfigResponse,
|
||||
voice_noise_suppression: VoiceNoiseSuppressionConfigResponse,
|
||||
screen_share_delivery: ScreenShareDeliveryConfigResponse,
|
||||
experiment_delivery: ExperimentDeliveryConfigResponse,
|
||||
registration: InstanceRegistrationResponse,
|
||||
self_hosted: z.boolean(),
|
||||
@@ -685,7 +680,6 @@ const InstancePolicyUpdateSchema = z.object({
|
||||
export const InstanceConfigUpdateRequest = z.object({
|
||||
gateway_rollout: GatewayRolloutConfigUpdateRequest.nullish(),
|
||||
voice_noise_suppression: VoiceNoiseSuppressionConfigUpdateRequest.nullish(),
|
||||
screen_share_delivery: ScreenShareDeliveryConfigUpdateRequest.nullish(),
|
||||
experiment_delivery: ExperimentDeliveryConfigUpdateRequest.nullish(),
|
||||
registration: z
|
||||
.object({
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {EXPERIMENT_BUCKET_RESOLUTION, experimentBucket} from '@fluxer/schema/src/domains/experiment/ExperimentBucket';
|
||||
import {z} from 'zod';
|
||||
|
||||
const CLIENT_BEHAVIOR_MAX_TARGETED_USERS = 1000;
|
||||
const CLIENT_BEHAVIOR_ASSIGNMENT_SOURCES = ['user_rule', 'canary'] as const;
|
||||
|
||||
export function createClientBehaviorExperiment({defaultRolloutSalt}: {defaultRolloutSalt: string}) {
|
||||
const targetIdSchema = z.string().regex(/^\d{1,20}$/u);
|
||||
const targetedUserIdsSchema = z.array(targetIdSchema).max(CLIENT_BEHAVIOR_MAX_TARGETED_USERS);
|
||||
const configFields = {
|
||||
enabled: z.boolean(),
|
||||
config_version: z.number().int().min(0),
|
||||
rollout_basis_points: z.number().int().min(0).max(EXPERIMENT_BUCKET_RESOLUTION),
|
||||
rollout_salt: z.string().trim().min(1).max(64),
|
||||
included_user_ids: targetedUserIdsSchema,
|
||||
excluded_user_ids: targetedUserIdsSchema,
|
||||
};
|
||||
const ConfigSchema = z.object({
|
||||
enabled: configFields.enabled.default(false),
|
||||
config_version: configFields.config_version.default(0),
|
||||
rollout_basis_points: configFields.rollout_basis_points.default(0),
|
||||
rollout_salt: configFields.rollout_salt.default(defaultRolloutSalt),
|
||||
included_user_ids: configFields.included_user_ids.default([]),
|
||||
excluded_user_ids: configFields.excluded_user_ids.default([]),
|
||||
});
|
||||
const ConfigUpdateRequest = z.object(configFields).omit({config_version: true}).partial();
|
||||
const AssignmentResponse = z.object({
|
||||
enabled: configFields.enabled,
|
||||
config_version: z.number().int(),
|
||||
user_targeted: z.boolean(),
|
||||
source: z.enum(CLIENT_BEHAVIOR_ASSIGNMENT_SOURCES).nullable(),
|
||||
});
|
||||
type Config = z.infer<typeof ConfigSchema>;
|
||||
type Assignment = z.infer<typeof AssignmentResponse>;
|
||||
const INERT_ASSIGNMENT: Assignment = {
|
||||
enabled: false,
|
||||
config_version: 0,
|
||||
user_targeted: false,
|
||||
source: null,
|
||||
};
|
||||
const resolveAssignment = (config: Config, userId: string): Assignment => {
|
||||
if (!config.enabled) {
|
||||
return {...INERT_ASSIGNMENT, config_version: config.config_version};
|
||||
}
|
||||
const shared = {enabled: true, config_version: config.config_version};
|
||||
if (config.excluded_user_ids.includes(userId)) {
|
||||
return {...shared, user_targeted: false, source: null};
|
||||
}
|
||||
if (config.included_user_ids.includes(userId)) {
|
||||
return {...shared, user_targeted: true, source: 'user_rule'};
|
||||
}
|
||||
const inCanary = experimentBucket(userId, config.rollout_salt) < config.rollout_basis_points;
|
||||
return {...shared, user_targeted: inCanary, source: inCanary ? 'canary' : null};
|
||||
};
|
||||
return {ConfigSchema, ConfigUpdateRequest, AssignmentResponse, INERT_ASSIGNMENT, resolveAssignment};
|
||||
}
|
||||
@@ -4,10 +4,6 @@ import {
|
||||
INERT_VOICE_NOISE_SUPPRESSION_ASSIGNMENT,
|
||||
VoiceNoiseSuppressionAssignmentResponse,
|
||||
} from '@fluxer/schema/src/domains/admin/VoiceNoiseSuppressionSchemas';
|
||||
import {
|
||||
INERT_SCREEN_SHARE_DELIVERY_ASSIGNMENT,
|
||||
ScreenShareDeliveryAssignmentResponse,
|
||||
} from '@fluxer/schema/src/domains/experiment/ScreenShareDeliverySchemas';
|
||||
import {z} from 'zod';
|
||||
|
||||
export const EXPERIMENT_MIN_POLL_INTERVAL_SECONDS = 60;
|
||||
@@ -46,7 +42,6 @@ export type ExperimentDeliveryConfigResponse = z.infer<typeof ExperimentDelivery
|
||||
|
||||
const ExperimentAssignmentsSchema = z.object({
|
||||
voice_noise_suppression: VoiceNoiseSuppressionAssignmentResponse.optional(),
|
||||
screen_share_delivery: ScreenShareDeliveryAssignmentResponse.optional(),
|
||||
});
|
||||
|
||||
export const ExperimentAssignmentsResponse = z.object({
|
||||
@@ -68,9 +63,3 @@ export function readVoiceNoiseSuppressionAssignment(
|
||||
): VoiceNoiseSuppressionAssignmentResponse {
|
||||
return response.assignments.voice_noise_suppression ?? INERT_VOICE_NOISE_SUPPRESSION_ASSIGNMENT;
|
||||
}
|
||||
|
||||
export function readScreenShareDeliveryAssignment(
|
||||
response: ExperimentAssignmentsResponse,
|
||||
): ScreenShareDeliveryAssignmentResponse {
|
||||
return response.assignments.screen_share_delivery ?? INERT_SCREEN_SHARE_DELIVERY_ASSIGNMENT;
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {createClientBehaviorExperiment} from '@fluxer/schema/src/domains/experiment/ClientBehaviorExperiment';
|
||||
import type {z} from 'zod';
|
||||
|
||||
const screenShareDelivery = createClientBehaviorExperiment({defaultRolloutSalt: 'screen-share-delivery-v1'});
|
||||
|
||||
export const ScreenShareDeliveryConfigSchema = screenShareDelivery.ConfigSchema;
|
||||
|
||||
export type ScreenShareDeliveryConfig = z.infer<typeof ScreenShareDeliveryConfigSchema>;
|
||||
|
||||
export const ScreenShareDeliveryConfigUpdateRequest = screenShareDelivery.ConfigUpdateRequest;
|
||||
|
||||
export type ScreenShareDeliveryConfigUpdateRequest = z.infer<typeof ScreenShareDeliveryConfigUpdateRequest>;
|
||||
|
||||
export const ScreenShareDeliveryConfigResponse = screenShareDelivery.ConfigSchema;
|
||||
|
||||
export const ScreenShareDeliveryAssignmentResponse = screenShareDelivery.AssignmentResponse;
|
||||
|
||||
export type ScreenShareDeliveryAssignmentResponse = z.infer<typeof ScreenShareDeliveryAssignmentResponse>;
|
||||
|
||||
export const INERT_SCREEN_SHARE_DELIVERY_ASSIGNMENT: ScreenShareDeliveryAssignmentResponse =
|
||||
screenShareDelivery.INERT_ASSIGNMENT;
|
||||
|
||||
export function resolveScreenShareDeliveryAssignment(
|
||||
config: ScreenShareDeliveryConfig,
|
||||
userId: string,
|
||||
): ScreenShareDeliveryAssignmentResponse {
|
||||
return screenShareDelivery.resolveAssignment(config, userId);
|
||||
}
|
||||
Reference in New Issue
Block a user