Browse Source

- Fix lot of little issues

- Start implementing OpenPGP support
- Add a first WebRTC test in tests folder
pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
c6c8de6b4f
  1. 6
      app/models/contact/Contact.php
  2. 3
      app/models/contact/ContactDAO.php
  3. 19
      app/models/presence/Presence.php
  4. 12
      app/models/presence/PresenceDAO.php
  5. 2
      app/models/rosterlink/RosterLink.php
  6. 61
      app/widgets/Chat/Chat.php
  7. 6
      app/widgets/Chat/_chat_contact.tpl
  8. 12
      app/widgets/Chat/chat.js
  9. 4
      app/widgets/Roster/Roster.php
  10. 17
      tests/webrtc/index.html
  11. 95
      tests/webrtc/script.js
  12. 1
      themes/movim/page.tpl

6
app/models/contact/Contact.php

@ -309,6 +309,7 @@ class RosterContact extends Contact {
protected $delay;
protected $chaton;
protected $last;
protected $publickey;
protected $rosterask;
protected $node;
protected $ver;
@ -340,7 +341,9 @@ class RosterContact extends Contact {
'delay' :
{'type':'date'},
'last' :
{'type':'int', 'size':11 }
{'type':'int', 'size':11 },
'publickey' :
{'type':'text'}
}";
}
@ -351,5 +354,6 @@ class RosterContact extends Contact {
$this->status = $p->status;
$this->delay = $p->delay;
$this->last = $p->last;
$this->publickey = $p->publickey;
}
}

3
app/models/contact/ContactDAO.php

