Browse Source

Huge cleanup and refactor of the MovimWebsocket class, behaviour and disconnection handling

pull/238/head
Timothée Jaussoin 9 years ago
parent
commit
b88d233100
  1. 32
      app/assets/js/movim_websocket.js
  2. 3
      app/controllers/AccountController.php
  3. 2
      app/controllers/LoginController.php
  4. 2
      app/models/sessionx/SessionxDAO.php
  5. 1
      app/views/login.tpl
  6. 11
      app/views/page.tpl
  7. 5
      app/widgets/AccountNext/AccountNext.php
  8. 3
      app/widgets/AccountNext/_accountnext_registered.tpl
  9. 6
      app/widgets/Login/_login_error.tpl
  10. 3
      app/widgets/Login/locales.ini
  11. 3
      app/widgets/Login/login.js
  12. 8
      app/widgets/Login/login.tpl
  13. 1
      locales/locales.ini
  14. 9
      themes/material/css/style.css

32
app/assets/js/movim_websocket.js

@ -25,10 +25,12 @@ var MovimWebsocket = {
connection: null,
attached: new Array(),
registered: new Array(),
unregistered: false,
attempts: 1,
launchAttached : function() {
// We hide the Websocket error
MovimUtils.hideElement(document.getElementById('error_websocket'));
for(var i = 0; i < MovimWebsocket.attached.length; i++) {
MovimWebsocket.attached[i]();
}
@ -80,20 +82,16 @@ var MovimWebsocket = {
if(e.code == 1006) {
MovimWebsocket.reconnect();
} else if(e.code == 1000) {
if(MovimWebsocket.unregistered == false) {
MovimUtils.disconnect();
} else {
MovimWebsocket.unregistered = false;
MovimWebsocket.init();
}
MovimUtils.disconnect();
}
};
this.connection.onerror = function(e) {
console.log(e.code);
console.log(e);
console.log("Connection error!");
// We hide the Websocket error
MovimUtils.showElement(document.getElementById('error_websocket'));
MovimWebsocket.reconnect();
// We prevent the onclose launch
@ -155,13 +153,12 @@ var MovimWebsocket = {
},
unregister : function(reload) {
if(reload == false) this.unregistered = true;
this.connection.unregister();
},
reconnect : function() {
var interval = MovimWebsocket.generateInterval();
console.log("Try to reconnect in " + interval);
console.log("Try to reconnect");
setTimeout(function () {
// We've tried to reconnect so increment the attempts by 1
MovimWebsocket.attempts++;
@ -183,16 +180,7 @@ var MovimWebsocket = {
}
}
function remoteUnregister()
{
MovimWebsocket.unregister(false);
}
function remoteUnregisterReload()
{
MovimWebsocket.unregister(true);
}
/*
document.addEventListener("visibilitychange", function () {
if(!document.hidden) {
if(MovimWebsocket.connection.readyState == 3) {
@ -200,7 +188,7 @@ document.addEventListener("visibilitychange", function () {
}
}
});
*/
window.onbeforeunload = function() {
MovimWebsocket.connection.onclose = function () {}; // disable onclose handler first
MovimWebsocket.connection.close()

3
app/controllers/AccountController.php

@ -7,6 +7,9 @@ class AccountController extends Base {
}
function dispatch() {
$session = \Sessionx::start();
requestURL('http://localhost:1560/disconnect/', 2, ['sid' => $session->sessionid]);
$this->page->setTitle(__('page.account_creation'));
}
}

2
app/controllers/LoginController.php

@ -8,7 +8,7 @@ class LoginController extends Base {
function dispatch() {
$session = \Sessionx::start();
requestURL('http://localhost:1560/unregister/', 2, ['sid' => $session->sessionid]);
//requestURL('http://localhost:1560/unregister/', 2, ['sid' => $session->sessionid]);
$this->page->setTitle(__('page.login'));

2
app/models/sessionx/SessionxDAO.php

@ -3,7 +3,7 @@
namespace modl;
class SessionxDAO extends SQL {
function init(Sessionx $s) {\movim_log($s->start);
function init(Sessionx $s) {
$this->_sql = '
update sessionx
set username = :username,

1
app/views/login.tpl

@ -1,6 +1,5 @@
<?php $this->widget('Presence'); ?>
<main>
<?php //$this->widget('Header');?>
<section>
<div>
<?php $this->widget('Login'); ?>

11
app/views/page.tpl

@ -53,6 +53,17 @@
</noscript>
<div id="hiddendiv"></div>
<div id="snackbar" class="snackbar"></div>
<div id="error_websocket" class="snackbar">
<ul class="list">
<li>
<span class="control icon gray">
<i class="zmdi zmdi-code-setting"></i>
</span>
<p class="normal">
<?php echo __('error.websocket'); ?>
</p>
</li>
</div>
<?php $this->widget('Dialog');?>
<?php $this->widget('Drawer');?>
<?php $this->widget('Notification');?>

5
app/widgets/AccountNext/AccountNext.php

@ -93,7 +93,10 @@ class AccountNext extends \Movim\Widget\Base {
function onServiceUnavailable()
{
Notification::append(null, $this->__('error.service_unavailable'));
RPC::call('remoteUnregister');
$session = \Sessionx::start();
requestURL('http://localhost:1560/disconnect/', 2, ['sid' => $session->sessionid]);
RPC::call('MovimUtils.redirect', $this->route('account'));
}

3
app/widgets/AccountNext/_accountnext_registered.tpl

@ -3,7 +3,8 @@
<h2 id="username">username@server.com</h2>
<a class="button color" onclick="remoteUnregister(); MovimWebsocket.attach(function() {MovimUtils.redirect('{$c->route('disconnect')}')});" href="#">
<a class="button color"
href="{$c->route('disconnect')}">
{$c->__('page.login')}
</a>
</div>

6
app/widgets/Login/_login_error.tpl

@ -4,5 +4,9 @@
<h4 class="gray">{$error}</h4>
</section>
<div>
<span class="button flat oppose" onclick="remoteUnregister(); MovimWebsocket.attach(function() {MovimUtils.redirect('{$c->route('login')}')});">{$c->__('button.return')}</span>
<span
class="button flat oppose"
onclick="MovimUtils.redirect('{$c->route('disconnect')}');">
{$c->__('button.return')}
</span>
</div>

3
app/widgets/Login/locales.ini

@ -10,7 +10,6 @@ session = Session error
account_created = Account successfully created
xmpp_unauthorized = Your XMPP server is unauthorized
mec_error = The server takes too much time to respond
websocket = Movim cannot talk with the server, please try again later (Websocket connection error)
impossible = Impossible login
title = Oops!
@ -30,6 +29,6 @@ create_one = Create one !
another_account = Another account
no_account = No account yet ?
whitelist.info = You can login with accounts from theses servers
whitelist_info = You can login with accounts from theses servers
connected = Connected
population = Population

3
app/widgets/Login/login.js

@ -147,9 +147,6 @@ MovimWebsocket.attach(function()
Login.init();
// We hide the Websocket error
MovimUtils.hideElement(document.getElementById('error_websocket'));
// We enable the form
var inputs = document.querySelectorAll('#login_widget div input[disabled]');
for (var i = 0; i < inputs.length; i++)

8
app/widgets/Login/login.tpl

@ -62,9 +62,10 @@
{/if}
{if="isset($whitelist) && $whitelist != ''"}
<ul class="list thin card">
<ul class="list thin">
<li class="info">
<p class="normal">{$c->__('whitelist.info')} : {$whitelist}</p>
<p></p>
<p class="center normal">{$c->__('form.whitelist_info')} : {$whitelist}</p>
</li>
</ul>
{/if}
@ -87,6 +88,3 @@
</div>
</div>
<div id="error_websocket" class="snackbar">
{$c->__('error.websocket')}
</div>

1
locales/locales.ini

@ -35,6 +35,7 @@ cannot_load_file = "Cannot load file '%s'"
widget_load_error = "Requested widget '%s' doesn't exist."
widget_call_error = "Requested event '%s' not registered."
whoops = "Whoops!"
websocket = Movim cannot talk with the server, please try again later (Websocket connection error)
[button]
validate = Validate

9
themes/material/css/style.css

@ -439,6 +439,15 @@ main section > div:first-child:nth-last-child(2) ~ div .actions.fixed > div:last
opacity: 0;
}
.snackbar#error_websocket {
max-height: initial;
}
.snackbar#error_websocket p {
line-height: 2.5rem;
white-space: initial;
}
@media screen and (max-width: 22rem) {
.snackbar {
width: 100%;

Loading…
Cancel
Save