Last active
February 29, 2016 17:38
-
-
Save chchrist/1b7d2cd2c6ed03b0b185 to your computer and use it in GitHub Desktop.
cometd postpone handshake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import $ from 'jquery'; | |
class AuthenticatorExt { | |
constructor(options) { | |
this.tokenUrl = options.tokenUrl; | |
this.memberId = options.memberId; | |
this.isPendingHanshake = false; | |
} | |
registered(name, cometd) { | |
this.cometd = cometd; | |
} | |
incoming(message) { | |
if (message.channel === '/meta/handshake' && this.isPendingHanshake) { | |
this.isPendingHanshake = false; | |
} | |
} | |
outgoing(message) { | |
if (message.channel === '/meta/handshake' && !this.isPendingHanshake) { | |
this.isPendingHanshake = true; | |
this._getToken().then(token => { | |
this.cometd.handshake({ | |
ext: { | |
authentication: { | |
memberId: this.memberId, | |
token: token, | |
} | |
} | |
}) | |
}).catch(res => { | |
//TODO something meaningful | |
}) | |
return false; | |
} | |
} | |
_getToken() { | |
return new Promise((resolve, reject) => { | |
$.ajax({ | |
url: this.tokenUrl, | |
xhrFields: { | |
withCredentials: true | |
} | |
}).then(token => { | |
resolve(token); | |
}).fail(e => { | |
reject(e); | |
}); | |
}); | |
} | |
} | |
export default AuthenticatorExt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 18: perhaps you should check also for
message.successful
?Line 38: you must return
null
.