#28 - RoomPollResultEvent added (#35)

Co-authored-by: Bill <billsonnn@users.noreply.github.com>
This commit is contained in:
object 2023-05-09 17:32:17 +02:00 committed by GitHub
parent f9cacc4d2b
commit 5c2580881d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 99 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -401,6 +401,7 @@ export class IncomingHeader
public static POLL_CONTENTS = 2997;
public static POLL_ERROR = 662;
public static POLL_OFFER = 3785;
public static POLL_ROOM_RESULT = 5201;
public static POLL_START_ROOM = 5200;
public static QUESTION_ANSWERED = 2589;
public static QUESTION_FINISHED = 1066;

View File

@ -0,0 +1,16 @@
import { IMessageEvent } from '../../../../../api';
import { MessageEvent } from '../../../../../events';
import { RoomPollResultParser } from '../../parser';
export class RoomPollResultEvent extends MessageEvent implements IMessageEvent
{
constructor(callBack: Function)
{
super(callBack, RoomPollResultParser);
}
public getParser(): RoomPollResultParser
{
return this.parser as RoomPollResultParser;
}
}

View File

@ -4,4 +4,5 @@ export * from './PollOfferEvent';
export * from './QuestionAnsweredEvent';
export * from './QuestionEvent';
export * from './QuestionFinishedEvent';
export * from './RoomPollResultEvent';
export * from './StartRoomPollEvent';

View File

@ -0,0 +1,59 @@
import { IMessageDataWrapper, IMessageParser } from '../../../../../api';
export class RoomPollResultParser implements IMessageParser
{
private _question: string;
private _choices: string[];
private _SafeStr_7651: any[];
private _SafeStr_7654: number;
flush(): boolean
{
this._question = null;
this._choices = [];
this._SafeStr_7651 = [];
this._SafeStr_7654 = -1;
return true;
}
parse(wrapper: IMessageDataWrapper): boolean
{
this._question = wrapper.readString();
this._choices = [];
this._SafeStr_7651 = [];
let totalChoices = wrapper.readInt();
while(totalChoices > 0)
{
this._choices.push(wrapper.readString());
this._SafeStr_7651.push(wrapper.readInt());
totalChoices--;
}
this._SafeStr_7654 = wrapper.readInt();
return true;
}
public get question(): string
{
return this._question;
}
public get choices(): string[]
{
return this._choices;
}
public get SafeStr_7651(): any[]
{
return this._SafeStr_7651;
}
public get SafeStr_7654(): number
{
return this._SafeStr_7654;
}
}

View File

@ -6,4 +6,5 @@ export * from './PollQuestion';
export * from './QuestionAnsweredParser';
export * from './QuestionFinishedParser';
export * from './QuestionParser';
export * from './RoomPollResultParser';
export * from './RoomPollDataParser';

View File

@ -1,6 +1,6 @@
import { IConnection, IRoomHandlerListener } from '../../../api';
import { RoomSessionPollEvent, RoomSessionVoteEvent } from '../../../events';
import { PollContentsEvent, PollErrorEvent, PollOfferEvent, StartRoomPollEvent } from '../../communication';
import { PollContentsEvent, PollErrorEvent, PollOfferEvent, StartRoomPollEvent, RoomPollResultEvent } from '../../communication';
import { BaseHandler } from './BaseHandler';
export class PollHandler extends BaseHandler
@ -13,6 +13,7 @@ export class PollHandler extends BaseHandler
connection.addMessageEvent(new PollOfferEvent(this.onPollOfferEvent.bind(this)));
connection.addMessageEvent(new PollErrorEvent(this.onPollErrorEvent.bind(this)));
connection.addMessageEvent(new StartRoomPollEvent(this.onStartRoomPollEvent.bind(this)));
connection.addMessageEvent(new RoomPollResultEvent(this.onRoomPollResultEvent.bind(this)));
}
private onPollContentsEvent(event: PollContentsEvent): void
@ -93,4 +94,21 @@ export class PollHandler extends BaseHandler
this.listener.events.dispatchEvent(pollEvent);
}
private onRoomPollResultEvent(event: RoomPollResultEvent): 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_RESULT, session, parser.question, parser.choices, parser.SafeStr_7651, parser.SafeStr_7654);
this.listener.events.dispatchEvent(pollEvent);
}
}