mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-19 05:55:34 +09:00
fix(voice): stop screen shares failing to reach their viewers (#2835)
This commit is contained in:
1 parent
f32356801d
commit
bc47a724af
119 files changed
+27942
-12524
No files matched your search
@@ -0,0 +1,58 @@
|
||||
// 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,6 +4,10 @@ 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;
|
||||
@@ -42,6 +46,7 @@ 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({
|
||||
@@ -63,3 +68,9 @@ 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;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// 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