indicateur user online sur le chat (fixes #5)
This commit is contained in:
parent
7265099724
commit
5d877dd8ca
@ -58,6 +58,7 @@
|
||||
<input id="sendbymail" type="checkbox" id="item_essential" name="item[essential]" style="float:right" class='switch' ></input>
|
||||
<label class="custom-control-label" for="sendbymail">Envoyer par Mail ?</label>
|
||||
<a id="sendbtn" class="btn btn-success" style="margin-top:5px; width:100%; margin-bottom:15px">Envoyer</a>
|
||||
<div id="useronline" style="margin-bottom:10px"></div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -222,16 +223,18 @@
|
||||
],
|
||||
height: 150
|
||||
});
|
||||
},500);
|
||||
},1000);
|
||||
|
||||
$(".switch").bootstrapSwitch();
|
||||
$("#mymodal-sendmail").removeAttr("tabindex");
|
||||
|
||||
websocket();
|
||||
|
||||
/*
|
||||
setInterval(function(){
|
||||
islive();
|
||||
}, 15000);
|
||||
*/
|
||||
});
|
||||
|
||||
{% if websocket_activate and app.user %}
|
||||
@ -303,6 +306,28 @@
|
||||
if(payload.alert) {
|
||||
alert(payload.alert);
|
||||
}
|
||||
|
||||
if(payload.islive) {
|
||||
if(payload.userid!={{app.user.id}}) {
|
||||
console.log("Received message islive", payload.userid);
|
||||
addOnline(payload.userid, payload.useravatar, payload.userlastname, payload.userfirstname);
|
||||
{% if app.user.visible %}
|
||||
event={mykey: "{{userkey}}", type: "meto", userid: {{app.user.id}}, useravatar: "{{app.user.avatar}}", userlastname: "{{ app.user.lastname}}", userfirstname: "{{ app.user.firstname }}" };
|
||||
session.publish("websocket/channel/{{groupid}}", event);
|
||||
{% endif %}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(payload.meto) {
|
||||
console.log("Received message meto", payload.userid, payload.useravatar, payload.userlastname, payload.userfirstname);
|
||||
addOnline(payload.userid, payload.useravatar, payload.userlastname, payload.userfirstname);
|
||||
}
|
||||
|
||||
if(payload.isdead) {
|
||||
console.log("Received message isdead", payload.userid);
|
||||
$("#online"+payload.userid).remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -472,11 +497,24 @@
|
||||
function islive() {
|
||||
if(!session) return;
|
||||
isalive=true;
|
||||
event={mykey: "{{userkey}}", type: "islive", userid: {{app.user.id}}};
|
||||
|
||||
{% if app.user.visible %}
|
||||
addOnline({{app.user.id}}, "{{app.user.avatar}}", "{{app.user.lastname}}", "{{app.user.firstname}}");
|
||||
|
||||
event={mykey: "{{userkey}}", type: "islive", userid: {{app.user.id}}, useravatar: "{{app.user.avatar}}", userlastname: "{{app.user.lastname}}", userfirstname: "{{app.user.firstname}}" };
|
||||
console.log("send islive");
|
||||
session.publish("websocket/channel/{{groupid}}", event);
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
function addOnline(userid, useravatar, userlastname, userfirstname) {
|
||||
if(!$("#online"+userid).length) {
|
||||
html = "<span id='online"+userid+"'>";
|
||||
html+= "<img style='cursor:pointer; width:30px; height:30px; margin-right:5px;' onclick='seeUser("+userid+")' title='"+userlastname+" "+userfirstname+"' id='user_avatar_img' src='/{{ alias }}/uploads/avatar/"+useravatar+"' class='avatar'>";
|
||||
html+= "</span>";
|
||||
$("#useronline").append(html);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{% endif %}
|
||||
|
@ -52,9 +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(['log' => "Alive = ".$event["userid"]]);
|
||||
|
||||
$topic->broadcast(['log' => $connection->resourceId . " has left " . $topic->getId(). " || userid = ".$connection->userId]);
|
||||
$topic->broadcast(['isdead' => 'isdead','userid'=>$connection->userId]);
|
||||
}
|
||||
|
||||
|
||||
@ -90,10 +88,25 @@ class WebsocketTopic implements TopicInterface
|
||||
|
||||
if($group&&$usergroup&&$user) {
|
||||
if($event["type"]=="islive") {
|
||||
$topic->broadcast(['log' => "Alive = ".$event["userid"]]);
|
||||
$topic->broadcast([
|
||||
"islive" => "islive",
|
||||
"userid" => $event["userid"],
|
||||
"useravatar" => $event["useravatar"],
|
||||
"userlastname" => $event["userlastname"],
|
||||
"userfirstname" => $event["userfirstname"],
|
||||
]);
|
||||
$connection->userId=$event["userid"];
|
||||
}
|
||||
|
||||
if($event["type"]=="meto") {
|
||||
$topic->broadcast([
|
||||
"meto" => "meto",
|
||||
"userid" => $event["userid"],
|
||||
"useravatar" => $event["useravatar"],
|
||||
"userlastname" => $event["userlastname"],
|
||||
"userfirstname" => $event["userfirstname"],
|
||||
]);
|
||||
}
|
||||
|
||||
if($event["type"]=="add") {
|
||||
if(array_key_exists("mail",$event)) {
|
||||
|
Loading…
Reference in New Issue
Block a user