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

29 lines
942 B
TypeScript
Raw Normal View History

import * as loader from "tc-loader";
2019-10-25 19:51:40 -04:00
import {AddressTarget, ResolveOptions} from "tc-shared/dns";
import * as dns_handler from "tc-native/dns";
2020-09-24 16:06:52 -04:00
import {ServerAddress} from "tc-shared/tree/Server";
2019-10-25 19:51:40 -04:00
2020-12-02 12:08:49 -05:00
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 => {
2020-12-02 12:08:49 -05:00
if(typeof(result) === "string") {
reject(result);
2020-12-02 12:08:49 -05:00
} else {
resolve({
target_ip: result.host,
target_port: result.port
});
2020-12-02 12:08:49 -05:00
}
});
})
2019-10-25 19:51:40 -04:00
}
2020-09-24 16:06:52 -04:00
export function supported() { return true; }
2019-10-25 19:51:40 -04:00
loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, {
name: "Native DNS initialized",
function: async () => {
dns_handler.initialize();
},
priority: 10
});