-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #28 - StartRoomPollEvent added * Added handler --------- Co-authored-by: Bill <[email protected]>
- Loading branch information
Showing
7 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/nitro/communication/messages/incoming/poll/StartRoomPollEvent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/nitro/communication/messages/parser/poll/RoomPollDataParser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters