I am trying to develop TWA to be hosted on the google play store. Currently, my pwa application can utilize chromecast to cast video to smart TVs. However, when I tried to bundle the pwa into a TWA, I get the following error when trying to initialize chromecast:
error requesting session: session_error
Below is my simplified setup for chromecast in my Vue application:
export default {
data() {
return {
remotePlayer: null,
remotePlayerController: null,
castInitialized: false,
casting: false,
}
},
mounted() {
window.__onGCastApiAvailable = (isAvailable) => {
if (isAvailable) {
this.initializeCastApi()
}
}
},
methods: {
initializeCastApi() {
cast.framework.CastContext.getInstance().setOptions({
// receiverApplicationId: 'DCFC1A35', // (TESTING)
receiverApplicationId: this.audioOnly ? '6054D6F9' : '6F6AB411', // (PROD)
// receiverApplicationId: '99574D83', // (LOCAL)
autoJoinPolicy: chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED
})
this.castInitialized = true
const context = cast.framework.CastContext.getInstance()
context.addEventListener(cast.framework.CastContextEventType.SESSION_STATE_CHANGED, (e) => {
if (e.sessionState === 'SESSION_STARTED' || e.sessionState === 'SESSION_RESUMED') {
this.setCasting(true)
this.loadNewMedia()
}
if (e.sessionState === 'SESSION_ENDED') {
this.setCasting(false)
}
})
},
stopCasting() {
this.setCasting(false)
cast.framework.CastContext.getInstance().endCurrentSession(true)
},
async startCast() {
if (this.casting) {
this.stopCasting()
return
}
await cast.framework.CastContext.getInstance()
.requestSession()
.catch((error) => {
console.log('error requesting session', error)
})
},
requestSrc() {
return {
...this.source
}
}
}
}
Any help would be greatly appreciated