Skip to content

Generate live view counts for HackSoc pages using WebSockets

Notifications You must be signed in to change notification settings

HackSoc/socketwatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

socketwatch

The use of the URL API requires nodejs version 10 or later.

Example usage

This is best put behind an Nginx reverse proxy, perhaps under a subpath

There are <span id="viewers">0<span> people viewing this page right now.
<script>
    let ws = new WebSocket("ws://example.com/socketwatch/");

    ws.addEventListener('message', (e) => {
        document.querySelector('#viewers').innerHTML = e.data;
    }); // Whenever the server replies, update the view count

    ws.addEventListener('open', () => {
        setInterval(()=>{
            ws.send(window.location.href);
        }, 5000); // Every 5 seconds, send the server our URL.
    });
</script>

About

Generate live view counts for HackSoc pages using WebSockets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published