@@ -41,51 +41,6 @@ let openIDToken: string;
4141
4242let widgetApi : WidgetApi ;
4343
44- function processOpenIDMessage ( msg ) {
45- const data = ( msg . action === 'get_openid' ) ? msg . response : msg . data ;
46- // TODO: just use data.state once https://github.com/matrix-org/matrix-react-sdk/pull/5172 is out
47- const result = ( data . state !== undefined ) ? data . state :
48- ( data . success === true ) ? 'allowed' : 'blocked' ;
49-
50- switch ( result ) {
51- case 'allowed' :
52- console . info ( 'Successfully got OpenID credentials.' ) ;
53- openIDToken = data . access_token ;
54- // Send a response if this was not a response
55- if ( msg . action === 'openid_credentials' ) {
56- const request = objectClone ( msg ) ;
57- request . response = { } ;
58- window . parent . postMessage ( request , '*' ) ;
59- }
60- enableJoinButton ( ) ;
61- break ;
62- case 'blocked' :
63- console . warn ( 'OpenID credentials request was blocked by user.' ) ;
64- document . getElementById ( "widgetActionContainer" ) . innerText = "Failed to load Jitsi widget" ;
65- break ;
66- default :
67- // nothing to do
68- }
69- }
70-
71- /**
72- * Implements processing OpenID token requests as per MSC1960
73- */
74- function onWidgetMessage ( msg ) {
75- const data = msg . data ;
76- if ( ! data ) {
77- return ;
78- }
79- switch ( data . action ) {
80- case 'get_openid' :
81- case 'openid_credentials' :
82- processOpenIDMessage ( data ) ;
83- break ;
84- default :
85- // Nothing to do
86- }
87- }
88-
8944( async function ( ) {
9045 try {
9146 // The widget's options are encoded into the fragment to avoid leaking info to the server. The widget
@@ -147,6 +102,47 @@ function onWidgetMessage(msg) {
147102 }
148103} ) ( ) ;
149104
105+ function processOpenIDMessage ( msg ) {
106+ const data = ( msg . action === 'get_openid' ) ? msg . response : msg . data ;
107+
108+ switch ( data . state ) {
109+ case 'allowed' :
110+ console . info ( 'Successfully got OpenID credentials.' ) ;
111+ openIDToken = data . access_token ;
112+ // Send a response if this was not a response
113+ if ( msg . action === 'openid_credentials' ) {
114+ const request = objectClone ( msg ) ;
115+ request . response = { } ;
116+ window . parent . postMessage ( request , '*' ) ;
117+ }
118+ enableJoinButton ( ) ;
119+ break ;
120+ case 'blocked' :
121+ console . warn ( 'OpenID credentials request was blocked by user.' ) ;
122+ document . getElementById ( "widgetActionContainer" ) . innerText = "Failed to load Jitsi widget" ;
123+ break ;
124+ default :
125+ // nothing to do
126+ }
127+ }
128+
129+ /**
130+ * Implements processing OpenID token requests as per MSC1960
131+ */
132+ function onWidgetMessage ( msg ) {
133+ const data = msg . data ;
134+ if ( ! data ) {
135+ return ;
136+ }
137+ switch ( data . action ) {
138+ case 'get_openid' :
139+ case 'openid_credentials' :
140+ processOpenIDMessage ( data ) ;
141+ break ;
142+ default :
143+ // Nothing to do
144+ }
145+ }
150146
151147function enableJoinButton ( ) {
152148 document . getElementById ( "joinButton" ) . onclick = ( ) => joinConference ( ) ;
0 commit comments