mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2024-11-22 15:40:52 +01:00
* #28 - StartRoomPollEvent added * Added handler --------- Co-authored-by: Bill <billsonnn@users.noreply.github.com>
This commit is contained in:
parent
becf87b668
commit
53ab155f9c
File diff suppressed because one or more lines are too long
@ -399,6 +399,7 @@ export class IncomingHeader
|
||||
public static POLL_CONTENTS = 2997;
|
||||
public static POLL_ERROR = 662;
|
||||
public static POLL_OFFER = 3785;
|
||||
public static POLL_START_ROOM = 5200;
|
||||
public static QUESTION_ANSWERED = 2589;
|
||||
public static QUESTION_FINISHED = 1066;
|
||||
public static CFH_PENDING_CALLS = 1121;
|
||||
|
@ -0,0 +1,16 @@
|
||||
import { IMessageEvent } from '../../../../../api';
|
||||
import { MessageEvent } from '../../../../../events';
|
||||
import { RoomPollDataParser } from '../../parser';
|
||||
|
||||
export class StartRoomPollEvent extends MessageEvent implements IMessageEvent
|
||||
{
|
||||
constructor(callBack: Function)
|
||||
{
|
||||
super(callBack, RoomPollDataParser);
|
||||
}
|
||||
|
||||
public getParser(): RoomPollDataParser
|
||||
{
|
||||
return this.parser as RoomPollDataParser;
|
||||
}
|
||||
}
|
@ -4,3 +4,4 @@ export * from './PollOfferEvent';
|
||||
export * from './QuestionAnsweredEvent';
|
||||
export * from './QuestionEvent';
|
||||
export * from './QuestionFinishedEvent';
|
||||
export * from './StartRoomPollEvent';
|
||||
|
@ -0,0 +1,41 @@
|
||||
import { IMessageDataWrapper, IMessageParser } from '../../../../../api';
|
||||
|
||||
export class RoomPollDataParser implements IMessageParser
|
||||
{
|
||||
private _question: string;
|
||||
private _choices: string[];
|
||||
|
||||
flush(): boolean
|
||||
{
|
||||
this._question = null;
|
||||
this._choices = [];
|
||||
return true;
|
||||
}
|
||||
|
||||
parse(wrapper: IMessageDataWrapper): boolean
|
||||
{
|
||||
this._question = wrapper.readString();
|
||||
this._choices = [];
|
||||
|
||||
const totalChoices = wrapper.readInt();
|
||||
let total = 0;
|
||||
|
||||
while(total < totalChoices)
|
||||
{
|
||||
this._choices.push(wrapper.readString());
|
||||
total++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public get question(): string
|
||||
{
|
||||
return this._question;
|
||||
}
|
||||
|
||||
public get choices(): string[]
|
||||
{
|
||||
return this._choices.slice();
|
||||
}
|
||||
}
|
@ -6,3 +6,4 @@ export * from './PollQuestion';
|
||||
export * from './QuestionAnsweredParser';
|
||||
export * from './QuestionFinishedParser';
|
||||
export * from './QuestionParser';
|
||||
export * from './RoomPollDataParser';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { IConnection, IRoomHandlerListener } from '../../../api';
|
||||
import { RoomSessionPollEvent } from '../../../events';
|
||||
import { PollContentsEvent, PollErrorEvent, PollOfferEvent } from '../../communication';
|
||||
import { RoomSessionPollEvent, RoomSessionVoteEvent } from '../../../events';
|
||||
import { PollContentsEvent, PollErrorEvent, PollOfferEvent, StartRoomPollEvent } from '../../communication';
|
||||
import { BaseHandler } from './BaseHandler';
|
||||
|
||||
export class PollHandler extends BaseHandler
|
||||
@ -12,6 +12,7 @@ export class PollHandler extends BaseHandler
|
||||
connection.addMessageEvent(new PollContentsEvent(this.onPollContentsEvent.bind(this)));
|
||||
connection.addMessageEvent(new PollOfferEvent(this.onPollOfferEvent.bind(this)));
|
||||
connection.addMessageEvent(new PollErrorEvent(this.onPollErrorEvent.bind(this)));
|
||||
connection.addMessageEvent(new StartRoomPollEvent(this.onStartRoomPollEvent.bind(this)));
|
||||
}
|
||||
|
||||
private onPollContentsEvent(event: PollContentsEvent): void
|
||||
@ -75,4 +76,21 @@ export class PollHandler extends BaseHandler
|
||||
|
||||
this.listener.events.dispatchEvent(pollEvent);
|
||||
}
|
||||
|
||||
private onStartRoomPollEvent(event: StartRoomPollEvent): 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 RoomSessionVoteEvent(RoomSessionVoteEvent.VOTE_QUESTION, session, parser.question, parser.choices);
|
||||
|
||||
this.listener.events.dispatchEvent(pollEvent);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user