mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-01-19 06:46:28 +01:00
added wordquiz handler
This commit is contained in:
parent
2cc9598141
commit
e6d4d2a8f2
@ -77,7 +77,7 @@ export class QuestionParser implements IMessageParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IQuestion
|
export interface IQuestion
|
||||||
{
|
{
|
||||||
id: number;
|
id: number;
|
||||||
number: number;
|
number: number;
|
||||||
|
@ -12,6 +12,7 @@ import { RoomPermissionsHandler } from './handler/RoomPermissionsHandler';
|
|||||||
import { RoomPresentHandler } from './handler/RoomPresentHandler';
|
import { RoomPresentHandler } from './handler/RoomPresentHandler';
|
||||||
import { RoomSessionHandler } from './handler/RoomSessionHandler';
|
import { RoomSessionHandler } from './handler/RoomSessionHandler';
|
||||||
import { RoomUsersHandler } from './handler/RoomUsersHandler';
|
import { RoomUsersHandler } from './handler/RoomUsersHandler';
|
||||||
|
import { WordQuizHandler } from './handler/WordQuizHandler';
|
||||||
import { IRoomHandlerListener } from './IRoomHandlerListener';
|
import { IRoomHandlerListener } from './IRoomHandlerListener';
|
||||||
import { IRoomSession } from './IRoomSession';
|
import { IRoomSession } from './IRoomSession';
|
||||||
import { IRoomSessionManager } from './IRoomSessionManager';
|
import { IRoomSessionManager } from './IRoomSessionManager';
|
||||||
@ -77,6 +78,7 @@ export class RoomSessionManager extends NitroManager implements IRoomSessionMana
|
|||||||
new RoomUsersHandler(connection, this),
|
new RoomUsersHandler(connection, this),
|
||||||
new RoomPresentHandler(connection, this),
|
new RoomPresentHandler(connection, this),
|
||||||
new GenericErrorHandler(connection, this),
|
new GenericErrorHandler(connection, this),
|
||||||
|
new WordQuizHandler(connection, this),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { IRoomSession } from '../IRoomSession';
|
import { IQuestion } from '../../communication/messages/parser/poll/QuestionParser';
|
||||||
|
import { IRoomSession } from '../IRoomSession';
|
||||||
import { RoomSessionEvent } from './RoomSessionEvent';
|
import { RoomSessionEvent } from './RoomSessionEvent';
|
||||||
|
|
||||||
export class RoomSessionWordQuizEvent extends RoomSessionEvent
|
export class RoomSessionWordQuizEvent extends RoomSessionEvent
|
||||||
@ -12,7 +13,7 @@ export class RoomSessionWordQuizEvent extends RoomSessionEvent
|
|||||||
private _pollId: number = -1;
|
private _pollId: number = -1;
|
||||||
private _questionId: number = -1;
|
private _questionId: number = -1;
|
||||||
private _duration: number = -1;
|
private _duration: number = -1;
|
||||||
private _question: string[] = null;
|
private _question: IQuestion = null;
|
||||||
private _userId: number = -1;
|
private _userId: number = -1;
|
||||||
private _value: string;
|
private _value: string;
|
||||||
private _answerCounts: Map<string, number>;
|
private _answerCounts: Map<string, number>;
|
||||||
@ -69,12 +70,12 @@ export class RoomSessionWordQuizEvent extends RoomSessionEvent
|
|||||||
this._duration = k;
|
this._duration = k;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get question(): string[]
|
public get question(): IQuestion
|
||||||
{
|
{
|
||||||
return this._question;
|
return this._question;
|
||||||
}
|
}
|
||||||
|
|
||||||
public set question(k: string[])
|
public set question(k: IQuestion)
|
||||||
{
|
{
|
||||||
this._question = k;
|
this._question = k;
|
||||||
}
|
}
|
||||||
|
82
src/nitro/session/handler/WordQuizHandler.ts
Normal file
82
src/nitro/session/handler/WordQuizHandler.ts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import { IConnection } from '../../../core/communication/connections/IConnection';
|
||||||
|
import { QuestionAnsweredEvent } from '../../communication/messages/incoming/poll/QuestionAnsweredEvent';
|
||||||
|
import { QuestionEvent } from '../../communication/messages/incoming/poll/QuestionEvent';
|
||||||
|
import { QuestionFinishedEvent } from '../../communication/messages/incoming/poll/QuestionFinishedEvent';
|
||||||
|
import { RoomSessionWordQuizEvent } from '../events/RoomSessionWordQuizEvent';
|
||||||
|
import { IRoomHandlerListener } from '../IRoomHandlerListener';
|
||||||
|
import { BaseHandler } from './BaseHandler';
|
||||||
|
|
||||||
|
export class WordQuizHandler extends BaseHandler
|
||||||
|
{
|
||||||
|
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||||
|
{
|
||||||
|
super(connection, listener);
|
||||||
|
|
||||||
|
connection.addMessageEvent(new QuestionEvent(this.onQuestionEvent.bind(this)));
|
||||||
|
connection.addMessageEvent(new QuestionAnsweredEvent(this.onQuestionAnsweredEvent.bind(this)));
|
||||||
|
connection.addMessageEvent(new QuestionFinishedEvent(this.onQuestionFinishedEvent.bind(this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private onQuestionEvent(event: QuestionEvent): void
|
||||||
|
{
|
||||||
|
if(!this.listener) return;
|
||||||
|
|
||||||
|
const session = this.listener.getSession(this.roomId);
|
||||||
|
|
||||||
|
if(!session) return;
|
||||||
|
|
||||||
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
if(!parser) return;
|
||||||
|
|
||||||
|
const quizEvent = new RoomSessionWordQuizEvent(RoomSessionWordQuizEvent.QUESTION, session, parser.pollId);
|
||||||
|
|
||||||
|
quizEvent.question = parser.question;
|
||||||
|
quizEvent.duration = parser.duration;
|
||||||
|
quizEvent.pollType = parser.pollType;
|
||||||
|
quizEvent.questionId = parser.questionId;
|
||||||
|
quizEvent.pollId = parser.pollId;
|
||||||
|
|
||||||
|
this.listener.events.dispatchEvent(quizEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onQuestionAnsweredEvent(event: QuestionAnsweredEvent): void
|
||||||
|
{
|
||||||
|
if(!this.listener) return;
|
||||||
|
|
||||||
|
const session = this.listener.getSession(this.roomId);
|
||||||
|
|
||||||
|
if(!session) return;
|
||||||
|
|
||||||
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
if(!parser) return;
|
||||||
|
|
||||||
|
const quizEvent = new RoomSessionWordQuizEvent(RoomSessionWordQuizEvent.ANSWERED, session, parser.userId);
|
||||||
|
|
||||||
|
quizEvent.value = parser.value;
|
||||||
|
quizEvent.userId = parser.userId;
|
||||||
|
quizEvent.answerCounts = parser.answerCounts;
|
||||||
|
|
||||||
|
this.listener.events.dispatchEvent(quizEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onQuestionFinishedEvent(event: QuestionFinishedEvent): void
|
||||||
|
{
|
||||||
|
if(!this.listener) return;
|
||||||
|
|
||||||
|
const session = this.listener.getSession(this.roomId);
|
||||||
|
|
||||||
|
if(!session) return;
|
||||||
|
|
||||||
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
if(!parser) return;
|
||||||
|
|
||||||
|
const quizEvent = new RoomSessionWordQuizEvent(RoomSessionWordQuizEvent.FINISHED, session);
|
||||||
|
quizEvent.questionId = parser.questionId;
|
||||||
|
quizEvent.answerCounts = parser.answerCounts;
|
||||||
|
|
||||||
|
this.listener.events.dispatchEvent(quizEvent);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user