Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
6fa4d1b9
Commit
6fa4d1b9
authored
Sep 02, 2023
by
Deepslient
Committed by
夏楚
Sep 02, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add semicolons to unify JS format
parent
c83a3c56
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
24 行删除
+24
-24
www/webrtc/index.html
+24
-24
没有找到文件。
www/webrtc/index.html
查看文件 @
6fa4d1b9
...
@@ -89,12 +89,12 @@
...
@@ -89,12 +89,12 @@
</div>
</div>
<script>
<script>
var
player
=
null
var
player
=
null
;
var
recvOnly
=
true
var
recvOnly
=
true
;
var
resArr
=
[]
var
resArr
=
[]
;
var
ishttps
=
'https:'
==
document
.
location
.
protocol
?
true
:
false
var
ishttps
=
'https:'
==
document
.
location
.
protocol
?
true
:
false
;
var
isLocal
=
"file:"
==
document
.
location
.
protocol
?
true
:
false
var
isLocal
=
"file:"
==
document
.
location
.
protocol
?
true
:
false
;
const
searchParams
=
new
URL
(
document
.
location
.
href
).
searchParams
;
const
searchParams
=
new
URL
(
document
.
location
.
href
).
searchParams
;
let
type
=
searchParams
.
get
(
'type'
);
let
type
=
searchParams
.
get
(
'type'
);
...
@@ -105,19 +105,19 @@
...
@@ -105,19 +105,19 @@
const
apiPath
=
`/index/api/webrtc?app=
${
searchParams
.
get
(
'app'
)
??
'live'
}
&
stream
=
$
{
searchParams
.
get
(
'stream'
)
??
'test'
}
&
type
=
$
{
type
}
`;
const
apiPath
=
`/index/api/webrtc?app=
${
searchParams
.
get
(
'app'
)
??
'live'
}
&
stream
=
$
{
searchParams
.
get
(
'stream'
)
??
'test'
}
&
type
=
$
{
type
}
`;
if(!ishttps && !isLocal){
if(!ishttps && !isLocal){
alert('本demo需要在https的网站访问 ,如果你要推流的话(this demo must access in site of https if you want push stream)')
alert('本demo需要在https的网站访问 ,如果你要推流的话(this demo must access in site of https if you want push stream)')
;
}
}
const apiHost = isLocal ? "http://127.0.0.1" : `
$
{
document
.
location
.
protocol
}
//${window.location.host}`;
const apiHost = isLocal ? "http://127.0.0.1" : `
$
{
document
.
location
.
protocol
}
//${window.location.host}`;
var
url
=
apiHost
+
apiPath
;
var
url
=
apiHost
+
apiPath
;
document
.
getElementById
(
'streamUrl'
).
value
=
url
document
.
getElementById
(
'streamUrl'
).
value
=
url
;
document
.
getElementsByName
(
"method"
).
forEach
((
el
,
idx
)
=>
{
document
.
getElementsByName
(
"method"
).
forEach
((
el
,
idx
)
=>
{
el
.
checked
=
el
.
value
===
type
;
el
.
checked
=
el
.
value
===
type
;
el
.
onclick
=
function
(
e
)
{
el
.
onclick
=
function
(
e
)
{
let
url
=
new
URL
(
document
.
getElementById
(
'streamUrl'
).
value
);
let
url
=
new
URL
(
document
.
getElementById
(
'streamUrl'
).
value
);
url
.
searchParams
.
set
(
"type"
,
el
.
value
);
url
.
searchParams
.
set
(
"type"
,
el
.
value
);
document
.
getElementById
(
'streamUrl'
).
value
=
url
.
toString
()
document
.
getElementById
(
'streamUrl'
).
value
=
url
.
toString
()
;
if
(
el
.
value
==
"play"
){
if
(
el
.
value
==
"play"
){
recvOnly
=
true
;
recvOnly
=
true
;
...
@@ -136,7 +136,7 @@
...
@@ -136,7 +136,7 @@
if
(
1080
*
720
<=
r
.
width
*
r
.
height
&&
r
.
width
*
r
.
height
<=
1280
*
720
)
{
if
(
1080
*
720
<=
r
.
width
*
r
.
height
&&
r
.
width
*
r
.
height
<=
1280
*
720
)
{
opt
.
selected
=
true
;
opt
.
selected
=
true
;
}
}
document
.
getElementById
(
"resolution"
).
add
(
opt
,
null
)
document
.
getElementById
(
"resolution"
).
add
(
opt
,
null
)
;
});
});
function
start_play
(){
function
start_play
(){
...
@@ -162,17 +162,17 @@
...
@@ -162,17 +162,17 @@
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ICE_CANDIDATE_ERROR
,
function
(
e
)
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ICE_CANDIDATE_ERROR
,
function
(
e
)
{
// ICE 协商出错
{
// ICE 协商出错
console
.
log
(
'ICE 协商出错'
)
console
.
log
(
'ICE 协商出错'
)
;
});
});
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_REMOTE_STREAMS
,
function
(
e
)
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_REMOTE_STREAMS
,
function
(
e
)
{
//获取到了远端流,可以播放
{
//获取到了远端流,可以播放
console
.
log
(
'播放成功'
,
e
.
streams
)
console
.
log
(
'播放成功'
,
e
.
streams
)
;
});
});
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED
,
function
(
e
)
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED
,
function
(
e
)
{
// offer anwser 交换失败
{
// offer anwser 交换失败
console
.
log
(
'offer anwser 交换失败'
,
e
)
console
.
log
(
'offer anwser 交换失败'
,
e
)
;
stop
();
stop
();
});
});
...
@@ -188,31 +188,31 @@
...
@@ -188,31 +188,31 @@
player
.
on
(
ZLMRTCClient
.
Events
.
CAPTURE_STREAM_FAILED
,
function
(
s
)
player
.
on
(
ZLMRTCClient
.
Events
.
CAPTURE_STREAM_FAILED
,
function
(
s
)
{
// 获取本地流失败
{
// 获取本地流失败
console
.
log
(
'获取本地流失败'
)
console
.
log
(
'获取本地流失败'
)
;
});
});
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_CONNECTION_STATE_CHANGE
,
function
(
state
)
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_CONNECTION_STATE_CHANGE
,
function
(
state
)
{
// RTC 状态变化 ,详情参考 https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionState
{
// RTC 状态变化 ,详情参考 https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionState
console
.
log
(
'当前状态==>'
,
state
)
console
.
log
(
'当前状态==>'
,
state
)
;
});
});
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_DATA_CHANNEL_OPEN
,
function
(
event
)
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_DATA_CHANNEL_OPEN
,
function
(
event
)
{
{
console
.
log
(
'rtc datachannel 打开 :'
,
event
)
console
.
log
(
'rtc datachannel 打开 :'
,
event
)
;
});
});
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_DATA_CHANNEL_MSG
,
function
(
event
)
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_DATA_CHANNEL_MSG
,
function
(
event
)
{
{
console
.
log
(
'rtc datachannel 消息 :'
,
event
.
data
)
console
.
log
(
'rtc datachannel 消息 :'
,
event
.
data
)
;
document
.
getElementById
(
'msgrecv'
).
value
=
event
.
data
document
.
getElementById
(
'msgrecv'
).
value
=
event
.
data
;
});
});
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_DATA_CHANNEL_ERR
,
function
(
event
)
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_DATA_CHANNEL_ERR
,
function
(
event
)
{
{
console
.
log
(
'rtc datachannel 错误 :'
,
event
)
console
.
log
(
'rtc datachannel 错误 :'
,
event
)
;
});
});
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_DATA_CHANNEL_CLOSE
,
function
(
event
)
player
.
on
(
ZLMRTCClient
.
Events
.
WEBRTC_ON_DATA_CHANNEL_CLOSE
,
function
(
event
)
{
{
console
.
log
(
'rtc datachannel 关闭 :'
,
event
)
console
.
log
(
'rtc datachannel 关闭 :'
,
event
)
;
});
});
}
}
...
@@ -227,12 +227,12 @@
...
@@ -227,12 +227,12 @@
if
(
document
.
getElementById
(
'useCamera'
).
checked
&&
!
recvOnly
)
if
(
document
.
getElementById
(
'useCamera'
).
checked
&&
!
recvOnly
)
{
{
ZLMRTCClient
.
isSupportResolution
(
w
,
h
).
then
(
e
=>
{
ZLMRTCClient
.
isSupportResolution
(
w
,
h
).
then
(
e
=>
{
start_play
()
start_play
()
;
}).
catch
(
e
=>
{
}).
catch
(
e
=>
{
alert
(
"not support resolution"
)
alert
(
"not support resolution"
)
;
});
});
}
else
{
}
else
{
start_play
()
start_play
()
;
}
}
}
}
...
@@ -257,13 +257,13 @@
...
@@ -257,13 +257,13 @@
function
send
(){
function
send
(){
if
(
player
){
if
(
player
){
//send msg refernece https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/send
//send msg refernece https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/send
player
.
sendMsg
(
document
.
getElementById
(
'msgsend'
).
value
)
player
.
sendMsg
(
document
.
getElementById
(
'msgsend'
).
value
)
;
}
}
}
}
function
close
(){
function
close
(){
if
(
player
){
if
(
player
){
player
.
closeDataChannel
()
player
.
closeDataChannel
()
;
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论