Answer the question
In order to leave comments, you need to log in
Pusher laravel not working?
I have a code that sends messages >
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
var receiver_id = '';
var my_id = "{{ Auth::id() }}";
$(document).ready(function () {
// ajax setup form csrf token
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('3856999f0d59abd33d07', {
cluster: 'eu',
forceTLS: true
});
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function (data) {
alert(JSON.stringify(data));
if (my_id == data.from) {
$('#' + data.to).click();
} else if (my_id == data.to) {
if (receiver_id == data.from) {
// if receiver is selected, reload the selected user ...
$('#' + data.from).click();
} else {
// if receiver is not seleted, add notification for that user
var pending = parseInt($('#' + data.from).find('.pending').html());
if (pending) {
$('#' + data.from).find('.pending').html(pending + 1);
} else {
$('#' + data.from).append('<span class="pending">1</span>');
}
}
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question