mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
first cut at implementing TURN
This commit is contained in:
parent
7ce5cdfc4a
commit
af2098327b
@ -513,6 +513,7 @@ export class Session {
|
||||
// TODO: what can we do if this throws?
|
||||
await txn.complete();
|
||||
}
|
||||
await this._updateTurnServers();
|
||||
// enable session backup, this requests the latest backup version
|
||||
if (!this._keyBackup.get()) {
|
||||
if (dehydratedDevice) {
|
||||
@ -559,6 +560,18 @@ export class Session {
|
||||
}
|
||||
}
|
||||
|
||||
async _updateTurnServers() {
|
||||
const turnServersData = await this._hsApi.getTurnServers().response();
|
||||
this._callHandler.setTurnServers({
|
||||
urls: turnServerData.uris,
|
||||
username: turnServerData.username,
|
||||
credential: turnServerData.password,
|
||||
});
|
||||
if (turnServersData.ttl > 0) {
|
||||
setTimeout(this._updateTurnServers, turnServersData.ttl * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
async _getPendingEventsByRoom(txn) {
|
||||
const pendingEvents = await txn.pendingEvents.getAll();
|
||||
return pendingEvents.reduce((groups, pe) => {
|
||||
|
@ -75,6 +75,12 @@ export class CallHandler implements RoomStateHandler {
|
||||
this._loadCallEntries(callEntries, txn);
|
||||
}
|
||||
|
||||
async setTurnServers(turnServers: RTCIceServer) {
|
||||
this.options.turnServers = turnServers;
|
||||
this.groupCallOptions.turnServers = turnServers;
|
||||
// TODO: we should update any ongoing peerconnections if the TURN server details have changed
|
||||
}
|
||||
|
||||
private async _getLoadTxn(): Promise<Transaction> {
|
||||
const names = this.options.storage.storeNames;
|
||||
const txn = await this.options.storage.readTxn([
|
||||
|
@ -309,6 +309,10 @@ export class HomeServerApi {
|
||||
setAccountData(ownUserId: string, type: string, content: Record<string, any>, options?: BaseRequestOptions): IHomeServerRequest {
|
||||
return this._put(`/user/${encodeURIComponent(ownUserId)}/account_data/${encodeURIComponent(type)}`, {}, content, options);
|
||||
}
|
||||
|
||||
getTurnServer(options?: BaseRequestOptions): IHomeServerRequest {
|
||||
return this._get(`/voip/turnServer`, undefined, undefined, options);
|
||||
}
|
||||
}
|
||||
|
||||
import {Request as MockRequest} from "../../mocks/Request.js";
|
||||
|
Loading…
Reference in New Issue
Block a user