import RoapRequest from './request'; import Meeting from '../meeting'; import { TurnDiscoverySkipReason, TurnDiscoveryResult } from './types'; /** * Handles the process of finding out TURN server information from Linus. * This is achieved by sending a TURN_DISCOVERY_REQUEST. */ export default class TurnDiscovery { private roapRequest; private defer?; private turnInfo; private responseTimer?; /** Resets the turnInfo structure to the defaults * @returns {void} */ private resetTurnInfo; /** * Constructor * * @param {RoapRequest} roapRequest */ constructor(roapRequest: RoapRequest); /** * waits for TURN_DISCOVERY_RESPONSE message to arrive * * @returns {Promise} * @private * @memberof Roap */ private waitForTurnDiscoveryResponse; /** * Handles TURN_DISCOVERY_RESPONSE roap message. Use it if the roap message comes over the websocket, * otherwise use handleTurnDiscoveryHttpResponse() if it comes in the http response. * * @param {Object} roapMessage * @param {string} from string to indicate how we got the response (used just for logging) * @returns {void} * @public * @memberof Roap */ handleTurnDiscoveryResponse(roapMessage: any, from: string): void; /** * Generates TURN_DISCOVERY_REQUEST roap message. When this method returns a roapMessage, it means that a TURN discovery process has started. * It needs be ended by calling handleTurnDiscoveryHttpResponse() once you get a response from the backend. If you don't get any response * or want to abort, you need to call abort(). * * @param {Meeting} meeting * @param {boolean} isForced * @returns {Object} */ generateTurnDiscoveryRequestMessage(meeting: Meeting, isForced: boolean): Promise<{ roapMessage?: object; turnDiscoverySkippedReason: TurnDiscoverySkipReason; }>; /** * Handles any errors that occur during TURN discovery without re-throwing them. * * @param {Meeting} meeting * @param {Error} error * @returns {TurnDiscoveryResult} */ private handleTurnDiscoveryFailure; /** * Handles TURN_DISCOVERY_RESPONSE roap message that came in http response. If the response is not valid, * it returns an object with turnServerInfo set to undefined. In that case you need to call abort() * to end the TURN discovery process. * * @param {Meeting} meeting * @param {Object|undefined} httpResponse can be undefined to indicate that we didn't get the response * @returns {Promise} * @memberof Roap */ handleTurnDiscoveryHttpResponse(meeting: Meeting, httpResponse?: object): Promise; /** * Aborts current TURN discovery. This method needs to be called if you called generateTurnDiscoveryRequestMessage(), * but then never got any response from the server. * @returns {void} */ abort(): void; /** * Parses the TURN_DISCOVERY_RESPONSE roap message out of the http response * and returns it. * * @param {Meeting} meeting * @param {any} httpResponse * @returns {any} */ private parseHttpTurnDiscoveryResponse; /** * sends the TURN_DISCOVERY_REQUEST roap request * * @param {Meeting} meeting * @param {Boolean} isReconnecting * @returns {Promise} * @private * @memberof Roap */ private sendRoapTurnDiscoveryRequest; /** * Sends the OK message that server expects to receive * after it sends us TURN_DISCOVERY_RESPONSE * * @param {Meeting} meeting * @returns {Promise} */ sendRoapOK(meeting: Meeting): Promise<{ mediaConnections: any; locus: any; }>; /** * Gets the reason why reachability is skipped. * * @param {Meeting} meeting * @returns {Promise} Promise with empty string if reachability is not skipped or a reason if it is skipped */ private getSkipReason; /** * Checks if TURN discovery is skipped. * * @param {Meeting} meeting * @returns {Boolean} true if TURN discovery is being skipped, false if it is being done */ isSkipped(meeting: any): Promise; /** * Retrieves TURN server information from the backend by doing * a roap message exchange: * client server * | -----TURN_DISCOVERY_REQUEST-----> | * | <----TURN_DISCOVERY_RESPONSE----- | * | --------------OK----------------> | * * This TURN discovery roap exchange is always done with seq=0. * The RoapMediaConnection SDP exchange always starts with seq=1, * so it works fine no matter if TURN discovery is done or not. * * @param {Meeting} meeting * @param {Boolean} [isReconnecting] should be set to true if this is a new * media connection just after a reconnection * @param {Boolean} [isForced] * @returns {Promise} */ doTurnDiscovery(meeting: Meeting, isReconnecting?: boolean, isForced?: boolean): Promise; }