Я сделал программу webrtc, которая отлично работает в интрасети, но не работает в Интернете. Я отключил брандмауэр маршрутизатора, теперь не знаю, что не так.
Вот мой код:
<?php
global $db;
if(isset($_REQUEST['room_id'])){
$room_id=$_REQUEST['room_id'];
require_once 'modules/Conferencingrooms/Conferencingroom.php';
$conferencingroom=new Conferencingroom();
$conferencingroom->retrieve($room_id);
$branch_id=$conferencingroom->branch_id;
}
else{
sugar_die('Error! Access is Denind');
}
?>
<script>
if (window.location.protocol != "https:")
window.location.href = "https:" + window.location.href.substring(window.location.protocol.length);
</script>
<video src="" id="localVideo" style="border:1px red dotted">Patient Video</video>
<video src="" id="remoteVideo" style="border:1px red dotted">Doctor Video</video>
<script>
var pc;
var callNo = '<?php echo $room_id;?>'; // 0 indicates callNo not initialised yet
var caller = <?php if($branch_id==$current_user->branch_id) echo 'true';else echo 'false'?>;
if (caller) {
$("#ajaxStatusDiv").show();
}
var video_constraints={
mandatory:{
maxWidth:320,
maxHeight:320,
maxAspectRatio:16/8,
maxFrameRate:500,
}
}
navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia.bind(navigator);;
navigator.getUserMedia({audio: true, video: true}, onUserMediaSuccess, onUserMediaError);
function onUserMediaSuccess(stream) {
document.getElementById('localVideo').src = webkitURL.createObjectURL(stream);
document.getElementById('localVideo').play();
var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
pc = new PeerConnection({iceServers: [ {url:'stun:stun01.sipphone.com'},
{url:'stun:stun.ekiga.net'},
{url:'stun:stun.fwdnet.net'},
{url:'stun:stun.ideasip.com'},
{url:'stun:stun.iptel.org'},
{url:'stun:stun.rixtelecom.se'},
{url:'stun:stun.schlund.de'},
{url:'stun:stun.l.google.com:19302'},
{url:'stun:stun1.l.google.com:19302'},
{url:'stun:stun2.l.google.com:19302'},
{url:'stun:stun3.l.google.com:19302'},
{url:'stun:stun4.l.google.com:19302'},
{url:'stun:stunserver.org'},
{url:'stun:stun.softjoys.com'},
{url:'stun:stun.voiparound.com'},
{url:'stun:stun.voipbuster.com'},
{url:'stun:stun.voipstunt.com'},
{url:'stun:stun.voxgratia.org'},
{url:'stun:stun.xten.com'},
{
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: '[email protected]'
},
{
url: 'turn:192.158.29.39:3478?transport=udp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
},
{
url: 'turn:192.158.29.39:3478?transport=tcp',
credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
username: '28224511:1379330808'
}]});
pc.preventSSLAutoAllowed = false;
pc.autoReDialOnFailure = true;
pc.setDefaultEventsForMediaElement = false;
pc.addStream(stream);
pc.onicecandidate = function (evt) {
console.log('On Ice Candidate');
console.log(evt.candidate);
if (!evt.candidate) {
console.log('inner');
pc.onicecandidate = null;
if (pc.localDescription) postLocalData();
}
};
pc.onaddstream = function(evt) {
document.getElementById('remoteVideo').src = webkitURL.createObjectURL(evt.stream);
document.getElementById('remoteVideo').play();
};
if (caller){
console.log('Create Offer called');
pc.createOffer(onDescCreated, onCreateOfferError);
}
else {
getRemoteData();
}
window.onbeforeunload = function() {
/*
stream.stop();
if (caller && callNo > 0) navigator.sendBeacon('deleteCall.php', callNo);
*/
};
}
function onUserMediaError(err) {
if(err.name=='DevicesNotFoundError'){
alert('Media device is not connected');}
console.log('User media error: ' + err.name);
}
function onCreateOfferError(err) {
logError('Error creating offer: ' + err.name);
}
function onDescCreated(desc) {
pc.setLocalDescription(desc, onLocalDescSuccess, onLocalDescError);
}
function onLocalDescSuccess() {
if(caller)
console.log('offer create success');
if (pc.iceGatheringState == 'complete') {
if(caller)
{
console.log('Send for store sdp for caller');
}
else{
console.log('Send for store sdp for callee');
}
postLocalData();
}
}
function onLocalDescError(err) {
logError("Local description could not be created: " + err.name);
}
function postLocalData() {
console.log('Storing local sdp');
var xhr = new XMLHttpRequest();
var sdp=pc.localDescription.sdp;
xhr.open('POST', 'index.php?module=Conferencingrooms&action=AjaxCalls&storeSdp=true&caller='+caller);
xhr.onload = (caller ? getRemoteData : waitForConnection);
xhr.send(callNo + '~' + sdp);
}
function getRemoteData() {
console.log("Checking db for remote sdp");
var xhr = new XMLHttpRequest();
xhr.open('GET', 'index.php?module=Conferencingrooms&action=AjaxCalls&fetchSdp=true&caller='+caller+'&callNo=' + callNo);
xhr.onload = processRemoteData;
xhr.send();
}
function processRemoteData() {
if (this.response) {
var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription;
var sdp = new SessionDescription();
sdp.type = (caller ? 'answer' : 'offer');
sdp.sdp = this.response;
console.log('Processing remote sdp: ' + sdp);
pc.setRemoteDescription(sdp, onRemoteDescSuccess, onRemoteDescError);
}
else
setTimeout(getRemoteData, 1000);
}
function onRemoteDescSuccess() {
console.log("Remote sdp successfully set");
if (caller) {
waitForConnection();
}
else
pc.createAnswer(onDescCreated, onCreateAnswerError);
}
function onRemoteDescError(err) {
logError("Remote description could not be set: " + err.name);
}
function onCreateAnswerError(err) {
logError("Error creating answer: " + err.name);
}
function waitForConnection() {
console.log('Waiting');
if (pc.iceConnectionState == 'connected' || pc.iceConnectionState == 'completed') {
console.log('Waitingdsadsd');
logError('Connection complete');
caller = null;
document.getElementById('remoteVideo').ondblclick = function() {
this.requestFullscreen = this.mozRequestFullScreen || this.webkitRequestFullscreen;
this.requestFullscreen();
}
}
else
setTimeout(waitForConnection, 1000);
}
function logError(msg) {
console.log(msg);
if (caller && callNo > 0) navigator.sendBeacon('deleteCall.php', callNo);
}
</script>
Это версия сигнализации php, в которой комната создается на основе идентификатора комнаты в URL
Задача ещё не решена.
Других решений пока нет …