TeaSpeak-Client/modules/renderer/dns/dns_resolver.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2019-06-26 16:09:01 -04:00
/// <reference path="../imports/imports_shared.d.ts" />
window["require_setup"](module);
2019-10-24 12:41:23 -04:00
import * as dns_handler from "teaclient_dns";
2019-06-26 16:09:01 -04:00
namespace _dns {
export function supported() { return true; }
2019-10-24 12:41:23 -04:00
export async function resolve_address(address: ServerAddress, _options?: dns.ResolveOptions) : Promise<dns.AddressTarget> {
/* backwards compatibility */
if(typeof(address) === "string") {
address = {
host: address,
port: 9987
2019-06-26 16:09:01 -04:00
}
}
2019-10-24 12:41:23 -04:00
return new Promise<dns.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
});
2019-06-26 16:09:01 -04:00
});
2019-10-24 12:41:23 -04:00
})
2019-06-26 16:09:01 -04:00
}
}
2019-10-24 12:41:23 -04:00
Object.assign(window["dns"] || (window["dns"] = {} as any), _dns);
loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, {
name: "Native DNS initialized",
function: async () => {
dns_handler.initialize();
},
priority: 10
});