basic MP functionality working

This commit is contained in:
Shaheed Azaad
2025-07-17 10:09:20 +02:00
parent 02734040cb
commit e9565471cb
8 changed files with 805 additions and 23 deletions

View File

@@ -5,6 +5,11 @@ import * as schema from '$lib/server/db/schema';
import { eq } from 'drizzle-orm';
import argon2 from '@node-rs/argon2';
import { dev } from '$app/environment';
import { sessionManager } from '$lib/server/multiplayer/sessionManager';
// Initialize session manager (this starts the WebSocket server)
console.log('Initializing multiplayer session manager...');
// The sessionManager is initialized when imported
const ensureDefaultAdmin = async () => {
if (!dev) return;

View File

@@ -165,7 +165,9 @@ export async function GET({ params, cookies, getClientAddress, request }) {
}
}
const s3Prefix = `experiments/${experimentId}/`;
// Files are stored in the user's experiment_files directory
const createdBy = experiment.createdBy;
const s3Prefix = `${createdBy}/${experimentId}/experiment_files/`;
const filePath = path === '' ? 'index.html' : path;
const key = `${s3Prefix}${filePath}`;
@@ -199,15 +201,15 @@ export async function GET({ params, cookies, getClientAddress, request }) {
// Get all files in the experiment directory to create a resource manifest
const listCommand = new ListObjectsV2Command({
Bucket: S3_BUCKET,
Prefix: `experiments/${experimentId}/`
Prefix: s3Prefix
});
const listResponse = await s3.send(listCommand);
// Create resource manifest for PsychoJS
const resources = (listResponse.Contents || [])
.filter(obj => obj.Key && obj.Key !== `experiments/${experimentId}/index.html`)
.filter(obj => obj.Key && obj.Key !== `${s3Prefix}index.html`)
.map(obj => {
const relativePath = obj.Key!.replace(`experiments/${experimentId}/`, '');
const relativePath = obj.Key!.replace(s3Prefix, '');
return {
name: relativePath,
path: relativePath

View File

@@ -31,6 +31,15 @@ const vendorFileRules = [
export async function GET({ params, cookies, getClientAddress, request }) {
const { experimentId, path } = params;
// Check if the experiment exists
const experiment = await db.query.experiment.findFirst({
where: eq(schema.experiment.id, experimentId)
});
if (!experiment) {
throw error(404, 'Experiment not found');
}
// Map of requested CSS files to their location in the static directory.
const staticCssMap: Record<string, string> = {
'lib/vendors/survey.widgets.css': 'static/lib/psychoJS/surveyJS/survey.widgets.css',
@@ -151,7 +160,9 @@ export async function GET({ params, cookies, getClientAddress, request }) {
}
}
const s3Prefix = `experiments/${experimentId}/`;
// Files are stored in the user's experiment_files directory
const createdBy = experiment.createdBy;
const s3Prefix = `${createdBy}/${experimentId}/experiment_files/`;
const filePath = path === '' ? 'index.html' : path;
const key = `${s3Prefix}${filePath}`;
@@ -180,20 +191,22 @@ export async function GET({ params, cookies, getClientAddress, request }) {
// For PsychoJS experiments, we need to set the base href to the experiment root
// so that relative paths like "stimuli/image.jpg" resolve correctly
const basePath = `/public/run/${experimentId}/`;
// Use the request URL to determine if this is multiplayer or single player
const isMultiplayer = request.url.includes('/multiplayer/');
const basePath = isMultiplayer ? `/public/multiplayer/run/${experimentId}/` : `/public/run/${experimentId}/`;
// Get all files in the experiment directory to create a resource manifest
const listCommand = new ListObjectsV2Command({
Bucket: S3_BUCKET,
Prefix: `experiments/${experimentId}/`
Prefix: s3Prefix
});
const listResponse = await s3.send(listCommand);
// Create resource manifest for PsychoJS
const resources = (listResponse.Contents || [])
.filter(obj => obj.Key && obj.Key !== `experiments/${experimentId}/index.html`)
.filter(obj => obj.Key && obj.Key !== `${s3Prefix}index.html`)
.map(obj => {
const relativePath = obj.Key!.replace(`experiments/${experimentId}/`, '');
const relativePath = obj.Key!.replace(s3Prefix, '');
return {
name: relativePath,
path: relativePath