From 29466f616f998a0979977a45d39d8faf2df870a5 Mon Sep 17 00:00:00 2001
From: xc <double72cheng@gmail.com>
Date: Mon, 26 Apr 2021 17:10:45 +0800
Subject: [PATCH] 插件化 直播
---
src/main/resources/public/js/live/livepler.js | 74 ++++++++++++++++++++++++++++++++-----
1 files changed, 64 insertions(+), 10 deletions(-)
diff --git a/src/main/resources/public/js/live/livepler.js b/src/main/resources/public/js/live/livepler.js
index cb73411..2c8268c 100755
--- a/src/main/resources/public/js/live/livepler.js
+++ b/src/main/resources/public/js/live/livepler.js
@@ -1,7 +1,4 @@
;!(function () {
- window.onkeydown = function () {
- h5lc.fullscreen = false
- }
let _content = $("<div class=\"content\">\n" +
" <div class=\"player\" onmouseover=\"$('.player .control').css('display', 'block')\" onmouseout=\"$('.player .control').css('display', 'none')\">\n" +
@@ -21,16 +18,73 @@
" </div>");
$("#jessibucaContainer").append(_content);
+ var $play = document.getElementById('play');
+ var $stop = document.getElementById('stop');
- function constructLive(opt) {
- this._opt = opt;
- if (typeof opt.container === "string") {
- this._opt.container = document.getElementById(opt.container);
+ var $jessibucaContainer = document.getElementById('jessibucaContainer');
+
+
+ function Livepler(opt) {
+ if (typeof opt.elem === 'string') {
+ opt.elem = document.getElementById(opt.elem);
}
- if (!this._opt.container) {
- throw new Error('Jessibuca need container option');
+ if (!opt.elem) {
+ throw new Error('需要容器');
return;
}
+ let stream_path;
-}})()
+ this.elem = opt.elem;
+ let ffurl = opt.ffurl;
+ let code = opt.code;
+ this.container = document.getElementById("container");
+
+ let h5lc = new Jessibuca({container, decoder: ffurl, videoBuffer: 0});
+ this.playVideo(code,function (result) {
+ h5lc.onLoad=function () {
+ this.play(result.jessicaURL);
+ }
+ stream_path=result.streamPath;
+ $play.style.display = 'none';
+ $stop.style.display = 'inline';
+ })
+
+ let $close = document.getElementById('close');
+ let than = this;
+ //关闭
+ $close.addEventListener('click', function () {
+ h5lc.destroy();
+ than.closeVideo(stream_path)
+ than.elem.style.display = 'none';
+ }, false);
+ }
+
+ Livepler.prototype.playVideo = function (video_id, callback) {
+ $.ajax({
+ type: "get",
+ //url: "../../webapi/media/live?param=" + video_id,
+ url: "../../monica/live?param=" + video_id,
+ timeout: 5000,
+ async: false,
+ success: function (result) {
+ callback(result);
+ }
+ });
+ }
+
+ Livepler.prototype.closeVideo = function (streamPath) {
+ if (streamPath && typeof streamPath === "string") {
+ $.ajax({
+ type: "get",
+ //url: "../../webapi/media/stop?param=" + streamPath,
+ url: "../../monica/stop?param=" + streamPath,
+ async: false,
+ success: function (result) {
+ }
+ });
+ }
+ }
+
+ window.Livepler = Livepler;
+})()
--
Gitblit v1.9.1