Advertisement
michaelyuen

Untitled

Jan 17th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2.     // update new message to table
  3.     $data['chatid'] = $to_id; // use a unique random string
  4.     // broadcast using pusher notication
  5.     $pusher->trigger('__subscribed_channel__', '__chat_session__', $data);
  6. ?>
  7.  
  8. <!-- for user notification -->
  9. <script type="text/javascript">
  10.     // Enable pusher logging - don't include this in production
  11.     Pusher.log = function(message) {
  12.         if (window.console && window.console.log) {
  13.             window.console.log(message);
  14.         }
  15.     };
  16.  
  17.     var pusher = new Pusher('__app_secret__');
  18.     var channel = pusher.subscribe('__subscribed_channel__');
  19.     channel.bind('gsm_chat', function(data) {
  20.         var element = document.getElementById("new_msg");
  21.         if (data.chatid == '<?= $_SESSION['user']['chatid']; ?>') {
  22.         element.innerHTML = data.message;
  23.         } else {
  24.         element.innerHTML = '<a href="messaging.php"><div class="no_msg"></div></a>';                  
  25.         }
  26.     });
  27. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement