Skip to content

Commit 5c25808

Browse files
oobjecttbillsonnn
andauthored
#28 - RoomPollResultEvent added (#35)
Co-authored-by: Bill <[email protected]>
1 parent f9cacc4 commit 5c25808

File tree

7 files changed

+99
-2
lines changed

7 files changed

+99
-2
lines changed

src/nitro/communication/NitroMessages.ts

+2-1
Large diffs are not rendered by default.

src/nitro/communication/messages/incoming/IncomingHeader.ts

+1
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ export class IncomingHeader
401401
public static POLL_CONTENTS = 2997;
402402
public static POLL_ERROR = 662;
403403
public static POLL_OFFER = 3785;
404+
public static POLL_ROOM_RESULT = 5201;
404405
public static POLL_START_ROOM = 5200;
405406
public static QUESTION_ANSWERED = 2589;
406407
public static QUESTION_FINISHED = 1066;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { IMessageEvent } from '../../../../../api';
2+
import { MessageEvent } from '../../../../../events';
3+
import { RoomPollResultParser } from '../../parser';
4+
5+
export class RoomPollResultEvent extends MessageEvent implements IMessageEvent
6+
{
7+
constructor(callBack: Function)
8+
{
9+
super(callBack, RoomPollResultParser);
10+
}
11+
12+
public getParser(): RoomPollResultParser
13+
{
14+
return this.parser as RoomPollResultParser;
15+
}
16+
}

src/nitro/communication/messages/incoming/poll/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export * from './PollOfferEvent';
44
export * from './QuestionAnsweredEvent';
55
export * from './QuestionEvent';
66
export * from './QuestionFinishedEvent';
7+
export * from './RoomPollResultEvent';
78
export * from './StartRoomPollEvent';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { IMessageDataWrapper, IMessageParser } from '../../../../../api';
2+
3+
export class RoomPollResultParser implements IMessageParser
4+
{
5+
private _question: string;
6+
private _choices: string[];
7+
private _SafeStr_7651: any[];
8+
private _SafeStr_7654: number;
9+
10+
flush(): boolean
11+
{
12+
this._question = null;
13+
this._choices = [];
14+
this._SafeStr_7651 = [];
15+
this._SafeStr_7654 = -1;
16+
return true;
17+
}
18+
19+
parse(wrapper: IMessageDataWrapper): boolean
20+
{
21+
this._question = wrapper.readString();
22+
23+
this._choices = [];
24+
this._SafeStr_7651 = [];
25+
26+
let totalChoices = wrapper.readInt();
27+
28+
while(totalChoices > 0)
29+
{
30+
this._choices.push(wrapper.readString());
31+
this._SafeStr_7651.push(wrapper.readInt());
32+
33+
totalChoices--;
34+
}
35+
this._SafeStr_7654 = wrapper.readInt();
36+
37+
return true;
38+
}
39+
40+
public get question(): string
41+
{
42+
return this._question;
43+
}
44+
45+
public get choices(): string[]
46+
{
47+
return this._choices;
48+
}
49+
50+
public get SafeStr_7651(): any[]
51+
{
52+
return this._SafeStr_7651;
53+
}
54+
55+
public get SafeStr_7654(): number
56+
{
57+
return this._SafeStr_7654;
58+
}
59+
}

src/nitro/communication/messages/parser/poll/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export * from './PollQuestion';
66
export * from './QuestionAnsweredParser';
77
export * from './QuestionFinishedParser';
88
export * from './QuestionParser';
9+
export * from './RoomPollResultParser';
910
export * from './RoomPollDataParser';

src/nitro/session/handler/PollHandler.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IConnection, IRoomHandlerListener } from '../../../api';
22
import { RoomSessionPollEvent, RoomSessionVoteEvent } from '../../../events';
3-
import { PollContentsEvent, PollErrorEvent, PollOfferEvent, StartRoomPollEvent } from '../../communication';
3+
import { PollContentsEvent, PollErrorEvent, PollOfferEvent, StartRoomPollEvent, RoomPollResultEvent } from '../../communication';
44
import { BaseHandler } from './BaseHandler';
55

66
export class PollHandler extends BaseHandler
@@ -13,6 +13,7 @@ export class PollHandler extends BaseHandler
1313
connection.addMessageEvent(new PollOfferEvent(this.onPollOfferEvent.bind(this)));
1414
connection.addMessageEvent(new PollErrorEvent(this.onPollErrorEvent.bind(this)));
1515
connection.addMessageEvent(new StartRoomPollEvent(this.onStartRoomPollEvent.bind(this)));
16+
connection.addMessageEvent(new RoomPollResultEvent(this.onRoomPollResultEvent.bind(this)));
1617
}
1718

1819
private onPollContentsEvent(event: PollContentsEvent): void
@@ -93,4 +94,21 @@ export class PollHandler extends BaseHandler
9394

9495
this.listener.events.dispatchEvent(pollEvent);
9596
}
97+
98+
private onRoomPollResultEvent(event: RoomPollResultEvent): void
99+
{
100+
if(!this.listener) return;
101+
102+
const session = this.listener.getSession(this.roomId);
103+
104+
if(!session) return;
105+
106+
const parser = event.getParser();
107+
108+
if(!parser) return;
109+
110+
const pollEvent = new RoomSessionVoteEvent(RoomSessionVoteEvent.VOTE_RESULT, session, parser.question, parser.choices, parser.SafeStr_7651, parser.SafeStr_7654);
111+
112+
this.listener.events.dispatchEvent(pollEvent);
113+
}
96114
}

0 commit comments

Comments
 (0)