Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

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

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages