I am not sure if anyone experimented with JavaScript for socket connection with OGS. I had some difficulties getting my codes to work.
const { io } = require("socket.io-client");
async function connectSocket(accessToken) {
let url = 'https://online-go.com/socket.io/';
params = {
EIO: '4',
transport: 'websocket'
header = {
extraHeaders: {
Authorization: `Bearer ${accessToken}`
let socket = io(url, params, header);
socket.on('connect', () => {
console.log('socket connected');
After I ran the code, the terminal just froze… It didn’t give me any response or printed any texts. Can you see anything wrong with my codes?
I am using this post API Python recap/ help as a reference. If possible @Dyonn do you have any insights?
Could you share the full repo on GitHub or something? This code snippet won’t output anything because you never call connectSocket()
, but I’m guessing that was just omitted for brevity.
But other than that, I don’t see what the problem is. I wonder if the socket is already connected by the time you register the “connect” handler. So it doesn’t get emitted. @Dyonn idea of sending/receiving more messages seems good - there’s some ping/pong stuff in OGS code that you could try to emulate: online-go.com/sockets.ts at 09a424e7f2fe9bf8517cda0dfd7a2361313fedcb · online-go/online-go.com · GitHub
Okay here’s a pretty minimal working example of interacting with the OGS socket server via Node.js:
const { io } = require("socket.io-client");
let url = 'https://online-go.com';
params = {
transports: ["websocket"],
let socket = io(url, params);
socket.on('connect', () => {
console.log('socket connected');
socket.emit("hostinfo");
socket.on("hostinfo", (hostinfo) => {
console.log("Termination server", hostinfo);
output:
socket connected
Termination server {
hostname: 'ogs-termserver-8689699b58-z9hhf',
clients: 0,
uptime: 20549.259,
'ggs-version': 'rengo-1.2.2'
Note that in params
, I set transports: ['websocket']
instead of transport: 'websocket'
(see socket.io docs). Also the URL is just 'https://online-go.com'
.
I wasn’t able to get the ping/pong to work, but I think that’s because I haven’t sent the "authenticate"
message yet. You will likely need to figure out how that works in order to do anything useful. I think that’s where the accessToken
gets sent, but I’ve never done it myself…
I think I’m having trouble understanding the question. You’re asking if the demo will be viewable in the browser? I think the answer would be yes. You can get the review id from the XHR response, or you can just go to your profile and look at the newest entry in the Reviews and Demos table.
But it kind of sounds like you’re expecting the script to generate a GUI, which definitely will not happen unless you’re doing something clever.