@ -349,14 +349,13 @@ class ContactDAO extends ModlSQL {
return $this->run('RosterContact');
}
// limit 1
function getRosterChat() {
$this->_sql = '
select * from rosterlink
left outer join (
select * from presence
order by presence.priority desc
limit 1
) as presence
on rosterlink.jid = presence.jid
left outer join contact

19
app/models/presence/Presence.php

@ -23,6 +23,9 @@ class Presence extends ModlModel {
// Last Activity - XEP 0256
protected $last;
// Current Jabber OpenPGP Usage - XEP-0027
protected $publickey;
public function __construct() {
$this->_struct = '
@ -48,7 +51,9 @@ class Presence extends ModlModel {
"delay" :
{"type":"date"},
"last" :
{"type":"int", "size":11 }
{"type":"int", "size":11 },
"publickey" :
{"type":"text"}
}';
parent::__construct();
@ -98,6 +103,18 @@ class Presence extends ModlModel {
} else {
$this->value = 1;
}
// Specific XEP
if($stanza->x) {
foreach($stanza->children() as $name => $c) {
$ns = $c->getNamespaces(true);
switch($ns['']) {
case 'jabber:x:signed' :
$this->publickey = (string)$c;
break;
}
}
}
if($stanza->delay) {
$this->delay =

12
app/models/presence/PresenceDAO.php

@ -22,7 +22,8 @@ class PresenceDAO extends ModlSQL {
node = :node,
ver = :ver,
delay = :delay,
last = :last
last = :last,
publickey = :publickey
where id = :id';
$this->prepare(
@ -35,6 +36,7 @@ class PresenceDAO extends ModlSQL {
'ver' => $presence->ver,
'delay' => $presence->delay,
'last' => $presence->last,
'publickey' => $presence->publickey,
'id' => $id
)
);
@ -44,7 +46,7 @@ class PresenceDAO extends ModlSQL {
if(!$this->_effective) {
$this->_sql = '
insert into presence
(id,session, jid, ressource, value, priority, status, node, ver, delay,last)
(id,session, jid, ressource, value, priority, status, node, ver, delay,last,publickey)
values(
:id,
:session,
@ -56,7 +58,8 @@ class PresenceDAO extends ModlSQL {
:node,
:ver,
:delay,
:last)';
:last,
:publickey)';
$this->prepare(
'Presence',
@ -71,7 +74,8 @@ class PresenceDAO extends ModlSQL {
'node' => $presence->node,
'ver' => $presence->ver,
'delay' => $presence->delay,
'last' => $presence->last
'last' => $presence->last,
'publickey' => $presence->publickey
)
);

2
app/models/rosterlink/RosterLink.php

@ -15,6 +15,8 @@ class RosterLink extends ModlModel {
public $groupname;
public $chaton;
public $publickey;
public function __construct() {
$this->_struct = '

61
app/widgets/Chat/Chat.php

@ -218,6 +218,18 @@ class Chat extends WidgetBase
$evt = new Event();
$evt->runEvent('openchat');
}
/**
* Send an encrypted message
*
* @param string $to
* @param string $message
* @return void
*/
function ajaxSendEncryptedMessage($to, $message, $muc = false, $ressource = false)
{
$this->ajaxSendMessage($to, $message, $muc, $ressource, true);
}
/**
* Send a message
@ -226,7 +238,7 @@ class Chat extends WidgetBase
* @param string $message
* @return void
*/
function ajaxSendMessage($to, $message, $muc = false, $ressource = false)
function ajaxSendMessage($to, $message, $muc = false, $ressource = false, $encrypted = false)
{
$m = new \modl\Message();
@ -262,6 +274,7 @@ class Chat extends WidgetBase
// We decode URL codes to send the correct message to the XMPP server
$m = new \moxl\MessagePublish();
$m->setTo($to)
->setEncrypted($encrypted)
->setContent(htmlspecialchars(rawurldecode($message)));
if($muc)
$m->setMuc();
@ -390,9 +403,15 @@ class Chat extends WidgetBase
$html = '';
// Another filter to fix the database request
$jid = '';
if(isset($contacts)) {
foreach($contacts as $contact) {
$html .= trim($this->prepareChat($contact));
if($jid != $contact->jid) {
$html .= trim($this->prepareChat($contact));
$jid = $contact->jid;
}
}
}
@ -517,9 +536,34 @@ class Chat extends WidgetBase
if($contact->chaton == 2) {
$tabstyle = ' style="display: none;" ';
$panelstyle = ' style="display: block;" ';
}
}
$chatview = $this->tpl();
/*if($contact->publickey) {
$chatview->assign('publickey', $contact->publickey);
$chatview->assign(
'send',
$this->genCallAjax(
'ajaxSendEncryptedMessage',
"'".$contact->jid."'",
"sendEncryptedMessage(this, '".$contact->jid."')",
"false",
"'".$contact->ressource."'"
)
);
} else {*/
$chatview->assign(
'send',
$this->genCallAjax(
'ajaxSendMessage',
"'".$contact->jid."'",
"sendMessage(this, '".$contact->jid."')",
"false",
"'".$contact->ressource."'"
)
);
//}
$chatview->assign('contact', $contact);
$chatview->assign('tabstyle', $tabstyle);
@ -533,16 +577,7 @@ class Chat extends WidgetBase
'hidetalk',
$this->genCallAjax("ajaxHideTalk", "'".$contact->jid."'")
);
$chatview->assign(
'send',
$this->genCallAjax(
'ajaxSendMessage',
"'".$contact->jid."'",
"sendMessage(this, '".$contact->jid."')",
"false",
"'".$contact->ressource."'"
)
);
$chatview->assign(
'composing',
$this->genCallAjax(

6
app/widgets/Chat/_chat_contact.tpl

@ -7,6 +7,9 @@
<span class="chatbutton arrow" onclick="{$hidetalk} hideTalk(this)"></span>
<a class="name" href="{$c->route('friend',$contact->jid)}">
{$contact->getTrueName()}
{if="$publickey"}
- Encrypted
{/if}
</a>
</div>
<div class="messages" id="messages{$contact->jid}">
@ -19,6 +22,9 @@
<textarea
rows="1"
id="textarea{$contact->jid}"
{if="$publickey"}
data-publickey="{$publickey}"
{/if}
onkeypress="
if(event.keyCode == 13) {
state = 0;

12
app/widgets/Chat/chat.js

@ -90,7 +90,6 @@ function sendMessage(n, jid)
var text = n.value;
n.value = "";
n.focus();
// We escape the text to prevent XML errors
@ -98,6 +97,17 @@ function sendMessage(n, jid)
}
function sendEncryptedMessage(n, jid)
{
var text = JSON.parse(sjcl.encrypt(n.dataset.publickey,n.value)).iv;
n.value = "";
n.focus();
// We escape the text to prevent XML errors
return encodeURIComponent(text);
}
function disableSound(){
chatSoundNotif.volume = 0;
}

4
app/widgets/Roster/Roster.php

@ -298,6 +298,10 @@ class Roster extends WidgetBase
$offline = Cache::c('offlineshown');
if($param == 'offlineshown') {
if($bool)
Notification::appendNotification(t('Show disconnected contacts'), 'success');
else
Notification::appendNotification(t('Hide disconnected contacts'), 'success');
RPC::call('showRoster', $bool);
} else
RPC::call('rosterToggleGroup', $param, $bool, $offline);

17
tests/webrtc/index.html

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>WebRTC Example</title>
<!-- Simple Client JS -->
<script src="script.js" type="text/javascript"></script>
</head>
<body>
test
<script type="text/javascript">init();</script>
</body>
</html>

95
tests/webrtc/script.js

@ -0,0 +1,95 @@
var movim_getUserMedia = ( navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia ||
navigator.getUserMedia );
var movim_RTCPeerConnection = ( window.webkitRTCPeerConnection ||
window.mozRTCPeerConnection ||
window.RTCPeerConnection );
var WEBRTC_SESSION_DESCRIPTION = ( window.mozRTCSessionDescription ||
window.RTCSessionDescription );
var WEBRTC_ICE_CANDIDATE = ( window.mozRTCIceCandidate ||
window.RTCIceCandidate );
function onIceCandidate(event) {
/*if (event.candidate) {
sendMessage({type: 'candidate',
label: event.candidate.sdpMLineIndex,
id: event.candidate.sdpMid,
candidate: event.candidate.candidate});
noteIceCandidate("Local", iceCandidateType(event.candidate.candidate));
} else {
console.log('End of candidates.');
}*/
console.log('onIceCandidate');
console.log(event);
}
function onIceConnectionStateChanged(event) {
console.log('onIceConnectionStateChanged');
console.log(event);
}
function onSignalingStateChanged(event) {
console.log('onSignalingStateChanged');
console.log(event);
}
function init() {
var configuration = {"iceServers":[{"url": "stun:stun.l.google.com:19302"}]};
try {
pc = new movim_RTCPeerConnection(configuration);
pc.onicecandidate = onIceCandidate;
pc.onsignalingstatechange = onSignalingStateChanged;
pc.oniceconnectionstatechange = onIceConnectionStateChanged;
} catch (e) {
console.log('Failed to create PeerConnection, exception: ' + e.message);
alert('Cannot create RTCPeerConnection object; \
WebRTC is not supported by this browser.');
return;
}
if(movim_getUserMedia) {
if (movim_getUserMedia) {
movim_getUserMedia = movim_getUserMedia.bind(navigator);
}
// Request the camera.
movim_getUserMedia(
// Constraints
{
video: true
},
// Success Callback
function(localMediaStream) {
// Get a reference to the video element on the page.
//var vid = document.getElementById('camera-stream');
// Create an object URL for the video stream and use this
// to set the video source.
//vid.src = window.URL.createObjectURL(localMediaStream);
pc.addStream(localMediaStream);
},
// Error Callback
function(err) {
// Log the error to the console.
console.log('The following error occurred when trying to use getUserMedia: ' + err);
}
);
} else {
alert('Sorry, your browser does not support getUserMedia');
}
//channel = pc.createDataChannel("visio");
console.log(pc);
//console.log(channel);
}

1
themes/movim/page.tpl

@ -8,6 +8,7 @@
<link rel="shortcut icon" href="<?php $this->link_file('img/favicon.ico');?>" />
<link rel="stylesheet" href="<?php echo BASE_URI; ?>app/assets/js/leaflet.css" />
<script src="<?php echo BASE_URI; ?>app/assets/js/leaflet.js"></script>
<script src="<?php echo BASE_URI; ?>app/assets/js/sjcl.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1";>

Loading…
Cancel
Save