live-pusher.js 1.8 KB
Newer Older
M
mehaotian 已提交
1
import {
fxy060608's avatar
fxy060608 已提交
2
  findElmById,
M
mehaotian 已提交
3 4 5 6 7
  invokeVmMethod,
  invokeVmMethodWithoutArgs
} from '../util'

class LivePusherContext {
fxy060608's avatar
format  
fxy060608 已提交
8
  constructor (id, ctx) {
M
mehaotian 已提交
9 10 11 12
    this.id = id
    this.ctx = ctx
  }

fxy060608's avatar
format  
fxy060608 已提交
13
  start (cbs) {
M
mehaotian 已提交
14 15 16
    return invokeVmMethodWithoutArgs(this.ctx, 'start', cbs)
  }

fxy060608's avatar
format  
fxy060608 已提交
17
  stop (cbs) {
M
mehaotian 已提交
18 19 20
    return invokeVmMethodWithoutArgs(this.ctx, 'stop', cbs)
  }

fxy060608's avatar
format  
fxy060608 已提交
21
  pause (cbs) {
M
mehaotian 已提交
22 23 24
    return invokeVmMethodWithoutArgs(this.ctx, 'pause', cbs)
  }

fxy060608's avatar
format  
fxy060608 已提交
25
  resume (cbs) {
fxy060608's avatar
fxy060608 已提交
26 27 28
    return invokeVmMethodWithoutArgs(this.ctx, 'resume', cbs)
  }

fxy060608's avatar
format  
fxy060608 已提交
29
  switchCamera (cbs) {
M
mehaotian 已提交
30 31 32
    return invokeVmMethodWithoutArgs(this.ctx, 'switchCamera', cbs)
  }

fxy060608's avatar
format  
fxy060608 已提交
33
  snapshot (cbs) {
M
mehaotian 已提交
34 35 36
    return invokeVmMethodWithoutArgs(this.ctx, 'snapshot', cbs)
  }

fxy060608's avatar
format  
fxy060608 已提交
37
  toggleTorch (cbs) {
M
mehaotian 已提交
38 39
    return invokeVmMethodWithoutArgs(this.ctx, 'toggleTorch', cbs)
  }
fxy060608's avatar
fxy060608 已提交
40

fxy060608's avatar
format  
fxy060608 已提交
41
  playBGM (args) {
fxy060608's avatar
fxy060608 已提交
42 43 44
    return invokeVmMethod(this.ctx, 'playBGM', args)
  }

fxy060608's avatar
format  
fxy060608 已提交
45
  stopBGM (cbs) {
fxy060608's avatar
fxy060608 已提交
46 47 48
    return invokeVmMethodWithoutArgs(this.ctx, 'stopBGM', cbs)
  }

fxy060608's avatar
format  
fxy060608 已提交
49
  pauseBGM (cbs) {
fxy060608's avatar
fxy060608 已提交
50 51 52
    return invokeVmMethodWithoutArgs(this.ctx, 'pauseBGM', cbs)
  }

fxy060608's avatar
format  
fxy060608 已提交
53
  resumeBGM (cbs) {
fxy060608's avatar
fxy060608 已提交
54 55 56
    return invokeVmMethodWithoutArgs(this.ctx, 'resumeBGM', cbs)
  }

fxy060608's avatar
format  
fxy060608 已提交
57
  setBGMVolume (cbs) {
fxy060608's avatar
fxy060608 已提交
58 59 60
    return invokeVmMethod(this.ctx, 'setBGMVolume', cbs)
  }

fxy060608's avatar
format  
fxy060608 已提交
61
  startPreview (cbs) {
fxy060608's avatar
fxy060608 已提交
62 63 64
    return invokeVmMethodWithoutArgs(this.ctx, 'startPreview', cbs)
  }

fxy060608's avatar
format  
fxy060608 已提交
65
  stopPreview (args) {
M
mehaotian 已提交
66
    return invokeVmMethodWithoutArgs(this.ctx, 'stopPreview', args)
fxy060608's avatar
fxy060608 已提交
67
  }
M
mehaotian 已提交
68 69
}

fxy060608's avatar
format  
fxy060608 已提交
70
export function createLivePusherContext (id, vm) {
fxy060608's avatar
fxy060608 已提交
71
  if (!vm) {
fxy060608's avatar
fxy060608 已提交
72
    return global.nativeLog('uni.createLivePusherContext 必须传入第二个参数,即当前 vm 对象(this)', '__WARN')
fxy060608's avatar
fxy060608 已提交
73 74 75
  }
  const elm = findElmById(id, vm)
  if (!elm) {
fxy060608's avatar
fxy060608 已提交
76
    return global.nativeLog('Can not find `' + id + '`', '__WARN')
M
mehaotian 已提交
77
  }
fxy060608's avatar
fxy060608 已提交
78
  return new LivePusherContext(id, elm)
M
mehaotian 已提交
79
}