11import { type Button , registerPlugin } from '@pexip/plugin-api'
2+ import { createSelectRoomForm } from './forms/createSelectRoomForm'
3+ import { getMessageOverlay } from './messageOverlay'
4+ import { createInputMessageForm } from './forms/createInputMessageForm'
5+ import { setPlugin } from './plugin'
26
37const plugin = await registerPlugin ( {
48 id : 'message-overlay' ,
5- version : 0
9+ version : 1
610} )
711
12+ setPlugin ( plugin )
13+
814let button : Button < 'settingsMenu' > | null = null
915let creatingButton = false
1016
17+ const breakoutRooms = new Map < string , string > ( )
18+
19+ plugin . events . authenticatedWithConference . add ( async ( ) => {
20+ breakoutRooms . clear ( )
21+ } )
22+
23+ plugin . events . breakoutBegin . add ( async ( breakoutRoom ) => {
24+ breakoutRooms . set ( breakoutRoom . breakout_uuid , '' )
25+ } )
26+
27+ plugin . events . breakoutEnd . add ( async ( breakoutRoom ) => {
28+ breakoutRooms . delete ( breakoutRoom . breakout_uuid )
29+ } )
30+
1131plugin . events . conferenceStatus . add ( async ( { id, status } ) => {
12- if ( id === 'main' && ! status . directMedia && status . started ) {
32+ if ( breakoutRooms . has ( id ) && status . breakoutName != null ) {
33+ breakoutRooms . set ( id , status . breakoutName )
34+ }
35+
36+ if ( ! status . directMedia && status . started ) {
1337 await addButton ( )
1438 } else {
1539 await removeButton ( )
1640 }
1741} )
1842
1943const addButton = async ( ) : Promise < void > => {
20- console . log ( 'addButton' )
2144 if ( button != null || creatingButton ) {
2245 return
2346 }
@@ -43,65 +66,17 @@ const removeButton = async (): Promise<void> => {
4366}
4467
4568const handleClickButton = async ( ) : Promise < void > => {
46- let currentMessage = ''
47- try {
48- currentMessage = await getMessageOverlay ( )
49- console . log ( currentMessage )
50- } catch ( e ) {
51- console . error ( e )
52- }
53- await createForm ( currentMessage )
54- }
55-
56- const createForm = async ( currentMessage : string ) : Promise < void > => {
57- const form = await plugin . ui . addForm ( {
58- title : 'Set message overlay' ,
59- description :
60- 'Write your message overlay text below. If you would like to get a new line press enter or make a new line in the textarea' ,
61- form : {
62- elements : {
63- message : {
64- name : 'Enter text' ,
65- type : 'textarea' ,
66- isOptional : true ,
67- placeholder : 'Enter your message' ,
68- value : currentMessage
69- }
70- } ,
71- submitBtnTitle : 'Submit'
72- }
73- } )
69+ if ( breakoutRooms . size > 0 ) {
70+ await createSelectRoomForm ( breakoutRooms )
71+ } else {
72+ const roomId = 'main'
73+ let currentMessage = ''
7474
75- form . onInput . add ( ( result ) : void => {
76- handleFormSubmit ( form , result ) . catch ( ( e ) => {
75+ try {
76+ currentMessage = await getMessageOverlay ( roomId )
77+ } catch ( e ) {
7778 console . error ( e )
78- } )
79- } )
80- }
81-
82- const handleFormSubmit = async (
83- form : any ,
84- result : {
85- message : string
79+ }
80+ await createInputMessageForm ( roomId , currentMessage )
8681 }
87- ) : Promise < void > => {
88- form ?. remove ( )
89- await setMessageOverlay ( result . message )
90- }
91-
92- const getMessageOverlay = async ( ) : Promise < string > => {
93- const response = await ( plugin . conference as any ) . sendRequest ( {
94- method : 'GET' ,
95- path : 'get_message_text'
96- } )
97- console . log ( response )
98- return response . data . result . text ?? ''
99- }
100-
101- const setMessageOverlay = async ( text : string ) : Promise < void > => {
102- await ( plugin . conference as any ) . sendRequest ( {
103- method : 'POST' ,
104- path : 'set_message_text' ,
105- payload : { text }
106- } )
10782}
0 commit comments