@quicktvui/web-renderer 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quicktvui/web-renderer",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Web renderer for QuickTVUI - provides web browser rendering support",
5
5
  "author": "QuickTVUI Team",
6
6
  "license": "Apache-2.0",
@@ -21,4 +21,4 @@
21
21
  "peerDependencies": {
22
22
  "vue": "^3.0.0"
23
23
  }
24
- }
24
+ }
@@ -1,25 +1,16 @@
1
1
  /**
2
2
  * QtBaseComponent - Base class for all QuickTV UI components
3
- * Provides common property handling (visible, visibility, etc.)
3
+ * Provides common property handling (visible, visibility, showOnState, etc.)
4
4
  */
5
5
  import { HippyWebView } from '@hippy/web-renderer'
6
6
 
7
- /**
8
- * Visibility enum values
9
- * @typedef {'visible' | 'invisible' | 'gone'} QTVisibility
10
- */
11
-
12
7
  export class QtBaseComponent extends HippyWebView {
13
8
  constructor(context, id, pId) {
14
9
  super(context, id, pId)
15
- // Store original display value for visibility toggle
16
10
  this._originalDisplay = undefined
11
+ this._showOnState = null
17
12
  }
18
13
 
19
- /**
20
- * Override updateProperty to handle common properties first
21
- * Subclasses should call super.updateProperty(key, value) for unhandled properties
22
- */
23
14
  updateProperty(key, value) {
24
15
  if (key === 'type' && this.dom) {
25
16
  if (value !== null && value !== undefined && value !== '') {
@@ -37,12 +28,6 @@ export class QtBaseComponent extends HippyWebView {
37
28
  super.updateProperty(key, value)
38
29
  }
39
30
 
40
- /**
41
- * Handle common properties
42
- * @param {string} key - Property name
43
- * @param {*} value - Property value
44
- * @returns {boolean} - True if handled
45
- */
46
31
  _handleCommonProperty(key, value) {
47
32
  switch (key) {
48
33
  case 'visible':
@@ -54,7 +39,6 @@ export class QtBaseComponent extends HippyWebView {
54
39
  return true
55
40
 
56
41
  case 'autofocus':
57
- // 将 autofocus 属性设置到 DOM 元素上,供 TVFocusManager 识别
58
42
  if (value === true || value === 'true' || value === 1 || value === '1') {
59
43
  this.dom.setAttribute('autofocus', 'true')
60
44
  } else {
@@ -63,7 +47,6 @@ export class QtBaseComponent extends HippyWebView {
63
47
  return true
64
48
 
65
49
  case 'name':
66
- // 存储 name 属性到组件实例和 DOM 上,用于子组件查找
67
50
  this.props = this.props || {}
68
51
  this.props.name = value
69
52
  if (value) {
@@ -73,39 +56,26 @@ export class QtBaseComponent extends HippyWebView {
73
56
  }
74
57
  return true
75
58
 
59
+ case 'showOnState':
60
+ this._setShowOnState(value)
61
+ return true
62
+
76
63
  default:
77
64
  return false
78
65
  }
79
66
  }
80
67
 
81
- /**
82
- * Set component visibility via boolean
83
- * @param {boolean} visible - true to show, false to hide
84
- */
85
68
  _setVisible(visible) {
86
69
  if (visible === true) {
87
- // Restore original display value if saved
88
70
  if (this._originalDisplay !== undefined) {
89
71
  this.dom.style.display = this._originalDisplay
90
72
  } else {
91
- // In Hippy, all elements default to flex layout
92
- // Check if the element has flex properties and set display: flex accordingly
93
73
  const style = this.dom.style
94
- const hasFlexProperties =
95
- style.flexDirection ||
96
- style.justifyContent ||
97
- style.alignItems ||
98
- style.flexWrap ||
99
- style.flexGrow ||
100
- style.flexShrink
101
-
102
- // Default to 'flex' for Hippy compatibility, unless display is already set
103
74
  if (!style.display || style.display === 'none') {
104
- style.display = hasFlexProperties ? 'flex' : 'flex'
75
+ style.display = 'flex'
105
76
  }
106
77
  }
107
78
  } else {
108
- // Save current display value before hiding
109
79
  if (this._originalDisplay === undefined) {
110
80
  const currentDisplay = this.dom.style.display
111
81
  if (currentDisplay && currentDisplay !== 'none') {
@@ -116,19 +86,12 @@ export class QtBaseComponent extends HippyWebView {
116
86
  }
117
87
  }
118
88
 
119
- /**
120
- * Set component visibility via enum
121
- * @param {QTVisibility} visibility - 'visible' | 'invisible' | 'gone'
122
- */
123
89
  _setVisibility(visibility) {
124
90
  switch (visibility) {
125
91
  case 'visible':
126
- // Restore display and ensure visibility
127
92
  if (this._originalDisplay !== undefined) {
128
93
  this.dom.style.display = this._originalDisplay
129
94
  } else {
130
- // In Hippy, all elements default to flex layout
131
- // Default to 'flex' for Hippy compatibility
132
95
  const style = this.dom.style
133
96
  if (!style.display || style.display === 'none') {
134
97
  style.display = 'flex'
@@ -138,12 +101,10 @@ export class QtBaseComponent extends HippyWebView {
138
101
  break
139
102
 
140
103
  case 'invisible':
141
- // Hidden but takes space
142
104
  this.dom.style.visibility = 'hidden'
143
105
  break
144
106
 
145
107
  case 'gone':
146
- // Completely hidden, doesn't take space
147
108
  if (this._originalDisplay === undefined) {
148
109
  const currentDisplay = this.dom.style.display
149
110
  if (currentDisplay && currentDisplay !== 'none') {
@@ -158,19 +119,91 @@ export class QtBaseComponent extends HippyWebView {
158
119
  }
159
120
  }
160
121
 
161
- /**
162
- * Public method to set visibility via boolean
163
- * @param {boolean} visible - true to show, false to hide
164
- */
122
+ _setShowOnState(value) {
123
+ if (value === null || value === undefined) {
124
+ this._showOnState = null
125
+ this.dom.removeAttribute('showOnState')
126
+ this.dom.style.display = ''
127
+ return
128
+ }
129
+
130
+ this._showOnState = value
131
+
132
+ if (Array.isArray(value)) {
133
+ this.dom.setAttribute('showOnState', JSON.stringify(value))
134
+ } else {
135
+ this.dom.setAttribute('showOnState', String(value))
136
+ }
137
+
138
+ this._initShowOnStateVisibility()
139
+ }
140
+
141
+ _initShowOnStateVisibility() {
142
+ if (!this._showOnState) return
143
+
144
+ const focusedParent = this.dom.closest('.focused')
145
+ const selectedParent = this.dom.closest('[selected="true"], [selected=""]')
146
+
147
+ let currentState = 'normal'
148
+ if (focusedParent) {
149
+ currentState = 'focused'
150
+ } else if (selectedParent) {
151
+ currentState = 'selected'
152
+ }
153
+
154
+ this._applyShowOnState(currentState)
155
+ }
156
+
157
+ _applyShowOnState(state) {
158
+ if (!this._showOnState) return
159
+
160
+ const states = this._parseShowOnState(this._showOnState)
161
+ const shouldShow = states.includes(state.toLowerCase())
162
+
163
+ if (shouldShow) {
164
+ if (this._originalDisplay !== undefined) {
165
+ this.dom.style.display = this._originalDisplay
166
+ } else {
167
+ this.dom.style.display = ''
168
+ }
169
+ } else {
170
+ if (this._originalDisplay === undefined) {
171
+ const currentDisplay = this.dom.style.display
172
+ if (currentDisplay && currentDisplay !== 'none') {
173
+ this._originalDisplay = currentDisplay
174
+ }
175
+ }
176
+ this.dom.style.display = 'none'
177
+ }
178
+ }
179
+
180
+ _parseShowOnState(value) {
181
+ if (Array.isArray(value)) {
182
+ return value.map((s) => String(s).toLowerCase())
183
+ }
184
+
185
+ if (typeof value === 'string') {
186
+ try {
187
+ const parsed = JSON.parse(value)
188
+ if (Array.isArray(parsed)) {
189
+ return parsed.map((s) => String(s).toLowerCase())
190
+ }
191
+ } catch (e) {}
192
+ return [value.toLowerCase()]
193
+ }
194
+
195
+ return []
196
+ }
197
+
165
198
  setVisible(visible) {
166
199
  this._setVisible(visible)
167
200
  }
168
201
 
169
- /**
170
- * Public method to set visibility via enum
171
- * @param {QTVisibility} visibility - 'visible' | 'invisible' | 'gone'
172
- */
173
202
  setVisibility(visibility) {
174
203
  this._setVisibility(visibility)
175
204
  }
205
+
206
+ setShowOnState(value) {
207
+ this._setShowOnState(value)
208
+ }
176
209
  }
@@ -2,6 +2,7 @@
2
2
  // Handles keyboard arrow keys for TV-style focus navigation
3
3
 
4
4
  import { syncDomAutoWidthIn } from './templateBinding'
5
+ import { sendKeyDownEvent, sendKeyUpEvent, sendHardwareBackPress } from './nativeEventDispatcher'
5
6
 
6
7
  const DEBUG = false
7
8
 
@@ -566,16 +567,10 @@ export class TVFocusManager {
566
567
 
567
568
  _dispatchPageKeyDown(e) {
568
569
  const keyEvent = this._toESKeyEvent(e)
569
- // action: 0 = keydown, 1 = keyup
570
- keyEvent.action = 0
571
570
 
572
571
  // 模拟 Android 平台发送 DispatchKeyEvent
573
- try {
574
- const { EventBus } = require('@extscreen/es3-vue')
575
- if (EventBus && EventBus.$emit) {
576
- EventBus.$emit('DispatchKeyEvent', keyEvent)
577
- }
578
- } catch (err) {
572
+ const sent = sendKeyDownEvent(keyEvent)
573
+ if (!sent) {
579
574
  // fallback to direct method call
580
575
  this._callCurrentPageMethod('onKeyDown', keyEvent)
581
576
  }
@@ -583,16 +578,10 @@ export class TVFocusManager {
583
578
 
584
579
  _dispatchPageKeyUp(e) {
585
580
  const keyEvent = this._toESKeyEvent(e)
586
- // action: 0 = keydown, 1 = keyup
587
- keyEvent.action = 1
588
581
 
589
582
  // 模拟 Android 平台发送 DispatchKeyEvent
590
- try {
591
- const { EventBus } = require('@extscreen/es3-vue')
592
- if (EventBus && EventBus.$emit) {
593
- EventBus.$emit('DispatchKeyEvent', keyEvent)
594
- }
595
- } catch (err) {
583
+ const sent = sendKeyUpEvent(keyEvent)
584
+ if (!sent) {
596
585
  // fallback to direct method call
597
586
  this._callCurrentPageMethod('onKeyUp', keyEvent)
598
587
  }
@@ -1876,18 +1865,8 @@ export class TVFocusManager {
1876
1865
  console.log('[TVFocusManager] dispatchBackPressed called - emitting hardwareBackPress event')
1877
1866
 
1878
1867
  // 模拟 Android 平台的硬件返回按键事件
1879
- // 通过 EventBus 发射 hardwareBackPress 事件
1880
1868
  // ESCore 监听此事件并调用 router.back()
1881
- try {
1882
- // 从 es3-vue 动态获取 EventBus(避免模块级别导入问题)
1883
- const { EventBus } = require('@extscreen/es3-vue')
1884
- if (EventBus && EventBus.$emit) {
1885
- console.log('[TVFocusManager] Emitting hardwareBackPress event')
1886
- EventBus.$emit('hardwareBackPress')
1887
- }
1888
- } catch (err) {
1889
- console.error('[TVFocusManager] Error emitting hardwareBackPress:', err)
1890
- }
1869
+ sendHardwareBackPress()
1891
1870
  }
1892
1871
 
1893
1872
  // Focus direction constants (matching QTFocusDirection enum)
package/src/core/index.js CHANGED
@@ -6,3 +6,4 @@ export * from './patches'
6
6
  export * from './TVFocusManager'
7
7
  export * from './autoProxy'
8
8
  export * from './asyncLocalStorage'
9
+ export * from './nativeEventDispatcher'
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Native Event Dispatcher
3
+ * 封装原生事件发送功能,使用 EventDispatcher.receiveNativeEvent 发送事件到原生端
4
+ */
5
+
6
+ /**
7
+ * 获取 EventDispatcher 实例
8
+ * @returns {Object|null} EventDispatcher 实例
9
+ */
10
+ function getEventDispatcher() {
11
+ try {
12
+ const jsModuleList = global.__GLOBAL__?.jsModuleList
13
+ if (!jsModuleList || !jsModuleList.EventDispatcher) {
14
+ console.warn('[NativeEventDispatcher] EventDispatcher not available in jsModuleList')
15
+ return null
16
+ }
17
+ return jsModuleList.EventDispatcher
18
+ } catch (err) {
19
+ console.error('[NativeEventDispatcher] Error getting EventDispatcher:', err)
20
+ return null
21
+ }
22
+ }
23
+
24
+ /**
25
+ * 发送原生事件
26
+ * @param {string} eventName - 事件名称
27
+ * @param {any} eventData - 事件数据,可以是 null 或任意对象
28
+ * @returns {boolean} 是否发送成功
29
+ */
30
+ export function sendNativeEvent(eventName, eventData = null) {
31
+ const eventDispatcher = getEventDispatcher()
32
+ if (!eventDispatcher) {
33
+ return false
34
+ }
35
+
36
+ try {
37
+ // 事件格式: [eventName, eventData]
38
+ eventDispatcher.receiveNativeEvent([eventName, eventData])
39
+ return true
40
+ } catch (err) {
41
+ console.error(`[NativeEventDispatcher] Error sending event "${eventName}":`, err)
42
+ return false
43
+ }
44
+ }
45
+
46
+ /**
47
+ * 发送硬件返回按键事件
48
+ * @returns {boolean} 是否发送成功
49
+ */
50
+ export function sendHardwareBackPress() {
51
+ return sendNativeEvent('hardwareBackPress', null)
52
+ }
53
+
54
+ /**
55
+ * 发送按键事件
56
+ * @param {Object} keyEvent - 按键事件对象
57
+ * @returns {boolean} 是否发送成功
58
+ */
59
+ export function sendKeyEvent(keyEvent) {
60
+ return sendNativeEvent('DispatchKeyEvent', keyEvent)
61
+ }
62
+
63
+ /**
64
+ * 发送键盘按下事件
65
+ * @param {Object} keyEvent - 按键事件对象
66
+ * @returns {boolean} 是否发送成功
67
+ */
68
+ export function sendKeyDownEvent(keyEvent) {
69
+ return sendKeyEvent({
70
+ ...keyEvent,
71
+ action: 0, // 0 = keydown
72
+ })
73
+ }
74
+
75
+ /**
76
+ * 发送键盘释放事件
77
+ * @param {Object} keyEvent - 按键事件对象
78
+ * @returns {boolean} 是否发送成功
79
+ */
80
+ export function sendKeyUpEvent(keyEvent) {
81
+ return sendKeyEvent({
82
+ ...keyEvent,
83
+ action: 1, // 1 = keyup
84
+ })
85
+ }
86
+
87
+ // 默认导出
88
+ export default {
89
+ sendNativeEvent,
90
+ sendHardwareBackPress,
91
+ sendKeyEvent,
92
+ sendKeyDownEvent,
93
+ sendKeyUpEvent,
94
+ }
package/src/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  applyAllPatches,
14
14
  TVFocusManager,
15
15
  initAutoProxy,
16
- initAsyncLocalStorage
16
+ initAsyncLocalStorage,
17
17
  } from './core'
18
18
 
19
19
  // Create component registry for web renderer
@@ -2,6 +2,7 @@
2
2
  // Uses HTML5 Audio API to implement audio playback
3
3
 
4
4
  import { resolveAddon, createModuleInit } from '../core/moduleUtils'
5
+ import { sendNativeEvent } from '../core/nativeEventDispatcher'
5
6
 
6
7
  // Player states (matching native ESPlayerState)
7
8
  const ESPlayerState = {
@@ -38,34 +39,6 @@ const ESPlayerState = {
38
39
  ES_PLAYER_STATE_INITIALIZE_ERROR: 30,
39
40
  }
40
41
 
41
- // Get EventBus lazily
42
- let _eventBus = null
43
- function getEventBus() {
44
- if (!_eventBus) {
45
- try {
46
- const esVue = require('@extscreen/es3-vue')
47
- if (esVue && esVue.EventBus) {
48
- _eventBus = esVue.EventBus
49
- }
50
- } catch (e) {
51
- console.warn('[ESIJKAudioPlayerModule] EventBus not available:', e.message)
52
- }
53
- }
54
- return _eventBus
55
- }
56
-
57
- // Dispatch event to EventBus
58
- function dispatchEvent(eventName, data) {
59
- const eventBus = getEventBus()
60
- if (eventBus && eventBus.$emit) {
61
- eventBus.$emit(eventName, data)
62
- }
63
- // Also dispatch custom event for global listeners
64
- if (typeof window !== 'undefined') {
65
- window.dispatchEvent(new CustomEvent(eventName, { detail: data }))
66
- }
67
- }
68
-
69
42
  // Audio instance manager
70
43
  class AudioPlayerManager {
71
44
  constructor() {
@@ -95,7 +68,7 @@ class AudioPlayerManager {
95
68
  audio.addEventListener('play', () => {
96
69
  if (currentState !== ESPlayerState.ES_PLAYER_STATE_PLAYING) {
97
70
  currentState = ESPlayerState.ES_PLAYER_STATE_PLAYING
98
- dispatchEvent('onESAudioPlayerStatusChanged', {
71
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
99
72
  playerStatus: ESPlayerState.ES_PLAYER_STATE_PLAYING,
100
73
  playerState: ESPlayerState.ES_PLAYER_STATE_PLAYING,
101
74
  })
@@ -106,7 +79,7 @@ class AudioPlayerManager {
106
79
  audio.addEventListener('playing', () => {
107
80
  if (currentState !== ESPlayerState.ES_PLAYER_STATE_PLAYING) {
108
81
  currentState = ESPlayerState.ES_PLAYER_STATE_PLAYING
109
- dispatchEvent('onESAudioPlayerStatusChanged', {
82
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
110
83
  playerStatus: ESPlayerState.ES_PLAYER_STATE_PLAYING,
111
84
  playerState: ESPlayerState.ES_PLAYER_STATE_PLAYING,
112
85
  })
@@ -116,7 +89,7 @@ class AudioPlayerManager {
116
89
  // Pause event
117
90
  audio.addEventListener('pause', () => {
118
91
  currentState = ESPlayerState.ES_PLAYER_STATE_PAUSED
119
- dispatchEvent('onESAudioPlayerStatusChanged', {
92
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
120
93
  playerStatus: ESPlayerState.ES_PLAYER_STATE_PAUSED,
121
94
  playerState: ESPlayerState.ES_PLAYER_STATE_PAUSED,
122
95
  })
@@ -126,7 +99,7 @@ class AudioPlayerManager {
126
99
  audio.addEventListener('ended', () => {
127
100
  currentState = ESPlayerState.ES_PLAYER_STATE_PLAYBACK_COMPLETED
128
101
  hasPrepared = true // Prevent canplay from sending PREPARED again
129
- dispatchEvent('onESAudioPlayerStatusChanged', {
102
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
130
103
  playerStatus: ESPlayerState.ES_PLAYER_STATE_PLAYBACK_COMPLETED,
131
104
  playerState: ESPlayerState.ES_PLAYER_STATE_PLAYBACK_COMPLETED,
132
105
  })
@@ -135,7 +108,7 @@ class AudioPlayerManager {
135
108
  // Error event
136
109
  audio.addEventListener('error', (e) => {
137
110
  currentState = ESPlayerState.ES_PLAYER_STATE_ERROR
138
- dispatchEvent('onESAudioPlayerError', {
111
+ sendNativeEvent('onESAudioPlayerError', {
139
112
  errorCode: e.target.error?.code || -1,
140
113
  errorMessage: e.target.error?.message || 'Audio error',
141
114
  })
@@ -145,7 +118,7 @@ class AudioPlayerManager {
145
118
  audio.addEventListener('loadstart', () => {
146
119
  hasPrepared = false
147
120
  currentState = ESPlayerState.ES_PLAYER_STATE_PREPARING
148
- dispatchEvent('onESAudioPlayerStatusChanged', {
121
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
149
122
  playerStatus: ESPlayerState.ES_PLAYER_STATE_PREPARING,
150
123
  playerState: ESPlayerState.ES_PLAYER_STATE_PREPARING,
151
124
  })
@@ -156,7 +129,7 @@ class AudioPlayerManager {
156
129
  if (!hasPrepared) {
157
130
  hasPrepared = true
158
131
  currentState = ESPlayerState.ES_PLAYER_STATE_PREPARED
159
- dispatchEvent('onESAudioPlayerStatusChanged', {
132
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
160
133
  playerStatus: ESPlayerState.ES_PLAYER_STATE_PREPARED,
161
134
  playerState: ESPlayerState.ES_PLAYER_STATE_PREPARED,
162
135
  })
@@ -165,7 +138,7 @@ class AudioPlayerManager {
165
138
 
166
139
  // Waiting (buffering)
167
140
  audio.addEventListener('waiting', () => {
168
- dispatchEvent('onESAudioPlayerStatusChanged', {
141
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
169
142
  playerStatus: ESPlayerState.ES_PLAYER_STATE_BUFFER_START,
170
143
  playerState: ESPlayerState.ES_PLAYER_STATE_BUFFER_START,
171
144
  })
@@ -173,7 +146,7 @@ class AudioPlayerManager {
173
146
 
174
147
  // Can play through (buffer end)
175
148
  audio.addEventListener('canplaythrough', () => {
176
- dispatchEvent('onESAudioPlayerStatusChanged', {
149
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
177
150
  playerStatus: ESPlayerState.ES_PLAYER_STATE_BUFFER_END,
178
151
  playerState: ESPlayerState.ES_PLAYER_STATE_BUFFER_END,
179
152
  })
@@ -182,7 +155,7 @@ class AudioPlayerManager {
182
155
  // Duration change
183
156
  audio.addEventListener('durationchange', () => {
184
157
  if (audio.duration && !isNaN(audio.duration)) {
185
- dispatchEvent('onESAudioPlayerInfo', {
158
+ sendNativeEvent('onESAudioPlayerInfo', {
186
159
  what: 1, // MEDIA_INFO_DURATION
187
160
  extra: Math.floor(audio.duration * 1000),
188
161
  })
@@ -191,14 +164,14 @@ class AudioPlayerManager {
191
164
 
192
165
  // Rate change
193
166
  audio.addEventListener('ratechange', () => {
194
- dispatchEvent('onESAudioPlayRateChanged', {
167
+ sendNativeEvent('onESAudioPlayRateChanged', {
195
168
  playRate: audio.playbackRate,
196
169
  })
197
170
  })
198
171
 
199
172
  // Seeking
200
173
  audio.addEventListener('seeking', () => {
201
- dispatchEvent('onESAudioPlayerStatusChanged', {
174
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
202
175
  playerStatus: ESPlayerState.ES_PLAYER_STATE_SEEK_START,
203
176
  playerState: ESPlayerState.ES_PLAYER_STATE_SEEK_START,
204
177
  })
@@ -206,7 +179,7 @@ class AudioPlayerManager {
206
179
 
207
180
  // Seeked
208
181
  audio.addEventListener('seeked', () => {
209
- dispatchEvent('onESAudioPlayerStatusChanged', {
182
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
210
183
  playerStatus: ESPlayerState.ES_PLAYER_STATE_SEEK_COMPLETED,
211
184
  playerState: ESPlayerState.ES_PLAYER_STATE_SEEK_COMPLETED,
212
185
  })
@@ -214,7 +187,7 @@ class AudioPlayerManager {
214
187
 
215
188
  // Volume change
216
189
  audio.addEventListener('volumechange', () => {
217
- dispatchEvent('onESAudioPlayerInfo', {
190
+ sendNativeEvent('onESAudioPlayerInfo', {
218
191
  what: 2, // MEDIA_INFO_VOLUME_CHANGED
219
192
  extra: Math.floor(audio.volume * 100),
220
193
  })
@@ -252,12 +225,12 @@ export class ESIJKAudioPlayerModule {
252
225
 
253
226
  async init(...args) {
254
227
  // Send initialized event
255
- dispatchEvent('onESAudioPlayerStatusChanged', {
228
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
256
229
  playerStatus: ESPlayerState.ES_PLAYER_STATE_PLAYER_INITIALIZED,
257
230
  playerState: ESPlayerState.ES_PLAYER_STATE_PLAYER_INITIALIZED,
258
231
  })
259
232
  // Send init success
260
- dispatchEvent('onESAudioPlayerStatusChanged', {
233
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
261
234
  playerStatus: ESPlayerState.ES_PLAYER_STATE_INITIALIZE_SUCCESS,
262
235
  playerState: ESPlayerState.ES_PLAYER_STATE_INITIALIZE_SUCCESS,
263
236
  })
@@ -266,12 +239,12 @@ export class ESIJKAudioPlayerModule {
266
239
 
267
240
  initMediaPlayer(...args) {
268
241
  // Send initialized event
269
- dispatchEvent('onESAudioPlayerStatusChanged', {
242
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
270
243
  playerStatus: ESPlayerState.ES_PLAYER_STATE_PLAYER_INITIALIZED,
271
244
  playerState: ESPlayerState.ES_PLAYER_STATE_PLAYER_INITIALIZED,
272
245
  })
273
246
  // Send init success
274
- dispatchEvent('onESAudioPlayerStatusChanged', {
247
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
275
248
  playerStatus: ESPlayerState.ES_PLAYER_STATE_INITIALIZE_SUCCESS,
276
249
  playerState: ESPlayerState.ES_PLAYER_STATE_INITIALIZE_SUCCESS,
277
250
  })
@@ -319,7 +292,7 @@ export class ESIJKAudioPlayerModule {
319
292
  if (autoplay && audio.src) {
320
293
  audio.play().catch((e) => {
321
294
  console.warn('[ESIJKAudioPlayerModule] play error:', e)
322
- dispatchEvent('onESAudioPlayerError', {
295
+ sendNativeEvent('onESAudioPlayerError', {
323
296
  errorCode: -1,
324
297
  errorMessage: e.message || 'Play error',
325
298
  })
@@ -350,7 +323,7 @@ export class ESIJKAudioPlayerModule {
350
323
  console.warn('[ESIJKAudioPlayerModule] resume error:', e)
351
324
  })
352
325
  // Send resumed event
353
- dispatchEvent('onESAudioPlayerStatusChanged', {
326
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
354
327
  playerStatus: ESPlayerState.ES_PLAYER_STATE_RESUMED,
355
328
  playerState: ESPlayerState.ES_PLAYER_STATE_RESUMED,
356
329
  })
@@ -368,14 +341,14 @@ export class ESIJKAudioPlayerModule {
368
341
  stop(id, ...args) {
369
342
  const audio = audioManager.getInstance(id)
370
343
  // Send before stop event
371
- dispatchEvent('onESAudioPlayerStatusChanged', {
344
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
372
345
  playerStatus: ESPlayerState.ES_PLAYER_STATE_BEFORE_STOP,
373
346
  playerState: ESPlayerState.ES_PLAYER_STATE_BEFORE_STOP,
374
347
  })
375
348
  audio.pause()
376
349
  audio.currentTime = 0
377
350
  // Send stopped event
378
- dispatchEvent('onESAudioPlayerStatusChanged', {
351
+ sendNativeEvent('onESAudioPlayerStatusChanged', {
379
352
  playerStatus: ESPlayerState.ES_PLAYER_STATE_STOP,
380
353
  playerState: ESPlayerState.ES_PLAYER_STATE_STOP,
381
354
  })
@@ -385,7 +358,7 @@ export class ESIJKAudioPlayerModule {
385
358
  setPlayRate(id, speed, ...args) {
386
359
  const audio = audioManager.getInstance(id)
387
360
  audio.playbackRate = Number(speed) || 1.0
388
- dispatchEvent('onESAudioPlayRateChanged', {
361
+ sendNativeEvent('onESAudioPlayRateChanged', {
389
362
  playRate: audio.playbackRate,
390
363
  })
391
364
  return resolveAddon(args, null)