Messages en direct
// Configuration Pusher
const pusher = new Pusher(‘VOTRE_APP_KEY’, {
cluster: ‘VOTRE_CLUSTER’,
forceTLS: true
});
const channel = pusher.subscribe(‘fusée’);
channel.bind(‘nouveau-message’, function(data) {
const li = document.createElement(‘li’);
li.textContent = data.message;
document.getElementById(‘messages’).appendChild(li);
});
function sendMessage() {
const msg = document.getElementById(‘msg’).value;
fetch(‘https://www.lepetitchimiste.com/wp-content/plugins/fusee/send_message.php’, {
method: ‘POST’,
headers: {‘Content-Type’:’application/x-www-form-urlencoded’},
body: ‘message=’ + encodeURIComponent(msg)
}).then(response => response.text())
.then(data => console.log(data));
}