Skip to content

Commit

Permalink
fix: don't run participant status check until a game is initialized
Browse files Browse the repository at this point in the history
a stupid hardcoded timeout hack was the only measure in place for this
previously
  • Loading branch information
sgfost committed Dec 12, 2024
1 parent edc2fff commit 78061aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
5 changes: 4 additions & 1 deletion client/src/api/study/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export class StudyAPI {
constructor(public store: TStore, public ajax: AjaxRequest) {}

async getProlificParticipantStatus(): Promise<ProlificParticipantStatus> {
return this.ajax.get(url("/study/prolific/status"), ({ data }) => {
return this.ajax.get(url("/study/prolific/status"), ({ data, status }) => {
if (status !== 200) {
return null;
}
return data;
});
}
Expand Down
10 changes: 6 additions & 4 deletions client/src/views/ProlificStudy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ export default class ProlificStudy extends Vue {
this.api.room = await this.$client.create(SOLO_ROOM_NAME, { type });
applySoloGameServerResponses(this.api.room, this);
this.started = true;
setTimeout(() => {
// wait a bit for the room to be initialized
this.api.room.onMessage("ready", () => {
this.fetchProlificParticipantStatus();
}, 3 * 1000);
});
} catch (err) {
console.log("Error creating game room");
console.error(err);
Expand All @@ -132,7 +131,10 @@ export default class ProlificStudy extends Vue {
async fetchProlificParticipantStatus() {
this.statusLoading = true;
this.participantStatus = await this.studyApi.getProlificParticipantStatus();
const status = await this.studyApi.getProlificParticipantStatus();
if (status) {
this.participantStatus = status;
}
this.statusLoading = false;
}
Expand Down
7 changes: 7 additions & 0 deletions server/src/rooms/sologame/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class InitGameCmd extends Cmd<{ user: User }> {
new SetGameParamsCmd(),
new PersistGameCmd(),
new SetFirstRoundCmd(),
new BroadcastReadyCmd(),
];
}
}
Expand Down Expand Up @@ -120,6 +121,12 @@ export class SetFirstRoundCmd extends CmdWithoutPayload {
}
}

export class BroadcastReadyCmd extends CmdWithoutPayload {
execute() {
this.room.broadcast("ready", { kind: "ready" });
}
}

export class SendHiddenParamsCmd extends CmdWithoutPayload {
execute() {
const data: any = {};
Expand Down
9 changes: 9 additions & 0 deletions server/src/services/study.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ export class StudyService extends BaseService {
];
let currentStep = 1;

// fail nicely if one of the games hasn't been initialized yet
if (soloPlayers.some(p => !p.game)) {
throw new ServerError({
code: 202,
message: "Game not yet initialized",
displayMessage: "Game not yet initialized",
});
}

const hasPlayedBaseline = !!soloPlayers.find(p => p.game.type === "prolificBaseline");
const hasPlayedVariable = !!soloPlayers.find(p => p.game.type === "prolificVariable");
if (hasPlayedVariable) {
Expand Down

0 comments on commit 78061aa

Please sign in to comment.