Skip to content

Commit 1848295

Browse files
committed
billsonnn#28 - RoomPollResultEvent added
1 parent 26741b7 commit 1848295

File tree

7 files changed

+100
-3
lines changed

7 files changed

+100
-3
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
@@ -374,6 +374,7 @@ export class IncomingHeader
374374
public static POLL_CONTENTS = 2997;
375375
public static POLL_ERROR = 662;
376376
public static POLL_OFFER = 3785;
377+
public static POLL_ROOM_RESULT = 5201;
377378
public static QUESTION_ANSWERED = 2589;
378379
public static QUESTION_FINISHED = 1066;
379380
public static CFH_PENDING_CALLS = 1121;
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,3 +4,4 @@ export * from './PollOfferEvent';
44
export * from './QuestionAnsweredEvent';
55
export * from './QuestionEvent';
66
export * from './QuestionFinishedEvent';
7+
export * from './RoomPollResultEvent';
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,3 +6,4 @@ export * from './PollQuestion';
66
export * from './QuestionAnsweredParser';
77
export * from './QuestionFinishedParser';
88
export * from './QuestionParser';
9+
export * from './RoomPollResultParser';

src/nitro/session/handler/PollHandler.ts

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

66
export class PollHandler extends BaseHandler
@@ -12,6 +12,7 @@ export class PollHandler extends BaseHandler
1212
connection.addMessageEvent(new PollContentsEvent(this.onPollContentsEvent.bind(this)));
1313
connection.addMessageEvent(new PollOfferEvent(this.onPollOfferEvent.bind(this)));
1414
connection.addMessageEvent(new PollErrorEvent(this.onPollErrorEvent.bind(this)));
15+
connection.addMessageEvent(new RoomPollResultEvent(this.onRoomPollResultEvent.bind(this)));
1516
}
1617

1718
private onPollContentsEvent(event: PollContentsEvent): void
@@ -75,4 +76,21 @@ export class PollHandler extends BaseHandler
7576

7677
this.listener.events.dispatchEvent(pollEvent);
7778
}
79+
80+
private onRoomPollResultEvent(event: RoomPollResultEvent): void
81+
{
82+
if(!this.listener) return;
83+
84+
const session = this.listener.getSession(this.roomId);
85+
86+
if(!session) return;
87+
88+
const parser = event.getParser();
89+
90+
if(!parser) return;
91+
92+
const pollEvent = new RoomSessionVoteEvent(RoomSessionVoteEvent.VOTE_RESULT, session, parser.question, parser.choices, parser.SafeStr_7651, parser.SafeStr_7654);
93+
94+
this.listener.events.dispatchEvent(pollEvent);
95+
}
7896
}

0 commit comments

Comments
 (0)