php - Getting message in angularjs chat application without refresh. -
i using angularjs 1.5.5 , codeigniter 3.0 .
when send message 1 user user offline working fine after uploaded project come know not working because receiver received message in time when send message sender.
$scope.sendsendermessage = function(bsid,srid,message) { //bsid sender id while srid receiver id $http.post(url + 'c_chat/sendsendermessagejson', { 'bsid' : bsid , 'srid' : srid , 'message' : message }) .success(function(data) { $scope.startchat(fksc_id); }); } after sending message through following function data: $scope.startchat = function(fksc_id=false) { if(fksc_id) { $http.get(url + 'c_chat/startchatjson/' + fksc_id).success(function(data) { //console.log(data); $scope.chats = data; }); } }
and in view:
<div ng-init="startchat()"> <div ng-repeat="chat in chats" > <div class="col-md-6"> <p >{{chat.sender_message}}</p> </div> </div>
chat.sender_message real message both sender , receiver. problem receiver message show when message sent or page refreshed.
my data base table like
message_id fksc_id fkrc_id sender_message
you use angular timeout refresh scope every n seconds:-
var timer = $timeout( function refresh(){ //your code refresh scope timer = $timeout(refresh, 100000); }, 100000);
or use sockets socket.io emit event , refresh scope:
something this:
socket.on('receive:message', function (message) { //your code refresh scope });
i'll recommend socket io npm link
Comments
Post a Comment