mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-27 08:00:51 +01:00
add another handler
This commit is contained in:
parent
bc0c1b0562
commit
b7c978c786
110
src/api/nitro/room/widgets/events/RoomWidgetPollUpdateEvent.ts
Normal file
110
src/api/nitro/room/widgets/events/RoomWidgetPollUpdateEvent.ts
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
import { PollQuestion } from '@nitrots/nitro-renderer';
|
||||||
|
import { RoomWidgetUpdateEvent } from './RoomWidgetUpdateEvent';
|
||||||
|
|
||||||
|
export class RoomWidgetPollUpdateEvent extends RoomWidgetUpdateEvent
|
||||||
|
{
|
||||||
|
public static readonly OFFER = 'RWPUW_OFFER';
|
||||||
|
public static readonly ERROR = 'RWPUW_ERROR';
|
||||||
|
public static readonly CONTENT = 'RWPUW_CONTENT';
|
||||||
|
|
||||||
|
private _id = -1;
|
||||||
|
private _summary: string;
|
||||||
|
private _headline: string;
|
||||||
|
private _numQuestions = 0;
|
||||||
|
private _startMessage = '';
|
||||||
|
private _endMessage = '';
|
||||||
|
private _questionArray: PollQuestion[] = null;
|
||||||
|
private _pollType = '';
|
||||||
|
private _npsPoll = false;
|
||||||
|
|
||||||
|
constructor(type: string, id: number)
|
||||||
|
{
|
||||||
|
super(type);
|
||||||
|
this._id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get id(): number
|
||||||
|
{
|
||||||
|
return this._id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get summary(): string
|
||||||
|
{
|
||||||
|
return this._summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set summary(k: string)
|
||||||
|
{
|
||||||
|
this._summary = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get headline(): string
|
||||||
|
{
|
||||||
|
return this._headline;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set headline(k: string)
|
||||||
|
{
|
||||||
|
this._headline = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get numQuestions(): number
|
||||||
|
{
|
||||||
|
return this._numQuestions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set numQuestions(k: number)
|
||||||
|
{
|
||||||
|
this._numQuestions = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get startMessage(): string
|
||||||
|
{
|
||||||
|
return this._startMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set startMessage(k: string)
|
||||||
|
{
|
||||||
|
this._startMessage = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get endMessage(): string
|
||||||
|
{
|
||||||
|
return this._endMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set endMessage(k: string)
|
||||||
|
{
|
||||||
|
this._endMessage = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get questionArray(): PollQuestion[]
|
||||||
|
{
|
||||||
|
return this._questionArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set questionArray(k: PollQuestion[])
|
||||||
|
{
|
||||||
|
this._questionArray = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get pollType(): string
|
||||||
|
{
|
||||||
|
return this._pollType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set pollType(k: string)
|
||||||
|
{
|
||||||
|
this._pollType = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get npsPoll(): boolean
|
||||||
|
{
|
||||||
|
return this._npsPoll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set npsPoll(k: boolean)
|
||||||
|
{
|
||||||
|
this._npsPoll = k;
|
||||||
|
}
|
||||||
|
}
|
76
src/api/nitro/room/widgets/handlers/PollWidgetHandler.ts
Normal file
76
src/api/nitro/room/widgets/handlers/PollWidgetHandler.ts
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import { NitroEvent, RoomSessionPollEvent, RoomWidgetEnum } from '@nitrots/nitro-renderer';
|
||||||
|
import { RoomWidgetPollUpdateEvent } from '../events/RoomWidgetPollUpdateEvent';
|
||||||
|
import { RoomWidgetUpdateEvent } from '../events/RoomWidgetUpdateEvent';
|
||||||
|
import { RoomWidgetMessage } from '../messages/RoomWidgetMessage';
|
||||||
|
import { RoomWidgetPollMessage } from '../messages/RoomWidgetPollMessage';
|
||||||
|
import { RoomWidgetHandler } from './RoomWidgetHandler';
|
||||||
|
|
||||||
|
export class PollWidgetHandler extends RoomWidgetHandler
|
||||||
|
{
|
||||||
|
public processEvent(event: NitroEvent): void
|
||||||
|
{
|
||||||
|
const pollEvent = (event as RoomSessionPollEvent);
|
||||||
|
|
||||||
|
let widgetEvent: RoomWidgetPollUpdateEvent;
|
||||||
|
|
||||||
|
switch(event.type)
|
||||||
|
{
|
||||||
|
case RoomSessionPollEvent.OFFER:
|
||||||
|
widgetEvent = new RoomWidgetPollUpdateEvent(RoomWidgetPollUpdateEvent.OFFER, pollEvent.id);
|
||||||
|
widgetEvent.summary = pollEvent.summary;
|
||||||
|
widgetEvent.headline = pollEvent.headline;
|
||||||
|
break;
|
||||||
|
case RoomSessionPollEvent.ERROR:
|
||||||
|
widgetEvent = new RoomWidgetPollUpdateEvent(RoomWidgetPollUpdateEvent.ERROR, pollEvent.id);
|
||||||
|
widgetEvent.summary = pollEvent.summary;
|
||||||
|
widgetEvent.headline = pollEvent.headline;
|
||||||
|
break;
|
||||||
|
case RoomSessionPollEvent.CONTENT:
|
||||||
|
widgetEvent = new RoomWidgetPollUpdateEvent(RoomWidgetPollUpdateEvent.CONTENT, pollEvent.id);
|
||||||
|
widgetEvent.startMessage = pollEvent.startMessage;
|
||||||
|
widgetEvent.endMessage = pollEvent.endMessage;
|
||||||
|
widgetEvent.numQuestions = pollEvent.numQuestions;
|
||||||
|
widgetEvent.questionArray = pollEvent.questionArray;
|
||||||
|
widgetEvent.npsPoll = pollEvent.npsPoll;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!widgetEvent) return;
|
||||||
|
|
||||||
|
this.container.eventDispatcher.dispatchEvent(widgetEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public processWidgetMessage(message: RoomWidgetMessage): RoomWidgetUpdateEvent
|
||||||
|
{
|
||||||
|
const pollMessage = (message as RoomWidgetPollMessage);
|
||||||
|
|
||||||
|
switch(message.type)
|
||||||
|
{
|
||||||
|
case RoomWidgetPollMessage.START:
|
||||||
|
this.container.roomSession.sendPollStartMessage(pollMessage.id);
|
||||||
|
break;
|
||||||
|
case RoomWidgetPollMessage.REJECT:
|
||||||
|
this.container.roomSession.sendPollRejectMessage(pollMessage.id);
|
||||||
|
break;
|
||||||
|
case RoomWidgetPollMessage.ANSWER:
|
||||||
|
this.container.roomSession.sendPollAnswerMessage(pollMessage.id, pollMessage.questionId, pollMessage.answers);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get type(): string
|
||||||
|
{
|
||||||
|
return RoomWidgetEnum.ROOM_POLL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get eventTypes(): string[]
|
||||||
|
{
|
||||||
|
return [RoomSessionPollEvent.OFFER, RoomSessionPollEvent.ERROR, RoomSessionPollEvent.CONTENT];
|
||||||
|
}
|
||||||
|
|
||||||
|
public get messageTypes(): string[]
|
||||||
|
{
|
||||||
|
return [RoomWidgetPollMessage.ANSWER, RoomWidgetPollMessage.REJECT, RoomWidgetPollMessage.START];
|
||||||
|
}
|
||||||
|
}
|
44
src/api/nitro/room/widgets/messages/RoomWidgetPollMessage.ts
Normal file
44
src/api/nitro/room/widgets/messages/RoomWidgetPollMessage.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { RoomWidgetMessage } from './RoomWidgetMessage';
|
||||||
|
|
||||||
|
export class RoomWidgetPollMessage extends RoomWidgetMessage
|
||||||
|
{
|
||||||
|
public static readonly START = 'RWPM_START';
|
||||||
|
public static readonly REJECT = 'RWPM_REJECT';
|
||||||
|
public static readonly ANSWER = 'RWPM_ANSWER';
|
||||||
|
|
||||||
|
private _id = -1;
|
||||||
|
private _questionId = 0;
|
||||||
|
private _answers: string[] = null;
|
||||||
|
|
||||||
|
constructor(type: string, id: number)
|
||||||
|
{
|
||||||
|
super(type);
|
||||||
|
|
||||||
|
this._id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get id(): number
|
||||||
|
{
|
||||||
|
return this._id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get questionId(): number
|
||||||
|
{
|
||||||
|
return this._questionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set questionId(k: number)
|
||||||
|
{
|
||||||
|
this._questionId = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get answers(): string[]
|
||||||
|
{
|
||||||
|
return this._answers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set answers(k: string[])
|
||||||
|
{
|
||||||
|
this._answers = k;
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ import { EventDispatcher, NitroRectangle, RoomGeometry, RoomVariableEnum, Vector
|
|||||||
import { FC, useEffect, useRef, useState } from 'react';
|
import { FC, useEffect, useRef, useState } from 'react';
|
||||||
import { DispatchMouseEvent, DispatchTouchEvent, DoorbellWidgetHandler, FurniChooserWidgetHandler, FurnitureContextMenuWidgetHandler, FurnitureCreditWidgetHandler, FurnitureCustomStackHeightWidgetHandler, FurnitureDimmerWidgetHandler, FurnitureExternalImageWidgetHandler, FurnitureMannequinWidgetHandler, FurniturePresentWidgetHandler, GetNitroInstance, GetRoomEngine, InitializeRoomInstanceRenderingCanvas, IRoomWidgetHandlerManager, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler, RoomWidgetRoomToolsHandler, RoomWidgetUpdateRoomViewEvent, UserChooserWidgetHandler } from '../../api';
|
import { DispatchMouseEvent, DispatchTouchEvent, DoorbellWidgetHandler, FurniChooserWidgetHandler, FurnitureContextMenuWidgetHandler, FurnitureCreditWidgetHandler, FurnitureCustomStackHeightWidgetHandler, FurnitureDimmerWidgetHandler, FurnitureExternalImageWidgetHandler, FurnitureMannequinWidgetHandler, FurniturePresentWidgetHandler, GetNitroInstance, GetRoomEngine, InitializeRoomInstanceRenderingCanvas, IRoomWidgetHandlerManager, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler, RoomWidgetRoomToolsHandler, RoomWidgetUpdateRoomViewEvent, UserChooserWidgetHandler } from '../../api';
|
||||||
import { FurnitureYoutubeDisplayWidgetHandler } from '../../api/nitro/room/widgets/handlers/FurnitureYoutubeDisplayWidgetHandler';
|
import { FurnitureYoutubeDisplayWidgetHandler } from '../../api/nitro/room/widgets/handlers/FurnitureYoutubeDisplayWidgetHandler';
|
||||||
|
import { PollWidgetHandler } from '../../api/nitro/room/widgets/handlers/PollWidgetHandler';
|
||||||
import { WordQuizWidgetHandler } from '../../api/nitro/room/widgets/handlers/WordQuizWidgetHandler';
|
import { WordQuizWidgetHandler } from '../../api/nitro/room/widgets/handlers/WordQuizWidgetHandler';
|
||||||
import { RoomContextProvider } from './context/RoomContext';
|
import { RoomContextProvider } from './context/RoomContext';
|
||||||
import { RoomColorView } from './RoomColorView';
|
import { RoomColorView } from './RoomColorView';
|
||||||
@ -39,6 +40,7 @@ export const RoomView: FC<RoomViewProps> = props =>
|
|||||||
widgetHandlerManager.registerHandler(new UserChooserWidgetHandler());
|
widgetHandlerManager.registerHandler(new UserChooserWidgetHandler());
|
||||||
widgetHandlerManager.registerHandler(new DoorbellWidgetHandler());
|
widgetHandlerManager.registerHandler(new DoorbellWidgetHandler());
|
||||||
widgetHandlerManager.registerHandler(new WordQuizWidgetHandler());
|
widgetHandlerManager.registerHandler(new WordQuizWidgetHandler());
|
||||||
|
widgetHandlerManager.registerHandler(new PollWidgetHandler());
|
||||||
|
|
||||||
widgetHandlerManager.registerHandler(new FurniChooserWidgetHandler());
|
widgetHandlerManager.registerHandler(new FurniChooserWidgetHandler());
|
||||||
widgetHandlerManager.registerHandler(new FurnitureContextMenuWidgetHandler());
|
widgetHandlerManager.registerHandler(new FurnitureContextMenuWidgetHandler());
|
||||||
|
@ -8,3 +8,4 @@
|
|||||||
@import './object-location/ObjectLocationView';
|
@import './object-location/ObjectLocationView';
|
||||||
@import './room-tools/RoomToolsWidgetView';
|
@import './room-tools/RoomToolsWidgetView';
|
||||||
@import './choosers/ChooserWidgetView';
|
@import './choosers/ChooserWidgetView';
|
||||||
|
@import './word-quiz/WordQuizWidgetView';
|
||||||
|
12
src/views/room/widgets/word-quiz/WordQuizWidgetView.scss
Normal file
12
src/views/room/widgets/word-quiz/WordQuizWidgetView.scss
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
.word-quiz-question-container {
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
left: 0px;
|
||||||
|
.wordquiz-question {
|
||||||
|
font-size: large;
|
||||||
|
background: rgba($dark, 0.90);
|
||||||
|
//box-shadow: inset 0px 5px lighten(rgba($dark,.6),2.5), inset 0 -4px darken(rgba($dark,.6),4);
|
||||||
|
border-radius: $border-radius;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,46 @@
|
|||||||
import { FC } from 'react';
|
import { IQuestion } from '@nitrots/nitro-renderer';
|
||||||
|
import { FC, useCallback, useState } from 'react';
|
||||||
|
import { RoomWidgetWordQuizUpdateEvent } from '../../../../api/nitro/room/widgets/events/RoomWidgetWordQuizUpdateEvent';
|
||||||
|
import { BatchUpdates, CreateEventDispatcherHook } from '../../../../hooks';
|
||||||
|
import { useRoomContext } from '../../context/RoomContext';
|
||||||
|
import { QuestionView } from './views/question/QuestionView';
|
||||||
|
|
||||||
export const WordQuizWidgetView: FC<{}> = props =>
|
export const WordQuizWidgetView: FC<{}> = props =>
|
||||||
{
|
{
|
||||||
return null;
|
const { eventDispatcher = null, widgetHandler = null } = useRoomContext();
|
||||||
|
const [pollId, setPollId ] = useState(-1);
|
||||||
|
const [question, setQuestion] = useState<IQuestion>(null);
|
||||||
|
const [ answerSent, setAnswerSent ] = useState(false);
|
||||||
|
|
||||||
|
const onRoomWidgetWordQuizUpdateEvent = useCallback((event: RoomWidgetWordQuizUpdateEvent) =>
|
||||||
|
{
|
||||||
|
switch(event.type)
|
||||||
|
{
|
||||||
|
case RoomWidgetWordQuizUpdateEvent.NEW_QUESTION:
|
||||||
|
BatchUpdates(() =>
|
||||||
|
{
|
||||||
|
setPollId(event.id);
|
||||||
|
setQuestion(event.question);
|
||||||
|
setAnswerSent(false);
|
||||||
|
});
|
||||||
|
//this._showSignCounters = new Dictionary();
|
||||||
|
//this.showNewQuestion(this._question, k.duration);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const vote = useCallback((vote: string) =>
|
||||||
|
{
|
||||||
|
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
CreateEventDispatcherHook(RoomWidgetWordQuizUpdateEvent.NEW_QUESTION, eventDispatcher, onRoomWidgetWordQuizUpdateEvent);
|
||||||
|
CreateEventDispatcherHook(RoomWidgetWordQuizUpdateEvent.QUESTION_ANSWERED, eventDispatcher, onRoomWidgetWordQuizUpdateEvent);
|
||||||
|
CreateEventDispatcherHook(RoomWidgetWordQuizUpdateEvent.QUESTION_FINISHED, eventDispatcher, onRoomWidgetWordQuizUpdateEvent);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{question && <QuestionView question={question.content} canVote={!answerSent} vote={vote}/>}
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
2
src/views/room/widgets/word-quiz/common/VoteValue.ts
Normal file
2
src/views/room/widgets/word-quiz/common/VoteValue.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export const VALUE_KEY_DISLIKE = '0';
|
||||||
|
export const VALUE_KEY_LIKE = '1';
|
@ -0,0 +1,14 @@
|
|||||||
|
import { FC } from 'react';
|
||||||
|
import { QuestionViewProps } from './QuestionView.types';
|
||||||
|
|
||||||
|
export const QuestionView:FC<QuestionViewProps> = props =>
|
||||||
|
{
|
||||||
|
const { question = null, canVote = null } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="word-quiz-question-container w-100 align-content-center d-flex">
|
||||||
|
<div className="wordquiz-question p-3 d-flex mx-auto">{question}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
export interface QuestionViewProps
|
||||||
|
{
|
||||||
|
question: string;
|
||||||
|
canVote: boolean;
|
||||||
|
vote(value: string): void;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user