Created
December 6, 2018 21:19
-
-
Save dheerajsuthar/deeb2e32a1eebd67fe325aebf9ba2faa to your computer and use it in GitHub Desktop.
Simple Publisher using Client WebSockets API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
body { | |
font-family: Tahoma, Geneva, sans-serif; | |
} | |
div { | |
display: inline; | |
} | |
</style> | |
<script> | |
function publish() { | |
var message = document.getElementById('message').value; | |
var channel = document.getElementById('channel').value; | |
var host = window.document.location.host.replace(/:.*/, ''); | |
var ws = new WebSocket('ws://' + host + ':8080'); | |
ws.onopen = function () { | |
ws.send(JSON.stringify({ | |
request: 'PUBLISH', | |
message: message, | |
channel: channel | |
})); | |
ws.close(); | |
}; | |
} | |
</script> | |
</head> | |
<body> | |
<h1>Publisher</h1> | |
<input type="text" id="channel" placeholder="Channel (weather, sports etc.)" /> | |
<input type="text" id="message" placeholder="What you want to publish?" /> | |
<button onclick="publish()">Publish</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment