'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import initSubscribe from 'uni-core/service/bridge/subscribe'
 
import {
  VD_SYNC,
  VD_SYNC_CALLBACK,
  INVOKE_API,
  WEBVIEW_READY,
  WEB_INVOKE_APPSERVICE,
  WEBVIEW_INSERTED,
  WEBVIEW_REMOVED
} from '../../../constants'
 
import {
  registerPlusMessage
} from '../plus-message'
 
import onWebviewReady from './on-webview-ready'
 
import onVdSync from './on-vd-sync'
import onVdSyncCallback from './on-vd-sync-callback'
 
import onInvokeApi from './on-invoke-api'
import onWxsInvokeCallMethod from './on-wxs-invoke-call-method'
 
import {
  onWebviewInserted,
  onWebviewRemoved
} from './on-webview-lifecycle'
 
export function initSubscribeHandlers () {
  const {
    on,
    emit,
    subscribe,
    publishHandler,
    subscribeHandler
  } = UniServiceJSBridge
 
  initSubscribe(subscribe, {
    getApp,
    getCurrentPages
  })
 
  registerPlusMessage('subscribeHandler', (data) => {
    subscribeHandler(data.type, data.data, data.pageId)
  })
 
  if (__uniConfig.renderer !== 'native') {
    subscribe(WEBVIEW_READY, onWebviewReady)
 
    subscribe(VD_SYNC, onVdSync)
    subscribe(VD_SYNC_CALLBACK, onVdSyncCallback)
 
    const entryPagePath = '/' + __uniConfig.entryPagePath
    const routeOptions = __uniRoutes.find(route => route.path === entryPagePath)
    if (!routeOptions.meta.isNVue) { // 首页是 vue
      // 防止首页 webview 初始化过早, service 还未开始监听
      publishHandler(WEBVIEW_READY, Object.create(null), [1])
    }
  }
 
  // 应该使用subscribe,兼容老版本先用 on api 吧
  on('api.' + WEB_INVOKE_APPSERVICE, function (data, webviewIds) {
    emit('onWebInvokeAppService', data, webviewIds)
  })
 
  subscribe('onWxsInvokeCallMethod', onWxsInvokeCallMethod)
 
  subscribe(INVOKE_API, onInvokeApi)
 
  subscribe(WEBVIEW_INSERTED, onWebviewInserted)
  subscribe(WEBVIEW_REMOVED, onWebviewRemoved)
}