index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /**!
  2. * cnpmjs.org - config/index.js
  3. *
  4. * Copyright(c) cnpmjs.org and other contributors.
  5. * MIT Licensed
  6. *
  7. */
  8. 'use strict';
  9. /**
  10. * Module dependencies.
  11. */
  12. if (process.argv.length < 3) {
  13. console.log("ERROR: params not right, usage: pm2 start xxx.js port");
  14. process.exit();
  15. }
  16. //process.env.TZ = 'Asia/Shanghai';
  17. //process.env.TZ = 'Europe/London';
  18. //process.env.TZ = 'UTC';
  19. process.env.TZ = 'Asia/Shanghai';
  20. var path = require('path');
  21. var os = require('os');
  22. var _ = require('underscore');
  23. var root = path.dirname(__dirname);
  24. var redisGlobalPre = 'imxinpi_';
  25. var javaRedisGlobalPre = 'yingtao_';
  26. var allConfig = {
  27. aes_key: "09051825305fd819",
  28. aes_iv: "2dba43c93e7884b9",
  29. slow_log_delta: 30,
  30. testSpeedFile: 'data/tspeed/encode.js',
  31. waitForCon: true,
  32. redisPre: {
  33. uniid_svr_map_key: redisGlobalPre + 'uniid_svr_map_%d',//用户在哪一台机子 参数为userid,value为svr内部host
  34. pack_req_id_key: redisGlobalPre + 'pack_req_id_key', // request 唯一id
  35. sms_vercode_key: redisGlobalPre + 'sms_vercode_%s', // 短信验证码前缀,参数phone+vercode,value vercode
  36. sms_has_send_key: redisGlobalPre + 'sms_has_send_%s', // 短信验证码已生成标识, 参数phone, value vercode
  37. token_uid_map_key: redisGlobalPre + 'token_uid_map_%s', // token 映射uid, 参数 token,value uid
  38. uniid_realip_map_key: redisGlobalPre + 'uid_realip_map_%s', // uid 与登录host映射 参数 uid value host
  39. uniid_https_map_key: redisGlobalPre + 'uid_https_map_%s', // uid 与是否https协议映射 参数: uid,value:is_https
  40. roomid_uniid_map_key: redisGlobalPre + 'roomid_uniid_map_%s', // 主播间场次对应观众, 参数 场次id, value hset uniid score是时间
  41. uniid_roomid_map_key: redisGlobalPre + 'uniid_roomid_map_%s', // uid与主播间场次对应,参数 uniid,value:roomid
  42. uniid_roomid_prefix: redisGlobalPre + 'uniid_roomid_prefix_%s_%s', // 参数 uniid roomid, value: socket_id,con_time
  43. roomid_anchor_map_key: redisGlobalPre + 'roomid_anchor_map_%s', // 直播间场次与主播映射关系,参数:直播场次,value 主播id
  44. timer_id_prefix: redisGlobalPre + 'timer_id_%s', // 定时器前缀 参数:定时器id, value: 无
  45. userid_uni_map_key: redisGlobalPre + 'userid_uni_map_%s', // userid uni映射, 参数: userid value uniid列表
  46. subscribe_prefix: redisGlobalPre + 'subscribe_uniid_%s',//redis订阅key前缀
  47. timer_uniid_roomid_key: redisGlobalPre + 'timer_key_uniid_roomid_%s_%s', // 根据uniid 房间ID设置定时器锁
  48. timer_video_uniid_roomid_key: redisGlobalPre + 'timer_video_key_uniid_roomid_%s_%s', // 根据uniid 房间ID设置定时器-视频锁
  49. job_prefix: redisGlobalPre + 'job_prefix_%s:%s', // db 定时器前缀 参数:dbhost dbport
  50. job_stop_flag: redisGlobalPre + 'job_stop_flag', // db 定时器redis开关
  51. token_device_type_key: redisGlobalPre + 'token_device_type_map_%s', // token device_type
  52. token_sessid_key: redisGlobalPre + 'token_sessid_map_%s', // token sessid
  53. uniid_token_key: redisGlobalPre + 'uniid_token_map_%s', // uniid token
  54. send_req_cb_data: redisGlobalPre + 'send_req_cb_data_%s', // sequence id
  55. live_follow_key: redisGlobalPre + 'live_follow_%s_%s', // 直播间关注状态根据roomid和用户id来判断在该直播间是否关注过
  56. log_collect_next_id_key: redisGlobalPre + 'log_collect_next_id', // log_collect sn生成规则 自增ID
  57. mobile_access_date_key: redisGlobalPre + 'mobile_access_date_key_%s_%s', // 移动端访问日期key
  58. nickname_repleat_key: redisGlobalPre + 'nickname_repleat_key_%s', // 昵称重复锁 key
  59. nickname_change_key: redisGlobalPre + 'nickname_change_key_%s', // 昵称变更锁 key
  60. userid_sessionid_map_key: redisGlobalPre + 'userid_sessionid_map_key_%s', // userid sessionid映射 key
  61. login_reward_coupon_key: redisGlobalPre + 'login_reward_coupon_key_%s', // 登录送券锁 key
  62. haspop_key: redisGlobalPre + 'haspop_key_%s', // 记录用户pop 参数 userid
  63. rtmp_info_key: redisGlobalPre + 'rtmp_id_key_%s_%s', // 记录映射流媒体信息,参数1: stream, 参数2: rtmpid; value: token
  64. ga_user_key: redisGlobalPre + 'ga_user_key_%s_%s_%s_%s', // ga用户key 参数 userid platform type date
  65. page_socket_key: redisGlobalPre + 'page_socket_key_%s', // 用户page_socket redis key 参数 userid
  66. userid_uniid_map_key: redisGlobalPre + 'userid_uniid_map_key_%s', // userid uniid映射 key uniid
  67. hangout_create_room_user_key: redisGlobalPre + 'hangout_create_room_user_key_%s', // 多人直播间创建唯一键 参数 userid
  68. hangout_seat_room_list_key: redisGlobalPre + 'hangout_seat_room_key_%s', // 多人直播间位置list唯一键 参数 roomid
  69. hangout_timer_key: redisGlobalPre + 'hangout_timer_key_%s_%s_%s', // 多人视频定时扣费key room_id anchor_id sub_room_id
  70. userid_login_ip_info_key: redisGlobalPre + 'userid_login_ip_info_key_%s', // 用户登录记录IP信息 映射 key userid
  71. hangout_view_timer_key: redisGlobalPre + 'hangout_view_timer_key_%s', // 多人视频双向视频扣费key room_id
  72. live_show_timer_key: redisGlobalPre + 'live_show_timer_key_%s_%s', // 节目直播间扣费key 映射 key room_id userid
  73. anchor_enter_public_room_key: redisGlobalPre + 'anchor_enter_public_room_key_%s', // 主播进入公开直播间key 映射 key anchor_id
  74. next_expire_id_key: redisGlobalPre + 'next_expire_id_key_%s', // 生成会过期的唯一id 用于生成socketid用
  75. /***********以上redis为框架用**********/
  76. room_info_key: redisGlobalPre + 'room_info_%s', // 记录房间信息
  77. room_audio_channel_key: redisGlobalPre + 'room_audio_channel', // 记录房间信息
  78. default_audio_channel_key: redisGlobalPre + 'default_audio_channel', // 记录房间信息
  79. room_blacklist_key: redisGlobalPre + 'room_blacklist_%s', // 记录房间黑名单信息
  80. room_mute_key: redisGlobalPre + 'room_mute_%s', // 记录房间禁言信息
  81. room_manager_key: redisGlobalPre + 'room_manager_%s', // 记录房间角色信息
  82. user_info_key: redisGlobalPre + 'user_info_%s', // 记录用户信息
  83. user_map_socket_key: redisGlobalPre + 'user_map_socket_key_%s', //存用户对应所有socket
  84. roomid_map_uid_key: redisGlobalPre + 'roomid_map_uid_key_%s', // 存房间用户列表
  85. roomid_map_socket_key: redisGlobalPre + 'roomid_map_socket_key_%s', // 存房间socket列表
  86. socket_map_room_key: redisGlobalPre + 'socket_map_room_key_%s', // 方向存socket在哪些房间
  87. uid_room_map_socket_key: redisGlobalPre + 'uid_room_map_socket_key_%s_%s', // 存某个用户在某个房间有哪些socket
  88. room_map_queue_mem_key: redisGlobalPre + 'room_map_queue_mem_key_%s', // 存房间对应成员信息
  89. room_live_sortedset_key: redisGlobalPre + 'room_live_zset_key', // 存所有有活人的房间,数据类型:sorted set
  90. public_roomid_map_socketid_zset_key: redisGlobalPre + 'public_roomid_map_socketid_zset_key_%s',
  91. public_roomid_map_uid_zset_key: redisGlobalPre + 'public_roomid_map_uid_zset_key_%s',
  92. public_socketid_map_roomid_zset_key: redisGlobalPre + 'public_socketid_map_roomid_zset_key_%s',
  93. public_room_history_zset_key: redisGlobalPre + 'public_room_history_zset_key_%s',
  94. stream_uid_map_streamid_key: redisGlobalPre + 'stream_uid_map_streamid_key_%s',
  95. stream_uid_map_streamsvrid_key: redisGlobalPre + 'stream_uid_map_streamsvrid_key_%s',
  96. enter_room_white_list: redisGlobalPre + 'enter_room_white_list',
  97. /********以下key为获取java服务器端设置的redis用********/
  98. uid_ticket: javaRedisGlobalPre + 'uid_ticket', // 存储 uid 和 ticket关系的key
  99. room_mic_list: javaRedisGlobalPre + 'room_mic_list_%s', // 存储坑位信息
  100. room_room_id: javaRedisGlobalPre + 'room_room_id',
  101. uid_type_map_room_info: javaRedisGlobalPre + 'room', // uid map room
  102. },
  103. anchor_instant_invite_num: { //主播立即邀请男士数量限制
  104. level1: 99999,
  105. level2: 99999,
  106. level3: 99999,
  107. level4: 99999,
  108. level5: 99999
  109. },
  110. anchor_scheduled_invite_num: { //主播预约邀请男士数量限制
  111. level1: 5,
  112. level2: 10,
  113. level3: 15,
  114. level4: 20,
  115. level5: 25
  116. },
  117. anchor_invite_user_num: 3, // 主播邀请同一个用户发送的最大次数
  118. anchor_invite_user_time: 600, // 主播邀请同一个用户发送邀请最低间隔时间 秒
  119. session: {
  120. key: 'xhlive_sess', // cookie 前缀
  121. prefix: 'xhlive_sess:', // session 前缀
  122. ttl: 28800, // session:28800 过期时间 8个小时,单位秒(登录会话)
  123. site_ttl: 5 * 60//统计网站信息会话
  124. },
  125. // cookie:{
  126. // domain: 'charmdate.com'//'192.168.88.17',//
  127. // //maxage: null
  128. // },
  129. tips: {
  130. '1': '你被管理员请出房间',
  131. '2': '拉黑名单踢出',
  132. '3': '网络异常,正在尝试重连',
  133. '1000001': '欢迎%s进入直播间',
  134. '1000002': 'Your scheduled show start in %smin, please get prepared.', // 节目开始前10分钟主播通知
  135. '1000003': 'Show Calendar are the calendars of specially scheduled broadcasts arranged by broadcasters.', //节目描述
  136. '1000004': 'You current broadcast will be ended in 30 seconds and your scheduled show "%s" is starting in 4 minutes. Please get prepared.', // 公开直播间因节目被迫关闭公告
  137. '1000005': 'Welcome to the show %s. This show started from %s minutes ago and the show duration is %s minutes. Enjoy!', // 男士节目入场公告
  138. '1000006': 'Your show "%s" just started and the show duration is %s minutes. Enjoy!', // 女士节目入场公告
  139. '1000007': 'The show will be ended in 30 seconds. Please be prepared.', // 节目结束公告
  140. '1000008': 'Your show is starting in %s minutes.Please click to start now.', // 女士 节目前3分钟对应通知
  141. '1000009': '%s\'s show is ready to start. Join the show now.', // 男士节目前 1分钟通知
  142. '1000010': 'Price: 0.3 credits per minute for each broadcaster participated.', // 多人直播间消费提示
  143. '1000011': 'Your show is starting in %s minutes.Please be prepared.', // 女士 节目前10分钟对应通知
  144. '1000012': 'Your show is starting in %s minute.Please click to start now.', // 女士 节目前1分钟对应通知
  145. '1000013': '%s is on show now.',
  146. },
  147. // 主分支 用户错误码12000 主播错误码16500
  148. // hangout分支 用户错误码11000 主播错误码16300
  149. // live_show分支 用户错误码13000 主播错误码16600
  150. // 框架错误 17000 ~ 18000
  151. // 18000-18100主播后台列表私信错误码
  152. err_msg: {
  153. "10001": "We could not complete your request. Error code: (10001).",
  154. "10002": "Please login to continue your action.",
  155. "10003": "An error occurs while connecting to the server",
  156. "10004": "Your authorization has expired. Please login again.",
  157. "10005": "We could not complete your request. Error code: (10005).",
  158. "10006": "Invalid authentication. Please login and try again.",
  159. "10007": "Could not view this page due to the permission limit. Code: (10007)",
  160. "10008": "Could not send message. Code: (10008)",
  161. "10009": "Failed to send virtual gift. Code: (10009)",
  162. "10010": "You don't have enough #credit_unit_preg#s to continue this action. Please add more #credit_unit_preg#s and try again.",
  163. "10011": "You has been kickoff.", // 已经不使用
  164. "10012": "setTimeout param is too large.",
  165. "10013": "You don't have enough #credit_unit_preg#s to continue this action. Please add more #credit_unit_preg#s and try again.",// 发送弹幕金币不足
  166. "10014": "setInterval param is too large.",
  167. "10015": "Broadcast room has ended. Please check back later.",
  168. "10017": "Failed to delete this image.",
  169. "10018": "Invalid authorization. Please login and try again.",
  170. "10019": "Your operation has been blocked due to too many invalid attempts.",
  171. "10020": "Incorrect broadcaster ID or password.",//主播登录,账号或密码错误
  172. "10021": "Broadcast has ended. Please check back later.", // 进入房间失败 找不到房间信息or房间关闭
  173. "10022": "Unknown error occurred. Please reload this page.", // 进入房间失败 数据库操作失败(添加记录or删除扣费记录)
  174. "10037": "你的账号在其他设备登录.",
  175. /** [100100 - 100200) login接口使用 **/
  176. "100100": "im登录鉴权失败",
  177. "100101": "获取用户信息失败",
  178. /** [100200 - 100300) enterChatRoom接口使用 **/
  179. "100200": "获取房间信息失败",
  180. "100201": "用户房间socketId不存在",
  181. "100202": "用户在房间黑名单中",
  182. "100203": "房间不存在",
  183. "100204": "声音渠道不存在",
  184. /** [100300 - 100400) queue接口使用 **/
  185. "100300": "队列位置权限控制",
  186. "100301": "只能操作比自己低权限的用户",
  187. "100302": "没有上麦不能推流",
  188. "100303": "当前麦位已经有人",
  189. /** [100400 - 100500) 房间用户角色和黑名单接口使用 **/
  190. "100400": "用户已在黑名单",
  191. "100401": "用户不在黑名单",
  192. "100402": "用户已是管理员",
  193. "100403": "用户不是管理员",
  194. "100404": "用户不存在",
  195. "100405": "操作权限不足",
  196. "100406": "用户已经禁言",
  197. /** [100500 - 100600) 踢出成员接口 **/
  198. "100500": "你被管理员请出房间",
  199. /** [100600 - 100700) 公屏接口返回吗 **/
  200. "100601": "错误的公聊大厅",
  201. },
  202. lock_key: {
  203. room_key: "room_",
  204. invitation_scheduled_key: "invitation_scheduled_userid_%s", // 预约邀请key 预约ID
  205. interim_consume_key: "interim_consume_%s_%s", // 临时扣费key userid roomid
  206. user_online_status_key: "user_online_status_%s", // 用户在线状态key userid
  207. report_speed_key: "report_speed_key_%s_%s", // 记录测速结果 参数1 svrid,参数2 userid
  208. reward_key: "reward_key_%s", // 活动送奖品 参数1 userid
  209. send_gift_key: "send_gift_key_%s_%s_%s", // 发生礼物 参数1 userid 参数2 礼物类型 参数3 anchor_id
  210. hangout_timer_consume_key: "hangout_timer_consume_key_%s_%s_%s", // 多人视频定时扣费 参数 room_id anchor_id sub_room_id
  211. hangout_view_consume_key: "hangout_view_consume_key_%s", // 多人视频双向视频扣费 参数 room_id
  212. //program_time:"program_%s", // 主播接受预约时间块锁
  213. program_time: "program", // 主播接受预约全局锁
  214. enter_show_lock_key: "enter_show_lock_key_%s", // 用户进入节目直播间锁 参数 room_id
  215. room_queue: "room_queue_", // 房间队列锁
  216. },
  217. thumb_suffix: {
  218. high: "_960x720",
  219. middle: "_640x480",
  220. low: "_320x240",
  221. },
  222. SMS: {
  223. sms_url: 'http://101.227.68.49:7891/mt?',
  224. sms_user: '10690212',
  225. sms_pwd: 'qiYIg2016',
  226. },
  227. verCode_config: {
  228. "valid_time": 600,//验证码有效期
  229. "remake_interval": 60,//重新生成时间间隔
  230. "tpl": "【%s】thank you for you register,your identifying code is %s, duration of validity is %sseconds",
  231. },
  232. appName: "oklive",
  233. nickNamePrefix: "LIVE-",
  234. token_expire_time: 7200, // 7200秒
  235. RTMP_FLAG: '#RTMPToBeFitWithDomain#',
  236. //RTMP_HOST:'192.168.88.17',
  237. blurry_key: 'wpt76ke84ly8bj9e',
  238. rtmp_push_url: [
  239. "rtmp://#RTMPToBeFitWithDomain#:1936/speex/anchor_%s_%s"
  240. ],
  241. rtmp_pull_url: [
  242. "rtmp://#RTMPToBeFitWithDomain#:1936/speex/anchor_%s_%s"
  243. ],
  244. fansi_rtmp_push_url: [
  245. "rtmp://#RTMPToBeFitWithDomain#:1936/speex/fansi_%s_%s"
  246. ],
  247. fansi_rtmp_pull_url: [
  248. "rtmp://#RTMPToBeFitWithDomain#:1936/speex/fansi_%s_%s"
  249. ],
  250. rtmp_kickoff_api: "http://%s:%s/verify/v1/kickoff",
  251. pic_prefix: "#ToBeFittedWithDomain#",
  252. request_prefix: "#ToBeFromWithDomain#",
  253. is_open_sql_redis: true, //是否开启查看缓存
  254. };
  255. // 通过NODE_ENV来设置环境变量,如果没有指定则默认为生产环境
  256. console.log('当前环境');
  257. console.log(process.env.NODE_ENV);
  258. var env = process.env.NODE_ENV || 'development';
  259. console.log(env);
  260. env = env.toLowerCase();
  261. // C.env 为运行环境
  262. allConfig.env = env;
  263. // 载入配置文件
  264. var file = path.resolve(__dirname, env + '.js');
  265. try {
  266. var envConfig = require(file);
  267. var config = _.extend(allConfig, envConfig);
  268. //console.log('Load config: [%s] %s', env, file);
  269. } catch (err) {
  270. console.error('Cannot load config: [%s] %s', env, file);
  271. throw err;
  272. }
  273. //加载debug文件,用于覆盖index.js中的变量
  274. if (config.is_debug) {
  275. // 载入qn配置文件
  276. var qn_file = path.resolve(__dirname, 'debug.js');
  277. try {
  278. var qn_conf = require(qn_file);
  279. config = _.extend(config, qn_conf);
  280. } catch (err) {
  281. console.error('Cannot load config: debug.js');
  282. throw err;
  283. }
  284. }
  285. // 载入基础配置文件
  286. var basic_file = path.resolve(__dirname, 'basic.js');
  287. try {
  288. var basic_file = require(basic_file);
  289. config = _.extend(config, basic_file);
  290. //console.log('Load config: [%s] %s', env, file);
  291. } catch (err) {
  292. console.error('Cannot load config: qn_conf.js');
  293. throw err;
  294. }
  295. module.exports = config;