From 444813b3e25d840a6223afd14bd2e3387bb108b8 Mon Sep 17 00:00:00 2001 From: handongxun Date: Tue, 25 Jan 2022 15:50:58 +0800 Subject: [PATCH] vue live-pusher --- .../service/api/context/live-pusher.js | 53 ++++++- .../view/components/live-pusher/index.vue | 149 ++++++++++++++++++ 2 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 src/platforms/app-plus/view/components/live-pusher/index.vue diff --git a/src/platforms/app-plus/service/api/context/live-pusher.js b/src/platforms/app-plus/service/api/context/live-pusher.js index e698820b0..7ef794946 100644 --- a/src/platforms/app-plus/service/api/context/live-pusher.js +++ b/src/platforms/app-plus/service/api/context/live-pusher.js @@ -1,7 +1,52 @@ import { - createLivePusherContext as createLivePusher -} from 'uni-platforms/app-plus-nvue/service/api/context/live-pusher' + callback +} from 'uni-shared' -export function createLivePusherContext (id, vm) { - return createLivePusher(id, vm) +function operateLivePusher (livePusherId, pageVm, type, data) { + const pageId = pageVm.$page.id + UniServiceJSBridge.publishHandler(pageId + '-live-pusher-' + livePusherId, { + livePusherId, + type, + data + }, pageId) +} + +UniServiceJSBridge.subscribe('onLivePusherMethodCallback', ({ + callbackId, + data +}) => { + callback.invoke(callbackId, data) +}) + +const methods = ['preview', + 'start', + 'stop', + 'pause', + 'resume', + 'switchCamera', + 'snapshot'] + +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 + operateLivePusher(this.id, this.pageVm, method, options) + }) +}) + +export function createLivePusherContext (id, context) { + return new LivePusherContext(id, context) } diff --git a/src/platforms/app-plus/view/components/live-pusher/index.vue b/src/platforms/app-plus/view/components/live-pusher/index.vue new file mode 100644 index 000000000..71d6b1391 --- /dev/null +++ b/src/platforms/app-plus/view/components/live-pusher/index.vue @@ -0,0 +1,149 @@ + + + + -- GitLab