@mpxjs/webpack-plugin 2.8.54 → 2.8.57

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.
@@ -1,20 +1,14 @@
1
1
  <template>
2
2
  <video
3
3
  ref="_mpx_video_ref"
4
- :class="classList"
5
- :src="src"
6
- :controls="showControlsTool"
7
- :autoplay="autoplay"
8
- :loop="loop"
9
- :muted="mutedCopy"
10
- :poster="poster"
4
+ class="video-js"
11
5
  v-bind="playsinlineAttr"
12
- >
13
- </video>
14
- </template>
15
-
16
- <script>
6
+ ></video>
7
+ </template>
8
+ <script>
17
9
  import { inheritEvent } from './getInnerListeners'
10
+ import videojs from 'video.js'
11
+ import 'video.js/dist/video-js.min.css'
18
12
 
19
13
  export default {
20
14
  name: 'mpx-video',
@@ -54,7 +48,7 @@
54
48
  type: Boolean,
55
49
  default: false
56
50
  },
57
- initialTime: { // done
51
+ initialTime: {
58
52
  type: Number,
59
53
  default: 0
60
54
  },
@@ -63,6 +57,10 @@
63
57
  type: Boolean,
64
58
  default: true
65
59
  },
60
+ showBottomProgress: { // done
61
+ type: Boolean,
62
+ default: true
63
+ },
66
64
  showFullscreenBtn: { // done
67
65
  type: Boolean,
68
66
  default: true
@@ -125,135 +123,166 @@
125
123
  default: false
126
124
  },
127
125
  playsinline: {
128
- type: Boolean,
129
- default: true
130
- }
131
- },
132
- computed: {
133
- playsinlineAttr () {
134
- if (!this.playsinline) return {}
135
- return {
136
- 'webkit-playsinline': true,
137
- 'playsinline': true,
138
- 'x5-playsinline': true
139
- }
140
- }
126
+ type: Boolean,
127
+ default: true
128
+ }
141
129
  },
142
130
  data () {
143
131
  return {
144
- showControlsTool: this.controls,
145
- mutedCopy: this.muted,
146
- classList: ''
147
132
  }
148
133
  },
