eu tentei replicar a parte do websocket, tudo funciona corretamente mas quando o usuário chama a próxima senha, o disparo do websocket conectado "call ticket" não funciona, o codigo que eu fiz é bem simples, só fiz para testar o fluxo
window.onload = async () => {
const client_id = '2_3rj4b604e60w0ok8cckwkssw0cs4k0cco0sww48swscco44gg0'
const client_secret = '47i7t5n2zv0g4wksoskkkww0c0ogw0s8o8sc48co4sggkwk08o'
const username = 'admin'
const password = '123456'
const api = axios.create({
baseURL: 'http://localhost:8080/api'
})
let access_token
let refresh_token
let socket
async function auth() {
var params = new URLSearchParams()
params.append('grant_type', 'password')
params.append('client_id', client_id)
params.append('client_secret', client_secret)
params.append('username', username)
params.append('password', password)
return (await api.post('/token', params)).data
}
async function refreshToken() {
var params = new URLSearchParams()
params.append('grant_type', 'refresh_token')
params.append('client_id', client_id)
params.append('client_secret', client_secret)
params.append('refresh_token', refresh_token)
const refreshResponse = (await api.post('/token', params)).data
access_token = refreshResponse.access_token
refresh_token = refreshResponse.refresh_token
}
async function fetchMessages() {
await refreshToken()
const id = 1 //unidade
const config = {
headers: {
Authorization: 'Bearer ' + access_token
},
params: {
servicos: '1,2'
}
}
const messages = (await api.get(`unidades/${id}/painel`, config)).data
console.log(messages)
}
function doConnect() {
const url = `http://localhost:2020`
console.log('[websocket] trying connect to websocket server: ' + url)
socket = io(url, {
path: '/socket.io',
transports: ['websocket'],
secure: true,
timeout: 2000,
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
reconnectionAttempts: 3
})
socket.on('connect', () => {
console.log('[websocket] connected')
socket.emit('register panel', {
unity: 1,
services: '1,2'
})
})
socket.on('disconnect', () => {
console.log('[websocket] disconnected!')
})
socket.on('connect_error', (evt) => {
console.log('[websocket] connect error', evt)
})
socket.on('connect_timeout', () => {
console.log('[websocket] timeout')
})
socket.on('reconnect_failed', () => {
console.log('[websocket] max attempts reached, ajax polling fallback')
socket.open()
})
socket.on('error', (evt) => {
console.log('[websocket] error', evt)
})
socket.on('register ok', () => {
console.log('[websocket] painel registered')
fetchMessages()
})
socket.on('call ticket', () => {
console.log('[websocket] call ticket')
//fetchMessages()
})
fetchMessages()
}
const authResponse = await auth()
access_token = authResponse.access_token
refresh_token = authResponse.refresh_token
doConnect()
}
alguem pode me ajudar?