Browse Source

- Fix a warning in Chat

- Wait a little for the SDP creation in Chrome
pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
15d1e09838
  1. 5
      app/widgets/Chat/Chat.php
  2. 107
      app/widgets/Visio/webrtc.js
  3. 18
      lib/JingletoSDP.php
  4. 5
      lib/SDPtoJingle.php

5
app/widgets/Chat/Chat.php

@ -495,7 +495,10 @@ class Chat extends WidgetBase
7 => 'blue');
$s = base_convert($jid, 32, 8);
return $colors[$s[7]];
if(isset($s[7]))
return $colors[$s[7]];
else
return 'orange';
}
// Prepare Chat

107
app/widgets/Visio/webrtc.js

@ -16,7 +16,9 @@ var sdpConstraints = {'mandatory': {
function onIceCandidate(event) {
Visio.log('onIceCandidate');
Visio.log(event);
//Visio.log(event);
//pc.addIceCandidate(event.candidate, onIceCandidateAdded, onDomError);
}
function onIceConnectionStateChanged(event) {
@ -29,6 +31,16 @@ function onSignalingStateChanged(event) {
Visio.log(event);
}
function onIceCandidateAdded(event) {
Visio.log('onIceCandateAdded');
Visio.log(event);
}
function onSignalingStateChanged(event) {
Visio.log('onSignalingStateChanged');
Visio.log(event);
}
function onRemoteStreamAdded(event) {
var vid = document.getElementById('remote-video');
@ -44,20 +56,16 @@ function onRemoteStreamAdded(event) {
}
function onError(err) {
window.alert(err.message);
console.log(err);
}
function onOfferCreated(offer) {
//Visio.log(offer);
pc.setLocalDescription(offer,onSetSessionDescriptionSuccess, onSetSessionDescriptionError);
sendMessage(offer);
}
function onAnswerCreated(offer) {
//Visio.log(offer);
pc.setLocalDescription(offer,onSetSessionDescriptionSuccess, onSetSessionDescriptionError);
sendMessage(offer, true);
@ -66,19 +74,45 @@ function onAnswerCreated(offer) {
function sendMessage(msg, accept) {
offer = {};
offer.sdp = msg.sdp;
offer.jid = VISIO_JID;
offer.ressource = VISIO_RESSOURCE;
var msgString = JSON.stringify(offer);
if(accept) {
Visio.log('Send the acceptance.');
Visio.log('ACCEPTANCE ' + msg.sdp);
Visio.call(['VisioExt_ajaxSendAcceptance', msgString]);
if(webrtcDetectedBrowser == 'chrome') {
setTimeout(function() {
if(!accept)
offer.sdp = pc.localDescription.sdp;
var msgString = JSON.stringify(offer);
if(accept) {
Visio.log('Send the acceptance.');
//Visio.log('ACCEPTANCE ' + msg.sdp);
Visio.call(['VisioExt_ajaxSendAcceptance', msgString]);
} else {
Visio.log('Send the proposal.');
//Visio.log('PROPOSAL ' + msg.sdp);
Visio.call(['VisioExt_ajaxSendProposal', msgString]);
}
}, 1000);
} else {
Visio.log('Send the proposal.');
Visio.log('PROPOSAL ' + msg.sdp);
Visio.call(['VisioExt_ajaxSendProposal', msgString]);
var msgString = JSON.stringify(offer);
console.log(offer);
if(accept) {
Visio.log('Send the acceptance.');
//Visio.log('ACCEPTANCE ' + msg.sdp);
Visio.call(['VisioExt_ajaxSendAcceptance', msgString]);
} else {
Visio.log('Send the proposal.');
//Visio.log('PROPOSAL ' + msg.sdp);
Visio.call(['VisioExt_ajaxSendProposal', msgString]);
}
}
}
@ -95,22 +129,33 @@ function onSetRemoteSessionDescriptionSuccess() {
}
function onSetRemoteSessionDescriptionError(error) {
Visio.log('Failed to set remote session description: ' + error.message);
console.log('gnap');
console.log(error);
//Visio.log('Failed to set remote session description: ' + error.message);
}
function onOffer(offer) {
offer = offer[0];
Visio.log('Offer received.');
Visio.log('OFFER ' + offer);
//Visio.log('OFFER ' + offer);
console.log(offer);
if(!pc)
init(false);
if(offer != null) {
var desc = new RTCSessionDescription();
desc.sdp = offer;
desc.type = 'offer';
var message = {};
message.sdp = offer;
message.type = 'offer';
console.log(message);
var desc = new RTCSessionDescription(message);
console.log(desc);
//var desc = new RTCSessionDescription();
//desc.sdp = offer;
//desc.type = 'offer';
pc.setRemoteDescription(desc,
onSetRemoteSessionDescriptionSuccess, onSetRemoteSessionDescriptionError);
@ -121,12 +166,18 @@ function onAccept(offer) {
offer = offer[0];
Visio.log('Accept received.');
Visio.log('ACCEPT ' + offer);
Visio.log('ACCEPT ' + offer);
if(offer != null) {
var desc = new RTCSessionDescription();
desc.sdp = offer;
desc.type = 'answer';
//Visio.log('GN0P');
var message = {};
message.sdp = offer;
message.type = 'anwser';
console.log(message);
var desc = new RTCSessionDescription(message);
console.log(desc);
//desc.sdp = offer;
//desc.type = 'answer';
pc.setRemoteDescription(desc,
onSetRemoteSessionDescriptionSuccess, onSetRemoteSessionDescriptionError);
@ -149,7 +200,7 @@ function init(isCaller) {
WebRTC is not supported by this browser.');
return;
}
if(getUserMedia) {
if (getUserMedia) {
getUserMedia = getUserMedia.bind(navigator);
@ -184,8 +235,6 @@ function init(isCaller) {
pc.addStream(localMediaStream);
channel = pc.createDataChannel("visio");
console.log(pc);
if(isCaller)
pc.createOffer(onOfferCreated, onError);
else

18
lib/JingletoSDP.php

@ -28,8 +28,12 @@ class JingletoSDP {
}
function generate() {
$username = substr($this->jingle->attributes()->initiator, 0, strpos("@", $this->jingle->attributes()->initiator));//sinon le - marche pas
$username = $username? $username : "-";
if($this->jingle->attributes()->initiator) {
$username = explode('@', (string)$this->jingle->attributes()->initiator);
$username = $username[0];
} else
$username = '-';
$this->values['session_id'] = $this->getSessionId();
$sdp_version =
@ -55,10 +59,10 @@ class JingletoSDP {
foreach($this->jingle->children() as $content) {
$media_header_ids = array();
$media_header_first_port = null;
$media_header_last_ip = null;
$sdp_media =
"\nc=IN IP4 0.0.0.0";
$sdp_media = '';
/*
if(isset($content->description->crypto)
|| isset($content->transport->fingerprint)) {
$sdp_media .=
@ -67,6 +71,7 @@ class JingletoSDP {
$sdp_media .=
"\na=rtcp:1 IN IP4 0.0.0.0";
}
*/
if(isset($content->transport->attributes()->ufrag))
$sdp_media .= "\na=ice-ufrag:".$content->transport->attributes()->ufrag;
@ -248,6 +253,8 @@ class JingletoSDP {
if($media_header_first_port == null)
$media_header_first_port = $payload->attributes()->port;
$media_header_last_ip = $payload->attributes()->ip;
break;
}
@ -271,6 +278,7 @@ class JingletoSDP {
$sdp_medias .=
$sdp_media_header.
"\nc=IN IP4 ".$media_header_last_ip.
$sdp_media;
}

5
lib/SDPtoJingle.php

@ -272,9 +272,8 @@ class SDPtoJingle {
$candidate->addAttribute('component' , $matches[2]);
$candidate->addAttribute('foundation', $matches[1]);
//if(isset($matches[16]))
$candidate->addAttribute('generation', $generation); //|| JSJAC_JINGLE_GENERATION;
//$candidate->addAttribute('id' , generateKey(10)); //$self.util_generate_id();
$candidate->addAttribute('generation', $generation);
$candidate->addAttribute('id' , $id);
$candidate->addAttribute('ip' , $matches[5]);
$candidate->addAttribute('network' , $network);

Loading…
Cancel
Save