gestion websocket server
This commit is contained in:
parent
4b0d392e58
commit
1f3f2246fd
|
@ -22,6 +22,7 @@ composer install
|
|||
./perm.sh www-data
|
||||
|
||||
# Nettoyage du cache
|
||||
rm /var/www/html/ninegate/var/cache/* -rf
|
||||
php bin/console cache:clear --env=prod --no-debug
|
||||
|
||||
# Migration si nécessaire du schéma de la base
|
||||
|
@ -55,13 +56,5 @@ fi
|
|||
# Server Websocket
|
||||
if [[ "$ninegate_websocket" = 'oui' ]]
|
||||
then
|
||||
echo ""
|
||||
echo WEBSOCKET = STOP
|
||||
pid="$(pgrep -f gos:websocket)"
|
||||
if [ -n "${pid}" ]; then
|
||||
kill -9 ${pid};
|
||||
fi
|
||||
|
||||
echo WEBSOCKET = START
|
||||
bin/console gos:websocket:server --port $websocket_portinterne -a $websocket_url --no-debug -n -q --env=prod & disown
|
||||
/var/www/html/ninegate/scripts/ninegate-websocket.sh
|
||||
fi
|
|
@ -3,11 +3,24 @@ websocket_url=$(CreoleGet adresse_ip_eth0 non)
|
|||
websocket_portinterne=$(CreoleGet ninegate_websocket_portinterne non)
|
||||
|
||||
# Server Websocket
|
||||
echo WEBSOCKET = STOP
|
||||
pid="$(pgrep -f gos:websocket)"
|
||||
if [ -n "${pid}" ]; then
|
||||
kill -9 ${pid};
|
||||
if [[ "$1" != "restartifdown" ]]; then
|
||||
echo WEBSOCKET = STOP
|
||||
pid="$(pgrep -a -f gos:websocket | grep $websocket_portinterne)"
|
||||
if [ -n "${pid}" ]; then
|
||||
IFS=' ' read -r -a array <<< "$pid"
|
||||
kill -9 ${array[0]};
|
||||
fi
|
||||
fi
|
||||
|
||||
echo WEBSOCKET = START
|
||||
bin/console gos:websocket:server --port $websocket_portinterne -a $websocket_url --no-debug -n -q --env=prod & disown
|
||||
# Port LISTEN ?
|
||||
pid="$(pgrep -a -f gos:websocket | grep $websocket_portinterne)"
|
||||
restart="yes"
|
||||
if [ "$1" == "restartifdown" ] && [ -n "${pid}" ] ; then
|
||||
restart="no"
|
||||
fi
|
||||
|
||||
if [[ "$restart" == "yes" ]]; then
|
||||
echo WEBSOCKET = START
|
||||
cd /var/www/html/ninegate
|
||||
bin/console gos:websocket:server --port $websocket_portinterne -a $websocket_url --no-debug -n -q --env=prod & disown
|
||||
fi
|
|
@ -8,7 +8,7 @@ INSERT IGNORE INTO `niveau01` (`id`, `label`, `siren`) VALUES
|
|||
(-100, 'DRAAF', '130007107');
|
||||
|
||||
INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES
|
||||
(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}30Z8NQIFHi2TUxnZr8sENMbBiOWgonju
|
||||
(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}vVciL1BZlGqITdyEI5am1J21xEgy2M02
|
||||
', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple');
|
||||
|
||||
|
||||
|
|
|
@ -646,6 +646,27 @@ class PageController extends Controller
|
|||
|
||||
}
|
||||
|
||||
public function msgcounterAction(Request $request,$access="config")
|
||||
{
|
||||
// S'assurer que c'est un appel ajax
|
||||
if (!$request->isXmlHttpRequest()) {
|
||||
return new JsonResponse(array('message' => 'Interdit'), 400);
|
||||
}
|
||||
|
||||
$user=$this->getUser();
|
||||
$this->getDoctrine()->getRepository("CadolesPortalBundle:Page")->getPagesUser($user,null,$entity,$pagesuser,$pagesadmin,$groupsshared);
|
||||
|
||||
$output=[];
|
||||
foreach($groupsshared as $groupshared) {
|
||||
$output[$groupshared->getId()]=$groupshared->pagesshared[0]->getCounterRead();
|
||||
}
|
||||
|
||||
$response = new Response(json_encode($output));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode) {
|
||||
if ($form->get('submit')->isClicked() && $mode=="submit") {
|
||||
$usage = $form->get('usage')->getData();
|
||||
|
|
|
@ -325,6 +325,10 @@ cadoles_portal_user_page_application:
|
|||
path: /page/application
|
||||
defaults: { _controller: CadolesPortalBundle:Page:application, access: user }
|
||||
|
||||
cadoles_portal_user_page_ajax_msgcounter:
|
||||
path: /page/ajax/msgcounter
|
||||
defaults: { _controller: CadolesPortalBundle:Page:msgcounter, access: user }
|
||||
|
||||
|
||||
#== BOOKMARK =============================================================================================================================================
|
||||
|
||||
|
|
|
@ -269,7 +269,14 @@
|
|||
order: [[ 1, "asc" ]],
|
||||
});
|
||||
|
||||
{% if app.user %}
|
||||
setInterval(function(){
|
||||
loadmsgCounter()
|
||||
}, 10000);
|
||||
{% endif %}
|
||||
|
||||
// Init socket de counter
|
||||
/* Désactiver car il semble préférable de faire un appel ajax régulier plutot qu'ouvrir un channel websocket
|
||||
{% if websocket_activate %}
|
||||
var _WS_URI = "wss://{{ gos_web_socket_server_host }}:{{ gos_web_socket_server_port }}";
|
||||
|
||||
|
@ -309,6 +316,7 @@
|
|||
});
|
||||
});
|
||||
{% endif %}
|
||||
*/
|
||||
});
|
||||
|
||||
$(window).resize(function() {
|
||||
|
@ -336,6 +344,7 @@
|
|||
|
||||
// Affichage des frames associés aux items de bureau
|
||||
function showFrameitem(id,url,forcereload) {
|
||||
$(".pageframereload").remove();
|
||||
$(".pageframe").hide();
|
||||
|
||||
// Si force le rechargement et frame existante on la détruit
|
||||
|
@ -346,9 +355,11 @@
|
|||
if($("#frameitem-"+id).length)
|
||||
$("#frameitem-"+id).show();
|
||||
// Sinon on la génère
|
||||
else
|
||||
$("#pagecontainer").append("<iframe id='frameitem-"+id+"' class='pageframe' src='"+url+"' style='border:none; width:100%'></iframe>");
|
||||
|
||||
else {
|
||||
var myclass="";
|
||||
if(forcereload) myclass="pageframereload";
|
||||
$("#pagecontainer").append("<iframe id='frameitem-"+id+"' class='pageframe "+myclass+"' src='"+url+"' style='border:none; width:100%'></iframe>");
|
||||
}
|
||||
|
||||
resizeFrame();
|
||||
}
|
||||
|
@ -359,6 +370,7 @@
|
|||
idpage=id;
|
||||
|
||||
// Cacher toutes les pages
|
||||
$(".pageframereload").remove();
|
||||
$(".pageframe").hide();
|
||||
|
||||
// Rendre actif le page en cours dans le menu
|
||||
|
@ -378,8 +390,11 @@
|
|||
if($("#page-"+id).length)
|
||||
$("#page-"+id).show();
|
||||
// Sinon on la génère
|
||||
else
|
||||
$("#pagecontainer").append("<iframe id='page-"+id+"' data-category='"+catid+"' class='pageframe' src='"+url+"' style='border:none; width:100%'></iframe>");
|
||||
else {
|
||||
var myclass="";
|
||||
if(forcereload) myclass="pageframereload";
|
||||
$("#pagecontainer").append("<iframe id='page-"+id+"' data-category='"+catid+"' class='pageframe "+myclass+"' src='"+url+"' style='border:none; width:100%'></iframe>");
|
||||
}
|
||||
|
||||
// Détruire le badge associé car normalement de fait on a lu les notif
|
||||
if(usage=="group") {
|
||||
|
@ -455,9 +470,73 @@
|
|||
$(location).attr('href', url);
|
||||
};
|
||||
|
||||
function loadmsgCounter() {
|
||||
/*
|
||||
menu=$("a[data-group='"+payload.group+"']");
|
||||
if(menu.length) {
|
||||
if(payload.add) {
|
||||
console.log("Ajout counter pour group "+payload.group+" by "+payload.from);
|
||||
if(menu.children(".badge").length) {
|
||||
menu.children(".badge").html(+(menu.children(".badge").html())+1);
|
||||
}
|
||||
else menu.append("<span id='badge-"+payload.group+"' class='badge'>1</span");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "{{ path('cadoles_portal_user_page_ajax_msgcounter') }}",
|
||||
success: function(data) {
|
||||
$.each(data, function(group, counter) {
|
||||
menu=$("a[data-group='"+group+"']");
|
||||
if(menu.length) {
|
||||
if(menu.children(".badge").length) {
|
||||
if(counter==0)
|
||||
menu.remove();
|
||||
else
|
||||
menu.children(".badge").html(counter);
|
||||
}
|
||||
else if(counter>0)
|
||||
menu.append("<span id='badge-"+group+"' class='badge'>"+counter+"</span");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
/*
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "process.php?process=process-notifuser.php",
|
||||
success: function(data, dataType)
|
||||
{
|
||||
if(data.trim()!="") {
|
||||
var result=data.split(",");
|
||||
if(parseInt(result[0])) {
|
||||
$("#notif").show();
|
||||
|
||||
if(result[1]!=0) {
|
||||
$("#notifbadge").html(result[1]);
|
||||
$("#notifbadge").css('display', 'inline-block');
|
||||
}
|
||||
else {
|
||||
$("#notifbadge").hide();
|
||||
}
|
||||
}
|
||||
else $("#notifbadge").hide();
|
||||
}
|
||||
else {
|
||||
$("#notif").hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
// Permet de déclencher l'évenement de modification des counter
|
||||
/* Plus nécessaire on passe par de l'ajax
|
||||
function counter(event) {
|
||||
$('#refreshcounter').data("event",event);
|
||||
$('#refreshcounter').click();
|
||||
};
|
||||
*/
|
||||
{% endblock %}
|
||||
|
|
|
@ -146,10 +146,14 @@
|
|||
|
||||
{% if websocket_activate and app.user %}
|
||||
var _WS_URI = "wss://{{ gos_web_socket_server_host }}:{{ gos_web_socket_server_port }}";
|
||||
|
||||
var webSocket = WS.connect(_WS_URI);
|
||||
var timer;
|
||||
|
||||
webSocket.on("socket/connect", function (session) {
|
||||
// Reinit du tps de tentative de reco
|
||||
$('#modalinfo').modal('hide');
|
||||
clearInterval(timer);
|
||||
|
||||
//the callback function in "subscribe" is called everytime an event is published in that channel.
|
||||
session.subscribe("websocket/channel/{{groupid}}", function (uri, payload) {
|
||||
if(payload.msg) {
|
||||
|
@ -206,8 +210,10 @@
|
|||
session.publish("websocket/channel/{{groupid}}", event);
|
||||
CKEDITOR.instances["chat_message"].setData('');
|
||||
|
||||
/* Ne plus envoyer d'event compteur on passe par de l'ajax
|
||||
event={type: "add", group:{{groupid}}};
|
||||
parent.parent.counter(event);
|
||||
*/
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -243,7 +249,42 @@
|
|||
$("#mailto").val($("#mailto").val().replace(mail, ""));
|
||||
$(this).remove();
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
webSocket.on("socket/disconnect", function(error){
|
||||
laberror="Disconnected for " + error.reason + " with code " + error.code;
|
||||
console.log(laberror);
|
||||
|
||||
$('#modalinfo').modal('show');
|
||||
if(error.code==2) {
|
||||
$('#modalinfotext').html("<center>Impossible de se connecter au serveur.<br>Vous avez dépassé le nombre de reconnexion maximum<br><br>Veuillez retentez d'ici quelques secondes<br><br><code>"+laberror+"</code><br><br><div id='modalinfotimer'></div><br><a class='btn btn-primary' onclick='location.reload(true);'>Forcer la tentative de reconnexion</a></center>");
|
||||
|
||||
clearInterval(timer);
|
||||
var nbtentative=10;
|
||||
timer=setInterval(function(){ $('#modalinfotimer').html((nbtentative--)+"s") }, 1000);
|
||||
|
||||
setTimeout(function(){ location.reload(true); }, 10000);
|
||||
}
|
||||
|
||||
if(error.code==3) {
|
||||
$('#modalinfotext').html("<center>Impossible de se connecter au serveur.<br>Veuillez retentez d'ici quelques secondes<br><br><code>"+laberror+"</code><br><br><div id='modalinfotimer'></div><br><a class='btn btn-primary' onclick='location.reload(true);'>Forcer la tentative de reconnexion</a></center>");
|
||||
|
||||
clearInterval(timer);
|
||||
var nbtentative=10;
|
||||
timer=setInterval(function(){ $('#modalinfotimer').html((nbtentative--)+"s") }, 1000);
|
||||
|
||||
setTimeout(function(){ location.reload(true); }, 10000);
|
||||
}
|
||||
|
||||
if(error.code==6 || error.code==5) {
|
||||
$('#modalinfotext').html("<center>Impossible de se connecter au serveur.<br>Vous allez être reconnecté d'ici quelques secondes<br><br><code>"+laberror+"</code><br><br><div id='modalinfotimer'></div><br><a class='btn btn-primary' onclick='location.reload(true);'>Forcer la tentative de reconnexion</a></center>");
|
||||
|
||||
clearInterval(timer);
|
||||
var nbtentative=5;
|
||||
timer=setInterval(function(){ $('#modalinfotimer').html((nbtentative--)+"s") }, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
{% endif %}
|
||||
});
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class WebsocketTopic implements TopicInterface
|
|||
public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
|
||||
{
|
||||
//this will broadcast the message to ALL subscribers of this topic.
|
||||
//$topic->broadcast(['log' => $connection->resourceId." has joined ".$topic->getId()]);
|
||||
$topic->broadcast(['log' => $connection->resourceId." has joined ".$topic->getId()]);
|
||||
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ class WebsocketTopic implements TopicInterface
|
|||
public function onUnSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
|
||||
{
|
||||
//this will broadcast the message to ALL subscribers of this topic.
|
||||
//$topic->broadcast(['msg' => $connection->resourceId . " has left " . $topic->getId()]);
|
||||
$topic->broadcast(['log' => $connection->resourceId . " has left " . $topic->getId()]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1 +1,6 @@
|
|||
* * * * * root /var/www/html/ninegate/scripts/ninegate-cron.sh &>/dev/null
|
||||
%if %%getVar("ninegate_activate_websocket", 'non') == "oui"
|
||||
* * * * * root /var/www/html/ninegate/scripts/ninegate-websocket.sh restartifdown &>/dev/null
|
||||
0 5 * * * root /var/www/html/ninegate/scripts/ninegate-websocket.sh &>/dev/null
|
||||
%end if
|
||||
|
||||
|
|
Loading…
Reference in New Issue