Browse Source

- Merge with nodpounod

pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
3f77cdd34b
  1. 2
      app/widgets/Visio/visio.js
  2. 8
      app/widgets/Visio/visio.tpl
  3. 7
      app/widgets/Visio/webrtc.js
  4. 22
      app/widgets/VisioExt/VisioExt.php
  5. 8
      app/widgets/VisioExt/visioext.js
  6. 16
      lib/JingletoSDP.php
  7. 27
      lib/SDPtoJingle.php

2
app/widgets/Visio/visio.js

@ -73,5 +73,7 @@ var Visio = {
movim_add_onload(function()
{
document.getElementById("call").onclick = function() { init(true); };
document.getElementById("hang-up").onclick = function() { terminate(); };
document.getElementById("toggle-screen").onclick = function() { Visio.fullScreen(); };
});

8
app/widgets/Visio/visio.tpl

@ -14,10 +14,10 @@
<span class="name">{$name}</span>
</div>
<div class="menu">
<a class="button color green merged left icon call"
onclick="init(true);">Call</a>
<a class="button color red merged right icon hang-up"
onclick="terminate();">Hang Up</a>
<a id="call" class="button color green merged left icon call">
Call</a>
<a id="hang-up" class="button color red merged right icon hang-up">
Hang Up</a>
<a id="toggle-screen" class="button icon expand color blue alone"></a>
</div>

7
app/widgets/Visio/webrtc.js

@ -211,4 +211,11 @@ function init(isCaller) {
function terminate() {
pc.close();
Visio.call(['VisioExt_ajaxSendSessionTerminate']);
// Get a reference to the video element on the page.
var vid = document.getElementById('local-video');
var avatar = document.getElementById('avatar');
vid.className = vid.className.replace('tiny', '');
avatar.className = avatar.className.replace('tiny', '');
}

22
app/widgets/VisioExt/VisioExt.php

@ -43,8 +43,12 @@ class VisioExt extends WidgetBase
function onSessionAccept($jingle) {
$jts = new \JingletoSDP($jingle);
$sdp = $jts->generate();
$sid = $jts->getSessionId();
RPC::call('Popup.call', 'onAccept', $sdp);
RPC::call('Popup.call', 'onAccept', $sdp);
$s = Session::start('movim');
$s->set('jingleSid', $sid);
}
function onTransportInfo($jingle) {
@ -53,7 +57,7 @@ class VisioExt extends WidgetBase
}
function onSessionTerminate($jingle) {
//do something when you recieve the session-terminate from jingle
}
function ajaxSendProposal($proposal) {
@ -71,6 +75,10 @@ class VisioExt extends WidgetBase
$r->setTo($p->jid.'/'.$p->ressource)
->setOffer($stj->generate())
->request();
$sid = $sjt->getSessionId();
$s = Session::start('movim');
$s->set('jingleSid', $sid);
}
function ajaxSendAcceptance($proposal) {
@ -90,6 +98,16 @@ class VisioExt extends WidgetBase
->request();
}
function ajaxSendSessionTerminate() {
$s = Session::start('movim');
$jingleSid = $s->get("jingleSid");
$r = new moxl\JingleSessionTerminate();
$r->setTo($p->jid.'/'.$p->ressource)
->setJingleSid($jingleSid)
->request();
}
function build() {
}

8
app/widgets/VisioExt/visioext.js

@ -66,6 +66,10 @@ var Popup = {
this.win[func](params);
},
hangUp: function(args) {
console.log('Your friend just hung up');
},
call: function(args) {
if( this.win && !this.win.closed ) {
// The popup is open so call it
@ -78,9 +82,5 @@ var Popup = {
console.log('We wait a little');
setTimeout(function() {Popup.send(args); }, 1000);
}
},
hungup: function(args) {
console.log('Your friend just hung up');
}
}

16
lib/JingletoSDP.php

@ -15,12 +15,22 @@ class JingletoSDP {
function __construct($jingle) {
$this->jingle = $jingle;
}
function getSessionId(){
$s = Session::start('movim');
if($sid = $s->get('jingleSid')){
return $sid;
}
else{
$sessid = $this->jingle->attributes()->sid;
return substr(base_convert($sessid, 30, 10), 0, 6);
}
}
function generate() {
$username = substr($this->jingle->attributes()->initiator, 0, strpos("@", $this->jingle->attributes()->initiator));//sinon le - marche pas
$username = $username? $username : "-";
$sessid = $this->jingle->attributes()->sid;
$this->values['session_id'] = substr(base_convert($sessid, 30, 10), 0, 6);
$this->values['session_id'] = $this->getSessionId();
$sdp_version =
'v=0';

27
lib/SDPtoJingle.php

@ -1,6 +1,7 @@
<?php
class SDPtoJingle {
private $sdp;
private $arr;
private $jingle;
private $content = null;
@ -11,6 +12,7 @@ class SDPtoJingle {
private $regex = array(
'candidate' => "/^a=candidate:(\w{1,32}) (\d{1,5}) (udp|tcp) (\d{1,10}) ([a-zA-Z0-9:\.]{1,45}) (\d{1,5}) (typ) (host|srflx|prflx|relay)( (raddr) ([a-zA-Z0-9:\.]{1,45}) (rport) (\d{1,5}))?( (generation) (\d) (network) (\d) (id) ([a-zA-Z0-9]{1,45}))?/i", //à partir de generation les attr sont spécifiques à XMPP..autant l'enlever de la REGEX et les traiter à part? En théorie ils peuvent être dans n'importe quel ordre.
'sess_id' => "/^o=(\S+) (\d+)/i",
'rtpmap' => "/^a=rtpmap:(\d+) (([^\s\/]+)(\/(\d+)(\/([^\s\/]+))?)?)?/i",
'fmtp' => "/^a=fmtp:(\d+) (.+)/i",
'rtcp_fb' => "/^a=rtcp-fb:(\S+) (\S+)( (\S+))?/i",
@ -30,24 +32,37 @@ class SDPtoJingle {
'bandwidth' => "/^b=(\w+):(\d+)/i",
'media' => "/^m=(audio|video|application|data)/i"
);
function __construct($sdp, $initiator, $responder, $action) {
$this->sdp = $sdp;
$this->arr = explode("\n", $this->sdp);
$this->jingle = new SimpleXMLElement('<jingle></jingle>');
$this->jingle->addAttribute('xmlns', 'urn:xmpp:jingle:1');
$this->jingle->addAttribute('action',$action);
$this->jingle->addAttribute('initiator',$initiator);
$this->jingle->addAttribute('responder',$responder);
$this->jingle->addAttribute('sid', generateKey(10));
}
function getSessionId(){
$s = Session::start('movim');
if($sid = $s->get('jingleSid')){
return $sid;
}
else{
$o = $this->arr[1];
$sid = explode(" ", $o);
return substr(base_convert($sid[1], 30, 10), 0, 6);
}
}
function generate() {
$arr = explode("\n", $this->sdp);
foreach($arr as $l) {
foreach($this->arr as $l) {
foreach($this->regex as $key => $r) {
if(preg_match($r, $l, $matches)) {
if(preg_match($r, $l, $matches)) {
switch($key) {
case 'sess_id':
$this->jingle->addAttribute('sid', $this->getSessionId());
break;
case 'media':
$this->content = $this->jingle->addChild('content');
$this->transport = $this->content->addChild('transport');

Loading…
Cancel
Save