{"id":18401402,"url":"https://github.com/dozyio/watch-websocket","last_synced_at":"2025-04-12T17:33:56.667Z","repository":{"id":118202647,"uuid":"448338063","full_name":"dozyio/watch-websocket","owner":"dozyio","description":"File Watcher with Websocket","archived":false,"fork":false,"pushed_at":"2022-01-16T00:15:44.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-16T03:32:43.885Z","etag":null,"topics":["file-watcher","go","golang","websocket"],"latest_commit_sha":null,"homepage":"https://github.com/dozyio/watch-websocket","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dozyio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-15T16:57:57.000Z","updated_at":"2022-01-15T21:07:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"22fda13c-ecec-4094-be8e-2c313e5f5a7b","html_url":"https://github.com/dozyio/watch-websocket","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dozyio%2Fwatch-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dozyio%2Fwatch-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dozyio%2Fwatch-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dozyio%2Fwatch-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dozyio","download_url":"https://codeload.github.com/dozyio/watch-websocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248605110,"owners_count":21132112,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file-watcher","go","golang","websocket"],"created_at":"2024-11-06T02:38:43.125Z","updated_at":"2025-04-12T17:33:56.642Z","avatar_url":"https://github.com/dozyio.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# File Watcher \u0026 Websocket\n\nA file watcher and websocket server written in Go.\n\nBasic premise is that you want to watch for file system changes and inform a\nJavascript client of the update. The JS client could then perform a reload of\nthe page - i.e. a laymans hot reload.\n\nThere are probably better solutions but I needed something lightweight without\nusing webpack.\n\nThe file watcher runs on the current working directory and the websocket on\n**ws://127.0.0.1:12345/ws**\n\n## Install\n    git clone https://github.com/dozyio/watch-websocket\n    cd watch-websocket\n    go install\n\n## Running\n\nRun watch-websocket from the path you want to watch changes in.\n\n    ./watch-websocket\n\n## JS Client\n\nSample javascript client\n\n    \u003cscript\u003e\n    var socket = new WebSocket(\"ws://127.0.0.1:12345/ws\");\n    var heartbeat;\n\n    function wsHeartbeat() {\n        socket.send('!');\n    }\n\n    function reload() {\n        window.location.reload(true);\n    }\n\n    socket.onopen = function(event) {\n        console.log('WS Connected');\n        wsHeartbeat();\n        heartbeat = setInterval(wsHeartbeat, 5000);\n    };\n\n    socket.onmessage = function(event) {\n        console.log(`WS message ${event.data}`);\n        if (event.data === 'reload') {\n            // Add a small delay to allow files to save and other processes\n            // to run (i.e. tailwind JIT)\n            setTimeout(reload, 200);\n        }\n    };\n\n    socket.onclose = function(event) {\n        console.log('WS connection closed', event);\n        clearInterval(heartbeat);\n    };\n\n    socket.onerror = function(error) {\n        console.log(`WS error ${error.message}`);\n        clearInterval(heartbeat);\n    };\n    \u003c/script\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdozyio%2Fwatch-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdozyio%2Fwatch-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdozyio%2Fwatch-websocket/lists"}