Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

313
Vistas
Twilio Sync: connection closed by server, reason is TOKEN_EXPIRED

Twilio Sync Time out is 172800

$.getJSON("/dashboard/token", function (response) {
    console.log(`Token Generated at ${new Date()}`);
    localStorage.setItem('syncToken', response.token);
    
    syncClient = new Twilio.Sync.Client(response.token, { logLevel: "info" });

    syncClient.on('tokenAboutToExpire', function () {
        console.log(`tokenAboutToExpire at: ${new Date()}`);
        var token = localStorage.getItem('syncToken');
        syncClient.updateToken(token);
    });
});

Here is the Twilio Sync browser console showing:

Twilsock I: socket opened
twilio-sync.js:25304 Twilsock I: refreshing all registrations
twilio-sync.js:25304 Twilsock I: update registration for context 8c430fb3-4353-4b06-9cfd-6bebc78582b0

But after some time this message will occurs in browser:

Twilsock I: connection has expired
Notify I: Transport ready false 
Twilsock I: connection closed by server, reason is TOKEN_EXPIRED
Twilsock I: socket closed CloseEvent

can anyone tell me how to resolve this on Twilio Sync Event?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Twilio developer evangelist here.

The event you are receiving there is that the token is about to expire, however you are replacing the token with itself. Instead, you should request a new token from your back-end and update the client with that new token.

$.getJSON("/dashboard/token", function (response) {
    console.log(`Token Generated at ${new Date()}`);
    localStorage.setItem('syncToken', response.token);
    
    syncClient = new Twilio.Sync.Client(response.token, { logLevel: "info" });

    syncClient.on('tokenAboutToExpire', function () {
        console.log(`tokenAboutToExpire at: ${new Date()}`);
        $.getJSON("/dashboard/token", function (response) {
            syncClient.updateToken(response.token);
        });
    });
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

Thanks, I tried all events so here I got it...

syncClient.on('connectionStateChanged', (newState) => {
    console.log('Received a new connection state:', newState);
    if (newState === 'disconnecting') {
        $.getJSON("/dashboard/token", function (response) {
            var token = response.token;
            syncClient.updateToken(token);
        });
    }
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda