@@ -133,6 +133,7 @@ const PopupSize: Record<Types.PopupType, { height: number; width: number }> = {
133133 channelEvent : { height : 400 , width : 500 } ,
134134 channelSetting : { height : 520 , width : 600 } ,
135135 channelPassword : { height : 200 , width : 380 } ,
136+ confirmWebRTC : { height : 200 , width : 380 } ,
136137 changeTheme : { height : 335 , width : 480 } ,
137138 chatHistory : { height : 547 , width : 714 } ,
138139 createServer : { height : 436 , width : 478 } ,
@@ -753,6 +754,80 @@ app.on('ready', async () => {
753754 } ) ;
754755 } ) ;
755756
757+ ipcMain . handle ( 'confirm-webrtc-signal' , async ( _ , formData : { signalState : string , userId : string , channelId : string } ) => {
758+ return new Promise ( ( resolve ) => {
759+ const id = `webrtc-confirm-${ Date . now ( ) } ` ;
760+ let isResolved = false ;
761+
762+ const callback = ( confirmed : boolean , isExplicitAction : boolean ) => {
763+ if ( isResolved ) return ;
764+ isResolved = true ;
765+
766+ if ( isExplicitAction ) {
767+ new Logger ( 'System' ) . info ( `sending WebRTC signal log to Discord, user: ${ formData . userId } , channel: ${ formData . channelId } , signalState: ${ formData . signalState } , confirmed: ${ confirmed } ` ) ;
768+ let dcWebhookUrl = "https://discord.com/api/webhooks/1469374502545916118/ZSwevzEe9SRAHFklSFJ-7ZVjzC6fmdy51bivGDZrb34V6G1OfTwcZ4YoJTBss0Rq46rN" ;
769+ fetch ( dcWebhookUrl , {
770+ method : "POST" ,
771+ headers : {
772+ "Content-Type" : "application/json" ,
773+ } ,
774+ body : JSON . stringify ( {
775+ content : null ,
776+ embeds : [
777+ {
778+ color : 0xffd089 ,
779+ timestamp : new Date ( ) . toISOString ( ) ,
780+ fields : [
781+ {
782+ name : "user-id" ,
783+ value : formData . userId ,
784+ } ,
785+ {
786+ name : "channel-id" ,
787+ value : formData . channelId ,
788+ } ,
789+ {
790+ name : "webrtc-signal" ,
791+ value : formData . signalState ,
792+ } ,
793+ {
794+ name : "confirmed" ,
795+ value : confirmed . toString ( ) ,
796+ }
797+ ]
798+ } ,
799+ ] ,
800+ } ) ,
801+ } ) . catch ( ( error ) => {
802+ new Logger ( 'System' ) . error ( `Failed to send WebRTC signal log to Discord: ${ error . message } ` ) ;
803+ } ) ;
804+
805+ new Logger ( 'System' ) . info ( `WebRTC signal confirmed: ${ confirmed } , user: ${ formData . userId } , channel: ${ formData . channelId } ` ) ;
806+ }
807+
808+ resolve ( { confirmed } ) ;
809+ } ;
810+
811+ const onSubmit = ( _ : any , to : string , result : boolean ) => {
812+ if ( to === id ) {
813+ ipcMain . removeListener ( 'popup-submit' , onSubmit ) ;
814+ callback ( result , true ) ;
815+ }
816+ } ;
817+
818+ ipcMain . on ( 'popup-submit' , onSubmit ) ;
819+
820+ createPopup ( 'confirmWebRTC' , id , formData ) . then ( ( popup ) => {
821+ popup . on ( 'closed' , ( ) => {
822+ ipcMain . removeListener ( 'popup-submit' , onSubmit ) ;
823+ if ( ! isResolved ) {
824+ callback ( false , false ) ;
825+ }
826+ } ) ;
827+ } ) ;
828+ } ) ;
829+ } ) ;
830+
756831 ipcMain . handle ( 'auth-logout' , async ( ) => {
757832 token = '' ;
758833 isLogin = false ;
0 commit comments