let socket = io(); socket.on('connect', () => { let persistToken = localStorage.getItem('playerToken') if (persistToken) { socket.emit('token:set', persistToken); } else { socket.emit('token:refresh'); } }); socket.on('token:expired', () => { // token已过期,重载整个播放器 socket.emit('token:refresh'); }); socket.on('token:update', (token) => { // 收到token console.log('new token: ', token); localStorage.setItem('playerToken', token) });