本文整理汇总了TypeScript中Q.nbind函数的典型用法代码示例。如果您正苦于以下问题:TypeScript nbind函数的具体用法?TypeScript nbind怎么用?TypeScript nbind使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了nbind函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: upnpConf
async function upnpConf (noupnp:boolean, logger:any) {
const client = require('nat-upnp').createClient();
// Look for 2 random ports
const publicPort = await getAvailablePort(client)
const privatePort = publicPort
const conf:NetworkConfDTO = {
proxiesConf: undefined,
nobma: true,
bmaWithCrawler: false,
port: privatePort,
ipv4: '127.0.0.1',
ipv6: '::1',
dos: null,
upnp: false,
httplogs: false,
remoteport: publicPort,
remotehost: null,
remoteipv4: null,
remoteipv6: null
}
logger && logger.info('Checking UPnP features...');
if (noupnp) {
throw Error('No UPnP');
}
const publicIP = await Q.nbind(client.externalIp, client)();
await Q.nbind(client.portMapping, client)({
public: publicPort,
private: privatePort,
ttl: BMAConstants.UPNP_TTL
});
const privateIP = await Q.Promise((resolve:any, reject:any) => {
client.findGateway((err:any, res:any, localIP:any) => {
if (err) return reject(err);
resolve(localIP);
});
});
conf.remoteipv4 = publicIP.match(BMAConstants.IPV4_REGEXP) ? publicIP : null;
conf.remoteport = publicPort;
conf.port = privatePort;
conf.ipv4 = privateIP.match(BMAConstants.IPV4_REGEXP) ? privateIP : null;
return conf;
}
示例2: getAvailablePort
async function getAvailablePort(client:any) {
const mappings:{ public: { port:number }}[] = await Q.nbind(client.getMappings, client)();
const externalPortsUsed = mappings.map(m => m.public.port)
let availablePort = BMAConstants.BMA_PORTS_START
while (externalPortsUsed.indexOf(availablePort) !== -1 && availablePort <= BMAConstants.BMA_PORTS_END) {
availablePort++
}
if (availablePort > BMAConstants.BMA_PORTS_END) {
throw "No port available for UPnP"
}
return availablePort
}
示例3: findGateway
async findGateway() {
try {
const client = upnp.createClient();
const res = await Q.nbind(client.findGateway, client)();
const desc = res && res[0] && res[0].description;
if (desc) {
const match = desc.match(/(\d+.\d+.\d+.\d+):/);
if (match) {
return match[1];
}
}
return null;
} catch (e) {
return null;
}
}
示例4: function
export const Upnp = async function (localPort:number, remotePort:number, logger:any, conf:ConfDTO) {
"use strict";
logger.info('UPnP: configuring...');
const api = new UpnpApi(localPort, remotePort, logger, conf)
try {
await api.openPort()
} catch (e) {
const client = upnp.createClient();
try {
await Q.nbind(client.externalIp, client)();
} catch (err) {
if (err && err.message == 'timeout') {
throw 'No UPnP gateway found: your node won\'t be reachable from the Internet. Use --noupnp option to avoid this message.'
}
throw err;
} finally {
client.close();
}
}
return api
};
示例5: require
const _ = require('lodash')
const FS = require('fs')
const Q = require('q')
const glob = require('glob')
const sass = require('node-sass')
let globSearch = Q.denodeify(glob)
let sassRender = Q.nbind(sass.render, sass)
let writeFile = Q.denodeify(FS.writeFile)
let sassDefaults = {
includePaths: [
],
indentedSyntax: true
}
globSearch('src/**/*.scss')
.then((files) => {
var result = Q()
files.forEach((srcFile) => {
result = result
.then(() => {
let dstFile = srcFile.replace(/\.scss$/i, '.css')
return buildSassFile(srcFile, dstFile)
})
})
return result
})
.then(() => {
console.log('Compiled CSS files.')
})
.catch((err) => {