我正在尝试使用JS SDK,这样我就可以在短时间内使用不同的令牌进行多次调用。令牌的到期时间约为10秒,因此每次发出新的呼叫请求时,客户端都会要求新的令牌。第一个传出语音呼叫按预期工作,但第二个返回31002错误,即使我正在给他一个新的有效令牌。问题只发生在JS SDK上,而不适用于iOS或Android SDK。
控制台输出下方有更多详情
TOKEN: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZSI6InNjb3BlOmNsaWVudDpvdXRnb2luZz9hcHBTaWQ9QVBjMDQxMDY3NDZlM2UxNDg3MzQwMGM4OTEwZTM3NzY4YyZhcHBQYXJhbXM9IiwiaXNzIjoiQUM3NTkxNjVjODlkYWNjZDZhYWVlMTc4NzQyMzFkODljYSIsImV4cCI6MTQ5MTMwMDA3Mn0.-TeNrT7pn-84X8nEEeP8DN959c_6M8MUJXBOUfIn7Ds
console.js:26 [Device] Setting up PStream
console.js:26 [WSTransport] Opening socket
console.js:26 [WSTransport] attempting to connect
console.js:26 [WSTransport] Socket opened
console.js:26 [PStream] Setting token and publishing listen
console.js:26 [Device] Stream is ready
console.js:26 [Twilio.PeerConnection] signalingState is "have-local-offer"
console.js:26 Notification: twilio_client_connected
console.js:26 [Twilio.PeerConnection] signalingState is "stable"
console.js:26 Twilio connected
console.js:26 [Twilio.PeerConnection] iceConnectionState is "checking"
console.js:26 [Twilio.PeerConnection] iceConnectionState is "completed"
console.js:26 [Connection] Disconnecting...
console.js:26 Twilio disconnected
console.js:26 [Twilio.PeerConnection] iceConnectionState is "closed"
console.js:26 [Twilio.PeerConnection] signalingState is "closed"
console.js:26 Notification: voice_call_status_no_answer
console.js:26 Object {params: Object, type: "voice_call_status_no_answer"}
console.js:26 Event fired: voice-call:status-no-answer
console.js:26 TOKEN: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZSI6InNjb3BlOmNsaWVudDpvdXRnb2luZz9hcHBTaWQ9QVBjMDQxMDY3NDZlM2UxNDg3MzQwMGM4OTEwZTM3NzY4YyZhcHBQYXJhbXM9IiwiaXNzIjoiQUM3NTkxNjVjODlkYWNjZDZhYWVlMTc4NzQyMzFkODljYSIsImV4cCI6MTQ5MTMwMDExMn0.suJTJc0Sqa7akTsnAK7zo3IAYfhmr7vdw6jULDmBNd8
console.js:26 [Device] Found existing Device; using new token but ignoring options
console.js:26 [PStream] Setting token and publishing listen
console.js:26 [Twilio.PeerConnection] signalingState is "have-local-offer"
console.js:26 [Connection] Received HANGUP from gateway
console.js:26 [Connection] Received an error from the gateway:
console.js:26 Objectcode: 31002connection: amessage: "Authentication is in progress, please try again later."__proto__: Object
console.js:26 Object {code: 31002, message: "Authentication is in progress, please try again later.", connection: a}
console.js:26 Twilio Error
console.js:26 Object {code: 31002, message: "Authentication is in progress, please try again later.", connection: a}
console.js:26 Object {code: 31002, message: "Authentication is in progress, please try again later.", connection: a}
console.js:26 Twilio Error
console.js:26 Object {code: 31002, message: "Authentication is in progress, please try again later.", connection: a}
console.js:26 [Connection] Disconnecting...
console.js:26 Twilio disconnected
console.js:26 [Twilio.PeerConnection] iceConnectionState is "closed"
console.js:26 [Twilio.PeerConnection] signalingState is "closed"
如果有人能帮助我会很棒。
这是我的typescript类的代码和我用来执行它的脚本:
import { EventEmitter, Injectable } from '@angular/core';
@Injectable()
export class Twilio {
device: any;
token: string;
connection: any;
isConnected = false;
isInitialised = false;
Twilio = (<any>window).Twilio;
public onReady = new EventEmitter<Object>();
public onConnect = new EventEmitter<Object>();
public onDisconnect = new EventEmitter<Object>();
public onError = new EventEmitter<Object>();
public onOffline = new EventEmitter<Object>();
constructor(token: string) {
setTimeout(() => {
this.token = token;
this.setup();
}, 100);
}
public setup() {
this.Twilio.Device.setup(this.token, { debug: true });
if (!(<any>window).cordova) {
this.Twilio.Device.audio.incoming(false);
this.Twilio.Device.audio.disconnect(false);
this.Twilio.Device.audio.outgoing(false);
} else {
this.Twilio.Device.sounds.incoming(false);
this.Twilio.Device.sounds.disconnect(false);
this.Twilio.Device.sounds.outgoing(false);
}
if (this.Twilio.Device.status() == 'ready') {
this.onReady.emit({ isReady: true });
this.isInitialised = true;
}
this.Twilio.Device.ready((device) => {
this.onReady.emit(device);
this.isInitialised = true;
});
this.Twilio.Device.offline(() => {
this.onOffline.emit('');
});
this.Twilio.Device.connect((conn) => {
this.isConnected = true;
this.onConnect.emit('');
});
this.Twilio.Device.disconnect((conn) => {
this.isConnected = false;
this.onDisconnect.emit('');
});
this.Twilio.Device.error((error) => {
console.log(error);
this.onError.emit(error);
});
}
connect(params) {
if (!(<any>window).cordova) {
this.connection = this.Twilio.Device.connect(params);
} else {
this.Twilio.Device.connect(params);
}
}
disconnect() {
if (!(<any>window).cordova) {
try {
this.Twilio.Device.disconnectAll();
} catch (error) {} finally {
this.Twilio.Device.destroy();
}
} else {
this.Twilio.Device.disconnectAll();
}
}
mute(param) {
if (!(<any>window).cordova) {
this.connection.mute(param);
} else {
this.Twilio.Connection.mute();
}
}
speaker(param) {
if ((<any>window).cordova) {
this.Twilio.Connection.setSpeaker((param == true) ? 'on' : 'off');
}
}
sendDigits(digit) {
if (!(<any>window).cordova) {
this.connection.sendDigits(digit);
} else {
this.Twilio.Connection.sendDigits(digit);
}
}
}
this.twilio = new Twilio(VoiceCallService.callToken);
this.twilio.onReady.subscribe(data => {
if (!(<any>window).cordova) {
this.twilio.connect({
"PhoneNumber": this.voiceCall.targetNumber,
"IsTranslated": (VoiceCallService.isTranslated) ? "yes" : "no",
"UserId": Lockr.get('user_id'),
"To": this.voiceCall.targetLanguage,
"From": this.account.details.profile.language,
"FriendId": this.voiceCall.friendId
});
}
});
this.twilio.onConnect.subscribe(data => {
console.log('Twilio connected');
});
this.twilio.onDisconnect.subscribe(data => {
console.log('Twilio disconnected');
});
this.twilio.onError.subscribe(data => {
console.log('Twilio Error');
console.log(data);
});
this.twilio.onOffline.subscribe(data => {
console.log('Twilio offline');
});
if ((<any>window).cordova) {
setTimeout(() => {
this.twilio.connect({
"PhoneNumber": this.voiceCall.targetNumber,
"IsTranslated": (VoiceCallService.isTranslated) ? "yes" : "no",
"UserId": Lockr.get('user_id'),
"To": this.voiceCall.targetLanguage,
"From": this.account.details.profile.language,
"FriendId": this.voiceCall.friendId
});
}, 2000);
}
干杯, 烫发