Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!