TeaSpeak-Client/modules/renderer/dns/dns_resolver.ts
2020-12-02 18:08:49 +01:00

29 lines
942 B
TypeScript

import * as loader from "tc-loader";
import {AddressTarget, ResolveOptions} from "tc-shared/dns";
import * as dns_handler from "tc-native/dns";
import {ServerAddress} from "tc-shared/tree/Server";
export function resolve_address(address: ServerAddress, _options?: ResolveOptions) : Promise<AddressTarget> {
return new Promise<AddressTarget>((resolve, reject) => {
dns_handler.resolve_cr(address.host, address.port, result => {
if(typeof(result) === "string") {
reject(result);
} else {
resolve({
target_ip: result.host,
target_port: result.port
});
}
});
})
}
export function supported() { return true; }
loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, {
name: "Native DNS initialized",
function: async () => {
dns_handler.initialize();
},
priority: 10
});