我有以下代码:
openTokInit() {
this.session = OT.initSession(this.tokboxApiKey, this.sessionId);
const self = this;
this.session.on('connectionCreated', function(event) {
self.connectionCount++;
});
if (this.connectionCount < 2) {
this.session.connect(this.token, err => {
if (err) {
reject(err);
} else {
resolve(this.session);
}
});
}
Run Code Online (Sandbox Code Playgroud)
问题是当 if 语句运行时,connectionCount 始终为 0,因为 'connectionCreated' 事件在几秒钟后被触发。我不清楚如何在连接新会话之前适当地等待所有 connectionCreated 事件触发。