PlaybackVideoDlg.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div :class="['modal', { fade: fade }]" data-keyboard="true" data-backdrop="static" tabindex="-1">
  3. <div class="modal-dialog modal-lg">
  4. <div class="modal-content">
  5. <div class="modal-header">
  6. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  7. <span aria-hidden="true">&times;</span>
  8. </button>
  9. <h4 class="modal-title text-primary text-center"><span>{{videoTitle}}</span></h4>
  10. </div>
  11. <div class="modal-body">
  12. <LivePlayer v-if="bShow" :videoUrl="videoUrl" :snapUrl="snapUrl" :live="live" muted
  13. @message="$message" :loading.sync="bLoading" v-loading="bLoading" element-loading-text="加载中"></LivePlayer>
  14. <div class="text-center text-gray" v-if="isDemoUser(serverInfo, userInfo)">
  15. <br>
  16. 提示: 演示系统限制匿名登录播放时间, 若需测试长时间播放, 请<a target="_blank" href="//www.liveqing.com/docs/download/LiveGBS.html">下载使用</a>
  17. </div>
  18. </div>
  19. <div class="modal-footer">
  20. <button type="button" class="btn btn-primary" @click.prevent="scale(1)">x1</button>
  21. <button type="button" class="btn btn-primary" @click.prevent="scale(2)">x2</button>
  22. <button type="button" class="btn btn-primary" @click.prevent="scale(4)">x4</button>
  23. <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import "jquery-ui/ui/widgets/draggable";
  31. import LivePlayer from "@liveqing/liveplayer";
  32. import { mapState } from "vuex";
  33. export default {
  34. data() {
  35. return {
  36. videoUrl: "",
  37. videoTitle: "",
  38. snapUrl: "",
  39. serial: "",
  40. code: "",
  41. streamID: "",
  42. timer: 0,
  43. bShow: false,
  44. bLoading: false
  45. };
  46. },
  47. props: {
  48. live: {
  49. type: Boolean,
  50. default: false
  51. },
  52. fade: {
  53. type: Boolean,
  54. default: false
  55. }
  56. },
  57. computed: {
  58. ...mapState(['userInfo', 'serverInfo']),
  59. },
  60. beforeDestroy() {
  61. $(window).off("beforeunload", this.beforeUnload);
  62. this.stop();
  63. },
  64. mounted() {
  65. $(this.$el).find(".modal-content").draggable({
  66. handle: ".modal-header",
  67. cancel: ".modal-title span",
  68. addClasses: false,
  69. containment: "document",
  70. delay: 100,
  71. opacity: 0.5
  72. });
  73. $(this.$el).on("hide.bs.modal", () => {
  74. this.bShow = false;
  75. this.stop();
  76. }).on("show.bs.modal", () => {
  77. this.bShow = true;
  78. // no need since v1.2
  79. // if (this.streamID) {
  80. // this.timer = setInterval(() => {
  81. // $.get("/api/v1/playback/streaminfo", {
  82. // streamid: this.streamID,
  83. // touch: true,
  84. // });
  85. // }, 15000);
  86. // }
  87. });
  88. $(window).on("beforeunload", this.beforeUnload);
  89. },
  90. components: { LivePlayer },
  91. methods: {
  92. play(src, title, snap, serial, code, streamID) {
  93. this.videoTitle = title || "";
  94. this.snapUrl = snap || "";
  95. this.serial = serial || "";
  96. this.code = code || "";
  97. this.streamID = streamID || "";
  98. this.$nextTick(() => {
  99. this.videoUrl = src || "";
  100. })
  101. $(this.$el).modal("show");
  102. },
  103. stop() {
  104. this.snapUrl = "";
  105. this.videoUrl = "";
  106. if(this.timer) {
  107. clearInterval(this.timer);
  108. this.timer = 0;
  109. }
  110. if(this.streamID) {
  111. $.get("/api/v1/playback/stop", {
  112. streamid: this.streamID
  113. });
  114. this.streamID = "";
  115. }
  116. },
  117. scale(speed = 1) {
  118. $.get("/api/v1/playback/control", {
  119. streamid: this.streamID,
  120. command: "scale",
  121. scale: speed
  122. })
  123. },
  124. beforeUnload(event) {
  125. this.stop();
  126. event.preventDefault();
  127. event.returnValue = '';
  128. }
  129. }
  130. };
  131. </script>
  132. <style lang="less" scoped>
  133. .modal-title {
  134. overflow: hidden;
  135. white-space: nowrap;
  136. text-overflow: ellipsis;
  137. }
  138. </style>