Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
genary
uni-app
提交
83efd79c
U
uni-app
项目概览
genary
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
83efd79c
编写于
3月 10, 2022
作者:
d-u-a
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: vue3 支持 vue live-pusher 组件
上级
922cec6b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
254 addition
and
13 deletion
+254
-13
packages/uni-app-plus/src/service/api/context/createLivePusherContext.ts
...p-plus/src/service/api/context/createLivePusherContext.ts
+71
-9
packages/uni-app-plus/src/view/components/live-pusher/index.tsx
...es/uni-app-plus/src/view/components/live-pusher/index.tsx
+131
-0
packages/uni-app-plus/src/view/framework/dom/components/UniLivePusher.ts
...p-plus/src/view/framework/dom/components/UniLivePusher.ts
+21
-4
packages/uni-app-plus/style/live-pusher.css
packages/uni-app-plus/style/live-pusher.css
+31
-0
未找到文件。
packages/uni-app-plus/src/service/api/context/createLivePusherContext.ts
浏览文件 @
83efd79c
...
...
@@ -79,20 +79,82 @@ class LivePusherContext implements UniApp.LivePusherContext {
'
setMICVolume
'
:
()
=>
{}
}
// TODO
function
publishToView
(
livePusherId
:
string
,
pageId
:
number
,
type
:
string
,
data
?:
unknown
)
{
UniServiceJSBridge
.
invokeViewMethod
(
'
livepusher.
'
+
livePusherId
,
{
livePusherId
,
type
,
data
,
},
pageId
)
}
class
LivePusherContextVue
{
private
id
:
string
private
pageId
:
number
constructor
(
id
:
string
,
pageId
:
number
)
{
this
.
id
=
id
this
.
pageId
=
pageId
}
start
()
{
publishToView
(
this
.
id
,
this
.
pageId
,
'
start
'
)
}
stop
()
{
publishToView
(
this
.
id
,
this
.
pageId
,
'
stop
'
)
}
pause
()
{
publishToView
(
this
.
id
,
this
.
pageId
,
'
pause
'
)
}
resume
()
{
publishToView
(
this
.
id
,
this
.
pageId
,
'
resume
'
)
}
switchCamera
()
{
publishToView
(
this
.
id
,
this
.
pageId
,
'
switchCamera
'
)
}
startPreview
()
{
publishToView
(
this
.
id
,
this
.
pageId
,
'
preview
'
)
}
stopPreview
()
{
publishToView
(
this
.
id
,
this
.
pageId
,
'
stop
'
)
}
snapshot
()
{
publishToView
(
this
.
id
,
this
.
pageId
,
'
snapshot
'
)
}
}
export
const
createLivePusherContext
=
defineSyncApi
<
API_TYPE_CREATE_LIVE_PUSHER_CONTEXT
>
(
API_CREATE_LIVE_PUSHER_CONTEXT
,
(
id
,
vm
)
=>
{
if
(
!
vm
)
{
return
console
.
warn
(
'
uni.createLivePusherContext: 2 arguments required, but only 1 present
'
)
}
const
elm
=
findElmById
(
id
,
vm
)
if
(
!
elm
)
{
return
console
.
warn
(
'
Can not find `
'
+
id
+
'
`
'
)
if
(
vm
.
$page
.
meta
.
isNVue
)
{
if
(
!
vm
)
{
return
console
.
warn
(
'
uni.createLivePusherContext: 2 arguments required, but only 1 present
'
)
}
const
elm
=
findElmById
(
id
,
vm
)
if
(
!
elm
)
{
return
console
.
warn
(
'
Can not find `
'
+
id
+
'
`
'
)
}
return
new
LivePusherContext
(
id
,
elm
)
}
return
new
LivePusherContext
(
id
,
elm
)
return
new
LivePusherContext
Vue
(
id
,
vm
.
$page
.
id
)
},
CreateLivePusherContextProtocol
)
packages/uni-app-plus/src/view/components/live-pusher/index.tsx
0 → 100644
浏览文件 @
83efd79c
import
{
Ref
,
ref
,
watch
,
onBeforeUnmount
}
from
'
vue
'
import
{
defineBuiltInComponent
,
useCustomEvent
,
EmitEvent
,
useSubscribe
,
useContextInfo
,
}
from
'
@dcloudio/uni-components
'
import
{
useNativeAttrs
,
useNative
}
from
'
../../../helpers/useNative
'
const
props
=
{
id
:
{
type
:
String
,
default
:
''
,
},
url
:
{
type
:
String
,
default
:
''
,
},
mode
:
{
type
:
String
,
default
:
'
SD
'
,
},
muted
:
{
type
:
[
Boolean
,
String
],
default
:
false
,
},
enableCamera
:
{
type
:
[
Boolean
,
String
],
default
:
true
,
},
autoFocus
:
{
type
:
[
Boolean
,
String
],
default
:
true
,
},
beauty
:
{
type
:
[
Number
,
String
],
default
:
0
,
},
whiteness
:
{
type
:
[
Number
,
String
],
default
:
0
,
},
aspect
:
{
type
:
[
String
],
default
:
'
3:2
'
,
},
minBitrate
:
{
type
:
[
Number
],
default
:
200
,
},
}
type
EventName
=
'
statechange
'
|
'
netstatus
'
|
'
error
'
const
emits
:
EventName
[]
=
[
'
statechange
'
,
'
netstatus
'
,
'
error
'
]
export
default
/*#__PURE__*/
defineBuiltInComponent
({
name
:
'
LivePusher
'
,
props
,
emits
,
setup
(
props
,
{
emit
})
{
const
rootRef
:
Ref
<
HTMLElement
|
null
>
=
ref
(
null
)
const
trigger
=
useCustomEvent
<
EmitEvent
<
typeof
emit
>>
(
rootRef
,
emit
)
const
containerRef
:
Ref
<
HTMLElement
|
null
>
=
ref
(
null
)
const
attrs
=
useNativeAttrs
(
props
,
[
'
id
'
])
const
{
position
,
hidden
,
onParentReady
}
=
useNative
(
containerRef
)
let
livePusher
:
PlusVideoLivePusher
onParentReady
(()
=>
{
livePusher
=
new
plus
.
video
.
LivePusher
!
(
'
livePusher
'
+
Date
.
now
(),
Object
.
assign
({},
attrs
.
value
,
position
)
)
plus
.
webview
.
currentWebview
().
append
(
livePusher
as
any
)
emits
.
forEach
((
key
)
=>
{
livePusher
.
addEventListener
(
key
,
(
event
)
=>
{
trigger
(
key
,
{}
as
Event
,
event
.
detail
)
})
})
watch
(
()
=>
attrs
.
value
,
(
attrs
)
=>
livePusher
.
setStyles
(
attrs
as
any
),
{
deep
:
true
}
)
watch
(
()
=>
position
,
(
position
)
=>
livePusher
.
setStyles
(
position
),
{
deep
:
true
}
)
watch
(
()
=>
hidden
.
value
,
(
val
)
=>
{
// iOS 隐藏状态设置 setStyles 不生效
if
(
!
val
)
{
livePusher
.
setStyles
(
position
)
}
}
)
})
const
id
=
useContextInfo
()
useSubscribe
(
(
type
:
string
,
data
:
any
)
=>
{
if
(
livePusher
)
{
// @ts-expect-error
livePusher
[
type
as
any
](
data
)
}
},
id
,
true
)
onBeforeUnmount
(()
=>
{
if
(
livePusher
)
{
livePusher
.
close
()
}
})
return
()
=>
{
return
(
<
uni
-
live
-
pusher
ref
=
{
rootRef
}
id
=
{
props
.
id
}
>
<
div
ref
=
{
containerRef
}
class
=
"uni-live-pusher-container"
/>
</
uni
-
live
-
pusher
>
)
}
},
})
packages/uni-app-plus/src/view/framework/dom/components/UniLivePusher.ts
浏览文件 @
83efd79c
import
{
UniTodoNode
}
from
'
../elements/UniTodoNode
'
import
{
UniNodeJSON
}
from
'
@dcloudio/uni-shared
'
import
'
../../../../../style/live-pusher.css
'
import
LivePusher
from
'
../../../components/live-pusher
'
export
class
UniLivePusher
extends
UniTodoNode
{
constructor
(
id
:
number
,
parentNodeId
:
number
,
refNodeId
:
number
)
{
super
(
id
,
'
uni-live-pusher
'
,
parentNodeId
,
refNodeId
)
import
{
UniComponent
}
from
'
./UniComponent
'
export
class
UniLivePusher
extends
UniComponent
{
constructor
(
id
:
number
,
parentNodeId
:
number
,
refNodeId
:
number
,
nodeJson
:
Partial
<
UniNodeJSON
>
)
{
super
(
id
,
'
uni-live-pusher
'
,
LivePusher
,
parentNodeId
,
refNodeId
,
nodeJson
,
'
.uni-live-pusher-slot
'
)
}
}
packages/uni-app-plus/style/live-pusher.css
0 → 100644
浏览文件 @
83efd79c
uni-live-pusher
{
width
:
320px
;
height
:
240px
;
display
:
inline-block
;
line-height
:
0
;
overflow
:
hidden
;
position
:
relative
;
}
uni-live-pusher
[
hidden
]
{
display
:
none
;
}
.uni-live-pusher-container
{
width
:
100%
;
height
:
100%
;
position
:
absolute
;
top
:
0
;
left
:
0
;
overflow
:
hidden
;
background-color
:
black
;
}
.uni-live-pusher-slot
{
position
:
absolute
;
top
:
0
;
width
:
100%
;
height
:
100%
;
overflow
:
hidden
;
pointer-events
:
none
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录