134
+ computed: {
135
+ playsinlineAttr () {
136
+ if (!this.playsinline) return {}
137
+ return {
138
+ 'webkit-playsinline': true,
139
+ 'playsinline': true,
140
+ 'x5-playsinline': true,
141
+ 'x5-video-orientation': 'landscape|portrait'
142
+ }
143
+ }
144
+ },
149
145
  watch: {
150
- muted (val) {
151
- this.mutedCopy = val
146
+ muted: function (val) {
147
+ this._player?.muted(val)
148
+ },
149
+ controls: function (show) {
150
+ this.$emit('controlstoggle', inheritEvent('controlstoggle', {}, { show }))
152
151
  }
153
152
  },
154
153
  mounted () {
154
+ const videoNode = this.$refs['_mpx_video_ref']
155
+ this._player = videojs(videoNode, {
156
+ controls: true,
157
+ sources:[
158
+ {
159
+ src: this.src
160
+ }
161
+ ],
162
+ autoplay: this.autoplay,
163
+ loop: this.loop,
164
+ /**
165
+ log 若 controls 属性值为 false 则设置 poster 无效
166
+ */
167
+ poster: this.controls ? this.poster : ''
168
+ }, function () {
169
+ })
170
+ this.initPlayer()
155
171
  this.initStyle()
156
172
  this.initEvent()
157
173
  },
158
174
  methods: {
159
- initStyle () {
160
- const videoNode = this.$refs['_mpx_video_ref']
175
+ initPlayer () {
176
+ this._player.muted(this.muted)
161
177
  if (this.initialTime) {
162
- videoNode.currentTime = this.initialTime
178
+ this._player.currentTime(this.initialTime)
163
179
  }
164
- if (this.autoplay) { // log 解决autoplay无法自动播放问题
165
- this.mutedCopy = true
166
- }
167
- if (!this.showProgress) this.classList += ' mpx-no-show_progress'
168
- if (!this.showFullscreenBtn) this.classList += ' mpx-no-show_fullscreen_btn'
169
- if (!this.showPlayBtn) this.classList += ' mpx-no-show_play_btn'
170
- if (!this.showCenterPlayBtn) this.classList += ' mpx-no-show_center_play_btn'
171
- if (!this.showMuteBtn) this.classList += ' mpx-no-show_mute_btn'
172
180
  },
173
- initEvent () {
174
- const videoNode = this.$refs['_mpx_video_ref']
181
+ initStyle () {
182
+ if (!this.controls) this._player.el_.classList.add('mpx-no-show_controls')
183
+
184
+ if (!this.showBottomProgress) this._player.el_.classList.add('mpx-no-show_progress')
185
+
186
+ /**
187
+ showProgress若不设置,宽度大于240时才会显示
188
+ */
189
+ if (!this.showProgress || (this._player.el_.offsetWidth < 240 && this.showProgress)) this._player.el_.classList.add('mpx-no-show_progress')
175
190
 
176
- videoNode.addEventListener('play', (e) => {
191
+ if (!this.showFullscreenBtn) this._player.el_.classList.add('mpx-no-show_fullscreen_btn')
192
+
193
+ if (!this.showPlayBtn) this._player.el_.classList.add('mpx-no-show_play_btn')
194
+
195
+ if (!this.showCenterPlayBtn) this._player.el_.classList.add('mpx-no-show_center_play_btn')
196
+
197
+ if (!this.showMuteBtn) this._player.el_.classList.add('mpx-no-show_mute_btn')
198
+ },
199
+ initEvent () {
200
+ this._player.on('play', (e) => {
177
201
  this.$emit('play', inheritEvent('play', e, {}))
178
202
  })
179
203
 
180
- videoNode.addEventListener('pause', (e) => {
204
+ this._player.on('pause', (e) => {
181
205
  this.$emit('pause', inheritEvent('pause', e, {}))
182
206
  })
183
207
 
184
- videoNode.addEventListener('ended', (e) => {
208
+ this._player.on('ended', (e) => {
185
209
  this.$emit('ended', inheritEvent('ended', e, {}))
186
210
  })
187
211
 
188
- videoNode.addEventListener('timeupdate', (e) => {
189
- const eNode = e.target
190
- this.$emit('timeupdate', inheritEvent('timeupdate', e, { currentTime: eNode.currentTime, duration: eNode.duration }))
212
+ this._player.on('timeupdate', (e) => {
213
+ this.$emit('timeupdate', inheritEvent('timeupdate', e, {}))
191
214
  })
192
215
 
193
- videoNode.addEventListener('error', (e) => {
216
+ this._player.on('error', (e) => {
194
217
  this.$emit('error', inheritEvent('error', e, {}))
195
218
  })
196
219
 
197
- videoNode.addEventListener('waiting', (e) => {
220
+ this._player.on('waiting', (e) => {
198
221
  this.$emit('waiting', inheritEvent('waiting', e, {}))
199
222
  })
200
-
201
- videoNode.addEventListener('loadedmetadata', (e) => {
202
- const eNode = e.target
203
- this.$emit('loadedmetadata', inheritEvent('loadedmetadata', e, { width: eNode.videoWidth, height: eNode.videoHeight, duration: eNode.duration }))
223
+ this._player.on('loadedmetadata', (e) => {
224
+ this.$emit('loadedmetadata', inheritEvent('loadedmetadata', e, {}))
204
225
  })
205
226
 
206
- videoNode.addEventListener('progress', (e) => {
227
+ this._player.on('progress', (e) => {
207
228
  const eNode = e.target
208
229
  const buffered = (eNode?.buffered?.end(0)) / (eNode?.duration)
209
230
  this.$emit('progress', inheritEvent('progress', e, { buffered: buffered * 100 }))
210
231
  })
211
232
 
212
- videoNode.addEventListener('seeked', (e) => {
233
+ this._player.on('seeked', (e) => {
213
234
  const eNode = e.target
214
- this.$emit('seekcomplete', inheritEvent('seekcomplete', e, { position: eNode.currentTime }))
235
+ this.$emit('seekcomplete', inheritEvent('seekcomplete', e, { position: eNode.currentTime }))
215
236
  })
216
-
217
- videoNode.addEventListener('fullscreenchange', (e) => {
218
- // TODO direction
219
- if (document.isFullScreen) {
220
- this.$emit('fullscreenchange', inheritEvent('fullscreenchange', e, { fullScreen: true }))
221
- } else {
222
- this.$emit('fullscreenchange', inheritEvent('fullscreenchange', e, { fullScreen: false }))
237
+ this._player.on('fullscreenchange', (e) => {
238
+ if (!this._player.paused()) {
239
+ // hack: 解决退出全屏自动暂停
240
+ setTimeout(() => {
241
+ this._player.play()
242
+ }, 500)
223
243
  }
244
+ this.$emit('fullscreenchange', inheritEvent('fullscreenchange', e, { fullScreen: this._player.isFullscreen() }))
224
245
  })
225
246
 
226
- videoNode.addEventListener('enterpictureinpicture', (e) => {
247
+ this._player.on('enterpictureinpicture', (e) => {
227
248
  this.$emit('enterpictureinpicture', inheritEvent('enterpictureinpicture', e, {}))
228
249
  })
229
250
 
230
- videoNode.addEventListener('leavepictureinpicture', (e) => {
251
+ this._player.on('leavepictureinpicture', (e) => {
231
252
  this.$emit('leavepictureinpicture', inheritEvent('leavepictureinpicture', e, {}))
232
253
  })
254
+
233
255
  }
234
256
  }
235
257
  }
236
- </script>
258
+ </script>
259
+
260
+ <style lang="stylus">
261
+
262
+ .vjs-chapters-button
263
+ display: none !important
264
+
265
+ .mpx-no-show_controls
266
+ .vjs-control-bar
267
+ display none !important
237
268
 
238
- <style lang="stylus">
239
- .mpx-video-container
240
- .mpx-no-show_progress
241
- &::-webkit-media-controls-timeline
242
- display none !important
269
+ .mpx-no-show_progress
270
+ .vjs-progress-control
271
+ display none !important
243
272
 
244
- .mpx-no-show_fullscreen_btn
245
- &::-webkit-media-controls-fullscreen-button
246
- display none !important
273
+ .mpx-no-show_fullscreen_btn
274
+ .vjs-fullscreen-control
275
+ display none !important
247
276
 
248
- .mpx-no-show_play_btn
249
- &::-webkit-media-controls-play-button
250
- display none !important
277
+ .mpx-no-show_play_btn
278
+ .vjs-play-control
279
+ display none !important
251
280
 
252
- .mpx-no-show_center_play_btn
253
- &::-webkit-media-controls-start-playback-button
254
- display none !important
281
+ .mpx-no-show_center_play_btn
282
+ .vjs-big-play-button
283
+ display none !important
255
284
 
256
- .mpx-no-show_mute_btn
257
- &::-webkit-media-controls-mute-button
258
- display none !important
259
- </style>
285
+ .mpx-no-show_mute_btn
286
+ .vjs-mute-control
287
+ display none !important
288
+ </style>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <iframe ref="mpxIframe" class="mpx-iframe" :src="currentUrl"></iframe>
2
+ <iframe ref="mpxIframe" class="mpx-iframe" :src="currentUrl" :key="currentUrl"></iframe>
3
3
  </template>
4
4
 
5
5
  <script>
@@ -11,91 +11,115 @@
11
11
  const eventMessage = 'message'
12
12
  const mpx = global.__mpx
13
13
  export default {
14
- data: function () {
15
- return {
16
- origin: '',
17
- messageList: [],
18
- Loaded: false,
19
- isActived: false,
20
- mpxIframe: null,
21
- isPostMessage: false,
22
- currentUrl: ''
23
- }
24
- },
25
14
  props: {
26
15
  src: {
27
16
  type: String
28
17
  }
29
18
  },
30
- watch: {
31
- src (value) {
32
- let host
33
- host = value.split('/')
19
+ computed: {
20
+ host () {
21
+ let host = this.src.split('/')
34
22
  if (host[2]) {
35
23
  host = host[0] + '//' + host[2]
36
24
  } else {
37
25
  host = ''
38
26
  }
39
- const hostValidate = this.hostValidate(host)
27
+ return host
28
+ },
29
+ currentUrl () {
30
+ if (!this.src) return ''
31
+ const hostValidate = this.hostValidate(this.host)
40
32
  if (!hostValidate) {
41
33
  console.error('访问页面域名不符合domainWhiteLists白名单配置,请确认是否正确配置该域名白名单')
42
- return
34
+ return ''
43
35
  }
44
- this.currentUrl = value
45
- this.mpxIframe = this.$refs.mpxIframe
46
- this.mpxIframe.addEventListener('load', (event) => {
47
- this.Loaded = true
48
- const loadData = {
49
- src: this.src
36
+ return this.src
37
+ },
38
+ loadData () {
39
+ return {
40
+ src: this.host,
41
+ fullUrl: this.src
42
+ }
43
+ }
44
+ },
45
+ watch: {
46
+ currentUrl: {
47
+ handler (value) {
48
+ if (!value) {
49
+ this.$emit(eventError, getCustomEvent(eventError, {
50
+ ...this.loadData,
51
+ errMsg: 'web-view load failed due to not in domain list'
52
+ }, this))
53
+ } else {
54
+ this.$nextTick(() => {
55
+ if (this.$refs.mpxIframe && this.mpxIframe != this.$refs.mpxIframe) {
56
+ this.mpxIframe = this.$refs.mpxIframe
57
+ this.mpxIframe.addEventListener('load', (event) => {
58
+ this.$emit(eventLoad, getCustomEvent(eventLoad, this.loadData, this))
59
+ })
60
+ }
61
+ })
50
62
  }
51
- this.$emit(eventLoad, getCustomEvent(eventLoad, loadData, this))
52
- })
63
+ },
64
+ immediate: true
53
65
  }
54
66
  },
67
+ beforeCreate () {
68
+ this.messageList = []
69
+ },
55
70
  mounted () {
56
- setTimeout(() => {
57
- if (!this.Loaded) {
58
- const loadData = {
59
- src: this.src
60
- }
61
- this.$emit(eventError, getCustomEvent(eventError, loadData, this))
62
- }
63
- }, 1000)
64
- window.addEventListener('message', (event) => {
71
+ window.addEventListener('message', this.messageCallback)
72
+ },
73
+ deactivated () {
74
+ if (!this.messageList.length) {
75
+ return
76
+ }
77
+ let data = {
78
+ type: 'message',
79
+ data: this.messageList
80
+ }
81
+ this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
82
+ },
83
+ destroyed () {
84
+ window.removeEventListener('message', this.messageCallback)
85
+ if (!this.messageList.length) {
86
+ return
87
+ }
88
+ let data = {
89
+ type: 'message',
90
+ data: this.messageList
91
+ }
92
+ this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
93
+ },
94
+ methods: {
95
+ messageCallback (event) {
65
96
  const hostValidate = this.hostValidate(event.origin)
66
- const hasPostMessage = this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage
67
97
  const data = event.data
68
98
  const value = data.payload
69
- if (!this.isActived || !hostValidate) {
99
+ if (!hostValidate) {
70
100
  return
71
101
  }
72
102
  let asyncCallback = null
73
103
  switch (data.type) {
74
104
  case 'postMessage':
75
- this.isPostMessage = true
76
- this.messageList.push(value.data)
105
+ this.messageList.push(value)
77
106
  asyncCallback = Promise.resolve({
78
107
  errMsg: 'invokeWebappApi:ok'
79
108
  })
80
109
  break
81
110
  case 'navigateTo':
82
- this.isActived = false
83
111
  asyncCallback = navigateTo(value)
84
112
  break
85
113
  case 'navigateBack':
86
- this.isActived = false
87
114
  asyncCallback = value ? navigateBack(value) : navigateBack()
88
115
  break
89
116
  case 'redirectTo':
90
- this.isActived = false
91
117
  asyncCallback = redirectTo(value)
92
118
  break
93
119
  case 'switchTab':
94
- this.isActived = false
95
120
  asyncCallback = switchTab(value)
96
121
  break
97
122
  case 'reLaunch':
98
- this.isActived = false
99
123
  asyncCallback = reLaunch(value)
100
124
  break
101
125
  case 'getLocation':
@@ -110,45 +134,19 @@
110
134
  break
111
135
  }
112
136
  asyncCallback && asyncCallback.then((res) => {
113
- hasPostMessage && this.mpxIframe.contentWindow.postMessage({
137
+ this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
114
138
  type: data.type,
115
139
  callbackId: data.callbackId,
116
140
  result: res
117
141
  }, event.origin)
118
142
  }).catch((error) => {
119
- hasPostMessage && this.mpxIframe.contentWindow.postMessage({
143
+ this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
120
144
  type: data.type,
121
145
  callbackId: data.callbackId,
122
146
  error
123
147
  }, event.origin)
124
148
  })
125
- })
126
- },
127
- activated () {
128
- this.isActived = true
129
- this.isPostMessage = false
130
- },
131
- deactivated () {
132
- if (!this.isPostMessage) {
133
- return
134
- }
135
- let data = {
136
- type: 'message',
137
- data: this.messageList
138
- }
139
- this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
140
- },
141
- destroyed () {
142
- if (!this.isPostMessage) {
143
- return
144
- }
145
- let data = {
146
- type: 'message',
147
- data: this.messageList
148
- }
149
- this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
150
- },
151
- methods: {
149
+ },
152
150
  hostValidate (host) {
153
151
  const hostWhitelists = mpx.config.webviewConfig && mpx.config.webviewConfig.hostWhitelists || []
154
152
  if (hostWhitelists.length) {
@@ -89,7 +89,7 @@ module.exports = function (css, map) {
89
89
  .process(css, options)
90
90
  .then(result => {
91
91
  // ali环境添加全局样式抹平root差异
92
- if (mode === 'ali' && isApp) {
92
+ if ((mode === 'ali' || mode === 'web') && isApp) {
93
93
  result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\n.${MPX_APP_MODULE_ID} { line-height: normal }`
94
94
  }
95
95
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.54",
3
+ "version": "2.8.57",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -54,7 +54,8 @@
54
54
  "postcss-modules-values": "^4.0.0",
55
55
  "postcss-selector-parser": "^6.0.8",
56
56
  "postcss-value-parser": "^4.0.2",
57
- "source-list-map": "^2.0.0"
57
+ "source-list-map": "^2.0.0",
58
+ "video.js": "^8.6.0"
58
59
  },
59
60
  "peerDependencies": {
60
61
  "webpack": "^5.48.0"
@@ -81,5 +82,5 @@
81
82
  "engines": {
82
83
  "node": ">=14.14.0"
83
84
  },
84
- "gitHead": "e39ad9b35cdb336f271f424dbfae9cf7688c8d0d"
85
+ "gitHead": "f533e8035850c01d5e98fc748ee4d57f60ba9dba"
85
86
  }