Files
tl-rtc-file/src/controller/comm/comm.js
https://blog.iamtsm.cn 491b05f7a8 feat: node code perf
2023-04-21 22:32:23 +08:00

33 lines
734 B
JavaScript

const utils = require("../../utils/utils");
const conf = require("../../../conf/cfg.json");
const wsConf = conf.ws;
const webrtcConf = conf.webrtc;
/**
* 获取ip地址,初始化等相关配置
* @param {*} req
* @param {*} res
*/
function initData(req, res) {
let regexIP = /^((?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d))$/;
let ip = utils.getLocalIP();
if (!regexIP.test(ip)) {
ip = utils.getClientIP(req)
}
if (!regexIP.test(ip)) {
ip = "127.0.0.1"
}
let data = {
wsHost: wsConf.ws_online ? wsConf.ws_online : "ws://" + ip + ":" + wsConf.port,
rtcConfig: { iceServers: webrtcConf.iceServers },
options: webrtcConf.options
};
res.json(data)
}
module.exports = {
initData,
}