@@ -229,19 +229,38 @@ window.requestAnimationFrame(() => {
229229 addDebuggingMethodsInJsConsole ( ) ;
230230} ) ;
231231
232+ /**
233+ * Dynamically gets the correct object within the Interactive Canvas
234+ * object that contains callback methods.
235+ * @returns InteractiveCanvasCallbacks object
236+ */
237+ function getInteractiveCanvasCallbacks ( ) {
238+ // Internally, the callbacks are stored in interactiveCanvas.g.[letter]
239+ // This letter is not static, and may change with each release.
240+ // We need to iterate through each letter to find callbacks.
241+ const callbackObjectKeys = Object . keys ( window . interactiveCanvas . g ) ;
242+ for ( const key of callbackObjectKeys ) {
243+ // Check that this element has an onUpdate function.
244+ if ( window . interactiveCanvas . g [ key ] . onUpdate !== undefined ) {
245+ return window . interactiveCanvas . g [ key ] ;
246+ }
247+ }
248+ throw new Error ( 'Cannot find callbacks in window.interactiveCanvas.g' ) ;
249+ }
250+
232251document . addEventListener ( 'message' , ( e : Event ) => {
233252 const event = e as MessageEvent ;
234253 const eventData = event . data ;
235254 const { type} = eventData ;
236255 switch ( type ) {
237256 case 'payload' : {
238257 const { data} = eventData ;
239- window . interactiveCanvas . g . G . onUpdate ( data ) ;
258+ getInteractiveCanvasCallbacks ( ) . onUpdate ( data ) ;
240259 break ;
241260 }
242261 case 'TtsEndpointEvent' : {
243262 const { name} = eventData ;
244- window . interactiveCanvas . g . G . onTtsMark ( name ) ;
263+ getInteractiveCanvasCallbacks ( ) . onTtsMark ( name ) ;
245264 break ;
246265 }
247266 case 'Ext-ShowHeader' : {
0 commit comments