jessibucaConfig.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Jessibuca 播放器配置
  3. */
  4. export const getJessibucaConfig = (container) => {
  5. return {
  6. container, // 播放器容器
  7. videoBuffer: 0.5, // 视频缓冲区时长,单位:秒
  8. audioBuffer: 0.5, // 音频缓冲区时长,单位:秒
  9. debug: true, // 是否开启调试模式
  10. forceNoOffscreen: true, // 是否强制不使用离屏模式
  11. isResize: true, // 是否根据容器自动调整大小
  12. isFullResize: false, // 是否全屏模式调整大小
  13. text: '视频加载中...', // 加载过程中的提示文本
  14. loadingText: '加载中...',
  15. background: '#000000', // 背景色
  16. controlAutoHide: false, // 控制栏是否自动隐藏
  17. showBandwidth: true, // 是否显示网速
  18. operateBtns: {
  19. fullscreen: true, // 是否显示全屏按钮
  20. screenshot: true, // 是否显示截图按钮
  21. play: true, // 是否显示播放按钮
  22. audio: true, // 是否显示声音按钮
  23. recording: false // 是否显示录制按钮
  24. },
  25. supportDblclickFullscreen: true, // 是否支持双击全屏
  26. showBandwidthPosition: 'controls', // 显示网速的位置
  27. keepScreenOn: true, // 是否保持屏幕常亮
  28. hotKey: true, // 是否支持热键
  29. loadingTimeout: 10, // 视频加载超时时间,单位:秒
  30. // 指定解码器文件路径
  31. decoder: process.env.BASE_URL + 'decoder.js',
  32. wasmUrl: process.env.BASE_URL + 'decoder.wasm',
  33. // 解码配置
  34. decoderConfig: {
  35. // 解码类型,可选值:'software', 'hardware'
  36. type: 'auto',
  37. // 是否优先使用 WASM 解码
  38. preferWasm: true,
  39. // 是否使用 Worker 进行解码
  40. useWorker: true,
  41. // 是否使用 SIMD 加速
  42. useSIMD: true,
  43. // 是否使用 WebGL 渲染
  44. useWebGL: true,
  45. },
  46. // 视频渲染配置
  47. render: {
  48. // 是否开启抗锯齿
  49. antialias: true,
  50. // 是否使用 WebGL2
  51. useWebGL2: true,
  52. // 是否使用 YUV 渲染
  53. yuv: true,
  54. },
  55. // 网络配置
  56. network: {
  57. // 是否开启 HTTP 请求超时
  58. timeout: 10000,
  59. // 是否开启重试
  60. retry: true,
  61. // 重试次数
  62. retryCount: 3,
  63. // 重试间隔,单位:毫秒
  64. retryDelay: 1000,
  65. }
  66. };
  67. };
  68. /**
  69. * 根据视频格式获取 Jessibuca 播放地址
  70. * @param {string} url - 原始 URL
  71. * @param {string} format - 视频格式
  72. * @returns {string} - 处理后的 URL
  73. */
  74. export const getJessibucaUrl = (url, format) => {
  75. // 对于 WebSocket 格式,确保 URL 以 ws:// 或 wss:// 开头
  76. if (format === 'ws' && !url.startsWith('ws://') && !url.startsWith('wss://')) {
  77. return `ws://${url.replace(/^https?:\/\//, '')}`;
  78. }
  79. // 对于 FLV 格式,确保 URL 正确
  80. if (format === 'flv' && !url.includes('.flv') && !url.includes('?') && !url.includes('=')) {
  81. // 如果 URL 不包含 .flv 后缀且没有查询参数,尝试添加 .flv 后缀
  82. return `${url}.flv`;
  83. }
  84. // 对于 HLS/M3U8 格式,确保 URL 正确
  85. if ((format === 'hls' || format === 'm3u8') && !url.includes('.m3u8') && !url.includes('?') && !url.includes('=')) {
  86. // 如果 URL 不包含 .m3u8 后缀且没有查询参数,尝试添加 .m3u8 后缀
  87. return `${url}.m3u8`;
  88. }
  89. return url;
  90. };