mirror of
https://github.com/umap-project/umap.git
synced 2025-05-05 14:01:50 +02:00
chore(sync): Sync engine now retrieves auth token
It's now it's responsability to get the authentication token from the http server and pass it to the websocket server, it will make it possible to redo the roundtrip when getting disconnected.
This commit is contained in:
parent
bfdc87a537
commit
a64690912b
2 changed files with 11 additions and 13 deletions
|
@ -5,7 +5,6 @@ export class SyncEngine {
|
|||
constructor(map) {
|
||||
this.map = map
|
||||
this.receiver = new MessagesDispatcher(this.map)
|
||||
|
||||
this._initialize()
|
||||
}
|
||||
_initialize() {
|
||||
|
@ -15,6 +14,13 @@ export class SyncEngine {
|
|||
this.upsert = this.update = this.delete = noop
|
||||
}
|
||||
|
||||
async authenticate(tokenURI, server) {
|
||||
const [response, _, error] = await this.server.get(tokenURI)
|
||||
if (!error) {
|
||||
this.sync.start(tokenURI, response.token)
|
||||
}
|
||||
}
|
||||
|
||||
start(webSocketURI, authToken) {
|
||||
this.transport = new WebSocketTransport(webSocketURI, authToken, this.receiver)
|
||||
this.sender = new MessagesSender(this.transport)
|
||||
|
|
|
@ -260,18 +260,10 @@ U.Map = L.Map.extend({
|
|||
if (this.options.syncEnabled != true) {
|
||||
this.sync.stop()
|
||||
} else {
|
||||
// FIXME: Do this directly in the sync engine, which should check if the engine
|
||||
// is already started or not.
|
||||
|
||||
// Get the authentication token from the server
|
||||
// And pass it to the sync engine.
|
||||
// FIXME: use `this.urls`
|
||||
const [response, _, error] = await this.server.get(
|
||||
`/map/${this.options.umap_id}/ws-token/`
|
||||
)
|
||||
if (!error) {
|
||||
this.sync.start(this.options.websocketURI, response.token)
|
||||
}
|
||||
const ws_token_uri = this.urls.get('map_websocket_auth_token', {
|
||||
map_id: this.options.umap_id,
|
||||
})
|
||||
await this.sync.authenticate(ws_token_uri, this.server)
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue