I’m trying to create a multiplayer game with Gun.js.
I made some tests with 2 browsers opened at same time and noticed sometimes the changes in one window are not updating the other.
So, I would like to check if the problem is with the connection / peer.
I’m using this GUN relay URL: https://gun-manhattan.herokuapp.com/gun
How do I check if the relay is connected?
index.html
<body>
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
<script src="gunjs-test.js"></script>
<div>
Relay URL:
<input type="text" id="url" value="https://gun-manhattan.herokuapp.com/gun" style="width: 400px">
<button onclick="initGun(document.getElementById('url').value)">Init gun</button>
</div>
<div>
Root node name:
<input type="text" id="rootNodeName" value="test">
</div>
<div>
Node name:
<input type="text" id="nodeName" value="paste">
</div>
<button onclick="enableRealtimeUpdates(document.getElementById('rootNodeName').value, document.getElementById('nodeName').value)">Enable realtime updates</button>
</body>
gunjs-test.js
let gun = null;
function initGun(url) {
gun = Gun([url]);
}
function enableRealtimeUpdates(rootNodeName, nodeName) {
gun.get(rootNodeName).get(nodeName).on((data, id) => {
console.log("id: " + id);
console.log("data: " + data);
});
}
function isConnected() {
// ???
}