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
| import {
| createLivePusherContext as createNVueLivePusherContext
| } from 'uni-platforms/app-plus-nvue/service/api/context/live-pusher'
| import {
| callback
| } from 'uni-shared'
|
| function operateLivePusher (livePusherId, pageVm, type, data) {
| const pageId = pageVm.$page.id
| UniServiceJSBridge.publishHandler(pageId + '-livepusher-' + livePusherId, {
| livePusherId,
| type,
| data
| }, pageId)
| }
|
| UniServiceJSBridge.subscribe('onLivePusherMethodCallback', ({
| callbackId,
| data
| }) => {
| callback.invoke(callbackId, data)
| })
|
| const methods = [
| 'start',
| 'stop',
| 'pause',
| 'resume',
| 'switchCamera',
| 'startPreview',
| 'stopPreview',
| 'snapshot'
| ]
|
| const methodMapping = {
| startPreview: 'preview',
| stopPreview: 'stop'
| }
|
| export class LivePusherContext {
| constructor (id, pageVm) {
| this.id = id
| this.pageVm = pageVm
| }
|
| on (name, callback) {
| operateLivePusher(this.id, this.pageVm, 'on', {
| name,
| callback
| })
| }
| }
|
| methods.forEach(function (method) {
| LivePusherContext.prototype[method] = callback.warp(function (options, callbackId) {
| options.callbackId = callbackId
| const methodName = methodMapping[method] ? methodMapping[method] : method
| operateLivePusher(this.id, this.pageVm, methodName, options)
| })
| })
|
| export function createLivePusherContext (id, context) {
| if (context.$page.meta.isNVue) {
| return createNVueLivePusherContext(id, context)
| }
| return new LivePusherContext(id, context)
| }
|
|