Browse Source

- Adding ICE Candidate support in Movim (receive and send)

- Fixing some little issues in the Javascript
pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
15d7145229
  1. 6
      app/assets/js/movim_rpc.js
  2. 1
      app/assets/js/movim_tpl.js
  3. 1
      app/widgets/Explore/Explore.php
  4. 1
      app/widgets/Visio/visio.css
  5. 58
      app/widgets/Visio/webrtc.js
  6. 24
      app/widgets/VisioExt/VisioExt.php
  7. 3
      app/widgets/VisioExt/visioext.js
  8. 37
      lib/JingletoSDP.php
  9. 6
      lib/SDPtoJingle.php
  10. 4
      themes/movim/css/posts.css

6
app/assets/js/movim_rpc.js

@ -104,15 +104,15 @@ function MovimRPC()
if(funcall.func != null) {
var funcs = funcall.func.split('.');
try {
//try {
if(funcs.length == 1)
window[funcs[0]](funcall.params);
else if(funcs.length == 2)
window[funcs[0]][funcs[1]](funcall.params);
}
/*}
catch(err) {
console.log("Error caught: " + err.toString() + " - " +funcall.func);
}
}*/
}
}
}

1
app/assets/js/movim_tpl.js

@ -62,5 +62,6 @@ function movim_fill(params)
function movim_delete(params)
{
target = document.getElementById(params[0]);
if(target)
target.parentNode.removeChild(target);
}

1
app/widgets/Explore/Explore.php

@ -122,6 +122,7 @@ class Explore extends WidgetCommon {
<section class="content">'.prepareString($user->description).'</section>
<footer></footer>
</article>
';
}

1
app/widgets/Visio/visio.css

@ -80,7 +80,6 @@ body {
}
#visio #log {
display: none;
color: white;
position: absolute;
top: 0;

58
app/widgets/Visio/webrtc.js

