| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- document.addEventListener('UniAppJSBridgeReady', function() {
- // var lats = getQueryVariable('lat') * 1;
- const peer=null;
- const localStream=null;
- /**
- * 初始化
- *
- */
- function initRtc() {
- //returngeocode('initRtc',1);
-
- setTimeout(() => {
- startCapture({ video:true });
- }, 1000)
-
- return;
- var peer = new RTCPeerConnection(
- {
- iceServers:[
- {
- urls:'stun:stun.l.google.com:19302',
- }
- ]
- }
- );
-
- peer.onicecandidate = function (event) {
- returngeocode('','onicecandidate');
- if (event.candidate){
- returngeocode('','candidate');
- }
- }
- returngeocode(JSON.stringify(peer),2);
- const constraints = { video: true, audio: true }
- var Stream = navigator.mediaDevices.getUserMedia(constraints);
- if(Stream){
- returngeocode(Stream,3);
- }
- else{
- returngeocode(Stream,333);
- }
- let video = document.getElementById("my_video");
- video.srcObject = Stream;
- video.setAttribute('autoplay',true);
- returngeocode(video,4);
- peer.addStream(Stream)
- returngeocode('addStream',5);
- const offer = peer.createOffer({
- offerToReceiveAudio:1,
- offerToReceiveVideo:1
- });
- returngeocode(offer,6);
- //发送offer
- }
- async function startCapture(displayMediaOptions) {
- let stream = null;
- try {
- stream = await navigator.mediaDevices.getUserMedia(displayMediaOptions);
- video = document.createElement("video");
- video.srcObject = stream;
- video.setAttribute('autoplay', true); /* THIS */
- document.body.appendChild(video);
- document.getElementById('note').innerHTML('startCapture');
- } catch(err) {
- console.error(err);
- }
- }
- function returngeocode(data,type){
- uni.postMessage({
- data: {
- data:data,
- type:type
- }
- });
- }
- window.onload=initRtc;
- });
|