Hello there !
Can someone demystify the basics RT API ?
As I konw right now, we start by request a token :
async function getAccessToken(username, password) {
const uri = `https://online-go.com/oauth2/token/`
const method = 'POST'
const body = new FormData()
body.append('grant_type', 'password')
body.append('username', username)
body.append('password', password)
body.append('client_id', CLIENT_ID)
body.append('client_secret', CLIENT_SECRET)
const res = await fetch(uri, { method, body })
return await res.json()
}
After this, we request the config object with the token :
async function getConfig(token) {
const uri = `https://online-go.com/api/v1/ui/config`
const headers = { 'Authorization': `Bearer ${token}` }
const method = 'GET'
const res = await fetch(uri, { method, headers })
return await res.json()
}
So, I have right now those items :
- token
- chat_auth
- user_jwt
- csrf_token
- user object (who is an anonyme unrelated with the user’s credentials)
Next I try to etablish websocket connection :
async function connectSocket(token, config) {
const ws = new WebSocket('wss://online-go.com/socket.io/?transport=websocket')
ws.on('open', () => {
console.log("connected")
ws.send(" ? ")
})
ws.on('message', (msg) => {
console.log('message: ', msg)
})
ws.on('error', console.log)
}
I use the package ‘ws’ on npm. At this stage this is what I get :
connected
message: 0{"sid":"c7Uv9Pam43DrQ7BZAB59","upgrades":[],"pingInterval":25000,"pingTimeout":5000}
How should I send message to the api ? I tried differents way (formating, parsing…) but I can’t get the right combinaison.
ws.send(`42[“notification/connect”,{“player_id”:“***”,“username”:“***”,“auth”:“***”}] `)
ws.emit('notification/connect', {player_id, username, auth})
ws.emit('notification/connect', JSON.stringify({player_id, username, auth}))
And what auth value among all items above should I send ?
Could be usefull for all I guess, thank you !