@ -15,13 +15,6 @@ var sdpConstraints = {'mandatory': {
'OfferToReceiveAudio': true,
'OfferToReceiveVideo': true }};
function onIceCandidate(event) {
Visio.log('onIceCandidate');
//Visio.log(event);
//pc.addIceCandidate(event.candidate, onIceCandidateAdded, onDomError);
}
function onIceConnectionStateChanged(event) {
Visio.log('onIceConnectionStateChanged');
Visio.log(event);
@ -33,7 +26,17 @@ function onSignalingStateChanged(event) {
}
function onIceCandidateAdded(event) {
Visio.log('onIceCandateAdded');
Visio.log('onIceCandidateAdded');
Visio.log(event);
}
function onRemoteIceCandidateAdded(event) {
Visio.log('onRemoteIceCandidateAdded');
Visio.log(event);
}
function onRemoteIceCandidateError(event) {
Visio.log('onRemoteIceCandidateError');
Visio.log(event);
}
@ -75,6 +78,25 @@ function onAnswerCreated(offer) {
sendMessage(offer, true);
}
function onIceCandidate(event) {
Visio.log('onIceCandidate');
console.log(event);
candidate = {};
if(event.candidate != null) {
candidate.sdp = event.candidate.candidate;
candidate.mid = event.candidate.sdpMid;
candidate.line = event.candidate.sdpMLineIndex;
candidate.jid = VISIO_JID;
candidate.ressource = VISIO_RESSOURCE;
var msgString = JSON.stringify(candidate);
Visio.call(['VisioExt_ajaxSendCandidate', msgString]);
}
}
function sendMessage(msg, accept) {
offer = {};
offer.sdp = msg.sdp;
@ -115,7 +137,6 @@ function sendMessage(msg, accept) {
} else {
Visio.log('Send the proposal.');
Visio.log('PROPOSAL ' + msg.sdp);
Visio.call(['VisioExt_ajaxSendProposal', msgString]);
}
}
@ -151,18 +172,18 @@ function onOffer(offer) {
init(false);
if(offer != null) {
/*
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);
}
@ -190,6 +211,19 @@ function onAccept(offer) {
}
}
function onCandidate(message) {
var label = {
'audio' : 0,
'video' : 1
};
var candidate = new RTCIceCandidate({sdpMLineIndex: label[message[1]],
candidate: message[0]});
//console.log(candidate);
pc.addIceCandidate(candidate, onRemoteIceCandidateAdded, onRemoteIceCandidateError);
}
function init(isCaller) {
var configuration = {"iceServers":[{"url": "stun:23.21.150.121:3478"}]};

24
app/widgets/VisioExt/VisioExt.php

@ -53,11 +53,11 @@ class VisioExt extends WidgetBase
function onTransportInfo($jingle) {
$jts = new \JingletoSDP($jingle);
$sdp = $jts->generate();
RPC::call('Popup.call', 'onCandidate', $jts->generate(), $jts->media);
}
function onSessionTerminate($jingle) {
//call webrtc.js terminate()
RPC::call('Popup.call', 'terminate');
}
@ -109,6 +109,26 @@ class VisioExt extends WidgetBase
->request();
}
function ajaxSendCandidate($candidate) {
$p = json_decode($candidate);
$sd = Sessionx::start();
$sdp =
'm='.$p->mid."\n".
$p->sdp;
$stj = new SDPtoJingle(
$sdp,
$this->user->getLogin().'/'.$sd->ressource,
$p->jid.'/'.$p->ressource,
'transport-info');
$r = new moxl\JingleSessionInitiate();
$r->setTo($p->jid.'/'.$p->ressource)
->setOffer($stj->generate())
->request();
}
function build() {
}

3
app/widgets/VisioExt/visioext.js

@ -39,12 +39,13 @@ var Popup = {
},
open: function(jid) {
console.log('Opening the Popup');
console.log('Popup already opened');
var url = BASE_URI + PAGE_KEY_URI + "visio&f="+jid
this.setJid(jid);
if( !this.win || this.win.closed ) {
console.log('Opening the Popup');
this.win = window.open( url, "win", "height=480,width=640,directories=0,titlebar=0,toolbar=0,location=0,status=0, personalbar=0,menubar=0,resizable=0" );
} else this.win.focus();
},

37
lib/JingletoSDP.php

@ -4,6 +4,11 @@ class JingletoSDP {
private $sdp = '';
private $jingle;
private $action;
// Only used for ICE Candidate (Jingle transport-info)
public $media;
private $values = array(
'session_id' => 1,
'session_version' => 0,
@ -14,6 +19,8 @@ class JingletoSDP {
function __construct($jingle) {
$this->jingle = $jingle;
$this->action = (string)$this->jingle->attributes()->action;
}
function getSessionId(){
@ -79,6 +86,7 @@ class JingletoSDP {
if(isset($content->transport->attributes()->pwd))
$sdp_media .= "\na=ice-pwd:".$content->transport->attributes()->pwd;
if(isset($content->description)) {
foreach($content->description->children() as $payload) {
switch($payload->getName()) {
case 'rtp-hdrext':
@ -184,13 +192,16 @@ class JingletoSDP {
}
// TODO sendrecv ?
}
}
if(isset($content->description->attributes()->ptime)) {
if(isset($content->description)
&& isset($content->description->attributes()->ptime)) {
$sdp_media .=
"\na=ptime:".$content->description->attributes()->ptime;
}
if(isset($content->description->attributes()->maxptime)) {
if(isset($content->description)
&& isset($content->description->attributes()->maxptime)) {
$sdp_media .=
"\na=maxptime:".$content->description->attributes()->maxptime;
}
@ -260,8 +271,20 @@ class JingletoSDP {
}
}
if($media_header_first_port == null)
$media_header_first_port = 1;
if($media_header_last_ip == null)
$media_header_last_ip = '0.0.0.0';
if(isset($content->description))
$this->media = (string)$content->description->attributes()->media;
else
$this->media = (string)$content->attributes()->name;
if($this->action != 'transport-info') {
$sdp_media_header =
"\nm=".$content->description->attributes()->media.
"\nm=".$this->media.
' '.$media_header_first_port.' ';
if(isset($content->transport->sctpmap)) {
@ -270,7 +293,7 @@ class JingletoSDP {
|| isset($content->transport->fingerprint)) {
$sdp_media_header .= 'RTP/SAVPF';
} else {
$sdp_media_header .= 'RTP/AVPF';
$sdp_media_header .= 'RTP/AVP';
}
@ -280,12 +303,18 @@ class JingletoSDP {
$sdp_media_header.
"\nc=IN IP4 ".$media_header_last_ip.
$sdp_media;
} else {
$sdp_medias = $sdp_media;
}
}
if($this->action != 'transport-info') {
$this->sdp .= $sdp_version;
$this->sdp .= "\n".$sdp_origin;
$this->sdp .= "\n".$sdp_session_name;
$this->sdp .= "\n".$sdp_timing;
}
$this->sdp .= $sdp_medias;
return $this->sdp;

6
lib/SDPtoJingle.php

@ -7,6 +7,8 @@ class SDPtoJingle {
private $content = null;
private $transport = null;
private $action;
// Move the global fingerprint into each medias
private $global_fingerprint = array();
@ -41,6 +43,8 @@ class SDPtoJingle {
$this->jingle->addAttribute('action',$action);
$this->jingle->addAttribute('initiator',$initiator);
$this->jingle->addAttribute('responder',$responder);
$this->action = $action;
}
function getSessionId(){
@ -72,9 +76,11 @@ class SDPtoJingle {
$this->content->addAttribute('name', $matches[1]);
// The description node
if($this->action != 'transport-info') {
$description = $this->content->addChild('description');
$description->addAttribute('xmlns', "urn:xmpp:jingle:apps:rtp:1");
$description->addAttribute('media', $matches[1]);
}
if(!empty($this->global_fingerprint)) {
$fingerprint = $this->transport->addChild('fingerprint', $this->global_fingerprint['fingerprint']);

4
themes/movim/css/posts.css

@ -46,6 +46,10 @@ article footer {
padding-bottom: 1em;
}
article:nth-last-child(-n+2) footer {
border-bottom: none;
}
article footer:after {
content: "";
clear: both;

Loading…
Cancel
Save