导入数据库表和音视频demo
This commit is contained in:
16
media-server-demo-node/www/datachannels/index.html
Normal file
16
media-server-demo-node/www/datachannels/index.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" type="text/css">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
|
||||
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
|
||||
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
<script src="js/datachannels.js" type="text/javascript"></script>
|
||||
50
media-server-demo-node/www/datachannels/js/datachannels.js
Normal file
50
media-server-demo-node/www/datachannels/js/datachannels.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const url = "wss://"+window.location.hostname+":"+window.location.port;
|
||||
|
||||
|
||||
|
||||
var sdp;
|
||||
var pc;
|
||||
|
||||
function connect()
|
||||
{
|
||||
|
||||
//Create PC
|
||||
pc = new RTCPeerConnection();
|
||||
const dc = pc.createDataChannel("aaaaaaaaaaaaaaaa");
|
||||
|
||||
var ws = new WebSocket(url,"datachannels");
|
||||
|
||||
ws.onopen = async function() {
|
||||
//Create new offer
|
||||
const offer = await pc.createOffer();
|
||||
//We have sdp
|
||||
sdp = offer.sdp;
|
||||
console.log("offer",sdp);
|
||||
//Set it
|
||||
await pc.setLocalDescription(offer);
|
||||
//Create room
|
||||
ws.send(JSON.stringify({
|
||||
cmd : "OFFER",
|
||||
offer : sdp
|
||||
}));
|
||||
};
|
||||
|
||||
ws.onmessage = function(event){
|
||||
//Get protocol message
|
||||
const msg = JSON.parse(event.data);
|
||||
const answer = msg.answer.replace("m=application 9 UDP/TLS/RTP/SAVPF","m=application 9 DTLS/SCTP 5000") + "a=sctpmap:5000 webrtc-datachannel 1024\r\n"
|
||||
console.log("answer",answer);
|
||||
pc.setRemoteDescription(new RTCSessionDescription({
|
||||
type:'answer',
|
||||
sdp: answer
|
||||
}), function () {
|
||||
console.log("JOINED");
|
||||
}, function (err) {
|
||||
console.error("Error joining",err);
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
connect();
|
||||
|
||||
Reference in New Issue
Block a user