mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-01-18 14:36:26 +01:00
add session poll handler
This commit is contained in:
parent
e6d4d2a8f2
commit
1cedce0a76
@ -5,6 +5,7 @@ import { IRoomEngine } from '../room/IRoomEngine';
|
||||
import { RoomSessionEvent } from './events/RoomSessionEvent';
|
||||
import { BaseHandler } from './handler/BaseHandler';
|
||||
import { GenericErrorHandler } from './handler/GenericErrorHandler';
|
||||
import { PollHandler } from './handler/PollHandler';
|
||||
import { RoomChatHandler } from './handler/RoomChatHandler';
|
||||
import { RoomDataHandler } from './handler/RoomDataHandler';
|
||||
import { RoomDimmerPresetsHandler } from './handler/RoomDimmerPresetsHandler';
|
||||
@ -79,6 +80,7 @@ export class RoomSessionManager extends NitroManager implements IRoomSessionMana
|
||||
new RoomPresentHandler(connection, this),
|
||||
new GenericErrorHandler(connection, this),
|
||||
new WordQuizHandler(connection, this),
|
||||
new PollHandler(connection, this),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { IRoomSession } from '../IRoomSession';
|
||||
import { PollQuestion } from '../../communication/messages/parser/poll/PollQuestion';
|
||||
import { IRoomSession } from '../IRoomSession';
|
||||
import { RoomSessionEvent } from './RoomSessionEvent';
|
||||
|
||||
|
||||
@ -14,7 +15,7 @@ export class RoomSessionPollEvent extends RoomSessionEvent
|
||||
private _numQuestions: number = 0;
|
||||
private _startMessage: string = '';
|
||||
private _endMessage: string = '';
|
||||
private _questionArray: string[] = null;
|
||||
private _questionArray: PollQuestion[] = null;
|
||||
private _npsPoll: boolean = false;
|
||||
|
||||
constructor(k: string, _arg_2: IRoomSession, _arg_3: number)
|
||||
@ -79,12 +80,12 @@ export class RoomSessionPollEvent extends RoomSessionEvent
|
||||
this._endMessage = k;
|
||||
}
|
||||
|
||||
public get questionArray(): string[]
|
||||
public get questionArray(): PollQuestion[]
|
||||
{
|
||||
return this._questionArray;
|
||||
}
|
||||
|
||||
public set questionArray(k: string[])
|
||||
public set questionArray(k: PollQuestion[])
|
||||
{
|
||||
this._questionArray = k;
|
||||
}
|
||||
|
81
src/nitro/session/handler/PollHandler.ts
Normal file
81
src/nitro/session/handler/PollHandler.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import { IConnection } from '../../../core/communication/connections/IConnection';
|
||||
import { PollContentsEvent } from '../../communication/messages/incoming/poll/PollContentsEvent';
|
||||
import { PollErrorEvent } from '../../communication/messages/incoming/poll/PollErrorEvent';
|
||||
import { PollOfferEvent } from '../../communication/messages/incoming/poll/PollOfferEvent';
|
||||
import { RoomSessionPollEvent } from '../events/RoomSessionPollEvent';
|
||||
import { IRoomHandlerListener } from '../IRoomHandlerListener';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class PollHandler extends BaseHandler
|
||||
{
|
||||
constructor(connection: IConnection, listener: IRoomHandlerListener)
|
||||
{
|
||||
super(connection, listener);
|
||||
|
||||
connection.addMessageEvent(new PollContentsEvent(this.onPollContentsEvent.bind(this)));
|
||||
connection.addMessageEvent(new PollOfferEvent(this.onPollOfferEvent.bind(this)));
|
||||
connection.addMessageEvent(new PollErrorEvent(this.onPollErrorEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onPollContentsEvent(event: PollContentsEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const pollEvent = new RoomSessionPollEvent(RoomSessionPollEvent.CONTENT, session, parser.id);
|
||||
|
||||
pollEvent.startMessage = parser.startMessage;
|
||||
pollEvent.endMessage = parser.endMessage;
|
||||
pollEvent.numQuestions = parser.numQuestions;
|
||||
pollEvent.questionArray = parser.questionArray;
|
||||
pollEvent.npsPoll = parser.npsPoll;
|
||||
|
||||
this.listener.events.dispatchEvent(pollEvent);
|
||||
}
|
||||
|
||||
private onPollOfferEvent(event: PollOfferEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const pollEvent = new RoomSessionPollEvent(RoomSessionPollEvent.OFFER, session, parser.id);
|
||||
|
||||
pollEvent.summary = parser.headline;
|
||||
pollEvent.summary = parser.summary;
|
||||
|
||||
this.listener.events.dispatchEvent(pollEvent);
|
||||
}
|
||||
|
||||
private onPollErrorEvent(event: PollErrorEvent): void
|
||||
{
|
||||
if(!this.listener) return;
|
||||
|
||||
const session = this.listener.getSession(this.roomId);
|
||||
|
||||
if(!session) return;
|
||||
|
||||
const parser = event.getParser();
|
||||
|
||||
if(!parser) return;
|
||||
|
||||
const pollEvent = new RoomSessionPollEvent(RoomSessionPollEvent.ERROR, session, -1);
|
||||
pollEvent.headline = '???';
|
||||
pollEvent.summary = '???';
|
||||
|
||||
this.listener.events.dispatchEvent(pollEvent);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user