From 270e87b372a06ffa42ebaec2969ea04fbeb9f353 Mon Sep 17 00:00:00 2001 From: shiyiya Date: Wed, 27 Mar 2024 19:12:13 +0800 Subject: [PATCH] fix(chromecast): err handler --- packages/plugins/package.json | 2 +- packages/plugins/src/chromecast.ts | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/plugins/package.json b/packages/plugins/package.json index d555c195..127574e6 100644 --- a/packages/plugins/package.json +++ b/packages/plugins/package.json @@ -1,6 +1,6 @@ { "name": "@oplayer/plugins", - "version": "1.0.12-beta.0", + "version": "1.0.12-beta.1", "author": "shiyiya", "description": "oplayer's plugin", "homepage": "https://github.com/shiyiya/oplayer", diff --git a/packages/plugins/src/chromecast.ts b/packages/plugins/src/chromecast.ts index a6ff1246..cb1ba84b 100644 --- a/packages/plugins/src/chromecast.ts +++ b/packages/plugins/src/chromecast.ts @@ -149,12 +149,15 @@ class ChromeCast implements PlayerPlugin { throw new Error(`Chrome Cast Error Code: ${errorCode}`) } } catch (error) { - const msg = - error instanceof chrome.cast.Error - ? `${error.code} - ${error.description} \n ${error.details}` - : (error as Error).message + let msg = 'UNKNOWN ERROR' - this._notice(msg) + if (error instanceof Error) { + msg = error.message + } else if (!!chrome.cast && error instanceof chrome.cast.Error) { + msg = `${error.code} - ${error.description} \n ${error.details}` + } + + this.player.emit('notice', { text: msg }) } } @@ -170,10 +173,6 @@ class ChromeCast implements PlayerPlugin { onClick: () => this.start() }) } - - _notice(message: string) { - this.player.context.ui?.notice(message) - } } export default ChromeCast