Alright,
problem solved! I needed to refactor my code and declare the publish()
function inside the peer connection block.
here's the code to assign the function to the button:
<script>
$( document ).ready(function() {
var peer = new Peer('controller', {key: 'xxxxxxxxxx'});
var conn = peer.connect('myGame');
var publish;
conn.on('open', function(){
publish = function(message) {
conn.send(message);
}
});
})
</script>
HTML
<button onclick="publish('Now I'm working!')">Send<button>