jhlive.nvue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="container-jhlive" data-type="jhlive">
  3. <JhliveApp
  4. class="liveView"
  5. ref="liveView"
  6. :sdkAppID="sdkAppID"
  7. :userSig="userSig"
  8. :userid="userId"
  9. :roomid="roomId"
  10. :isAuthor="isAuthor"
  11. :linkMic="linkMic"
  12. :liveEvent="handleLiveEvent" />
  13. <view class="top_left_box">
  14. <image class="top_left_box_img" :src="avatar"></image>
  15. <view class="top_left_box_text">
  16. <text class="top_left_box_text1">{{name}}</text>
  17. <text class="top_left_box_text2" >{{num}}</text>
  18. </view>
  19. </view>
  20. <view class="top-right-box">
  21. <view class="top-right-box-btn" v-if="isAuthor" @click="btnBeautify">
  22. <text class="top-right-box-btn-text">美颜</text>
  23. </view>
  24. <view class="top-right-box-btn" v-if="isAuthor" @click="btnChangeCamera">
  25. <text class="top-right-box-btn-text">切换</text>
  26. </view>
  27. </view>
  28. <view class="bottom-right-box">
  29. <view class="bottom-right-box-btn" @click="btnLike">
  30. <text class="bottom-right-box-btn-text">点赞</text>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import LibGenerateTestUserSig from "./lib-generate-test-usersig-es.min";
  37. // #ifdef MP-WEIXIN
  38. import JhliveApp from './live-wechat';
  39. //#endif
  40. const LOGTAG = '--JHLIVE--:';
  41. const EXPIRETIME = 604800;
  42. export default {
  43. name: 'jhlive',
  44. // #ifdef MP-WEIXIN
  45. components: {JhliveApp},
  46. //#endif
  47. data() {
  48. return {
  49. userSig: '',
  50. beautifyLevel: false,
  51. };
  52. },
  53. props: {
  54. sdkAppID: Number,
  55. secretKey: String,
  56. userId: String,
  57. roomId: String,
  58. isAuthor: Boolean,
  59. linkMic: Boolean,
  60. name: String,
  61. avatar: String,
  62. num: String,
  63. },
  64. onLoad() {
  65. this.init();
  66. },
  67. onUnload() {
  68. this.destroy();
  69. },
  70. methods: {
  71. init() {
  72. this.remoteUsers = [];
  73. uni.setKeepScreenOn({
  74. keepScreenOn: true
  75. });
  76. },
  77. destroy() {
  78. uni.setKeepScreenOn({
  79. keepScreenOn: false
  80. });
  81. this.exitRoom()
  82. },
  83. enterRoom() {
  84. if(!this.$refs.liveView) {
  85. console.log(LOGTAG+'no jhlive');
  86. uni.showToast({
  87. title: '直播组件初始化失败',
  88. duration: 2000
  89. });
  90. return;
  91. }
  92. console.log(LOGTAG+'enterRoom', this.isAuthor, this.linkMic, this.sdkAppID, this.secretKey, this.userId, this.roomId);
  93. const generator = new LibGenerateTestUserSig(this.sdkAppID, this.secretKey, EXPIRETIME);
  94. this.userSig = generator.genTestUserSig(String(this.userId));
  95. this.$nextTick(() => this.$refs.liveView.enterRoom());
  96. },
  97. exitRoom() {
  98. console.log(LOGTAG+'exitRoom');
  99. this.$refs.liveView.exitRoom();
  100. },
  101. btnChangeCamera() {
  102. console.log(LOGTAG+'btnChangeCamera');
  103. this.$refs.liveView.switchCarema();
  104. },
  105. btnBeautify() {
  106. console.log(LOGTAG+'btnBeautify', this.beautifyLevel);
  107. // blv - 美颜级别取值范围0 - 9; 0表示关闭,1 - 9值越大
  108. // wlv - 亮度级别取值范围0 - 9; 0表示关闭,1 - 9值越大
  109. // beautyStyle 美颜风格.三种美颜风格:0 :光滑 1:自然 2:朦胧
  110. this.beautifyLevel = !this.beautifyLevel;
  111. this.$refs.liveView.setBeauty(
  112. this.beautifyLevel?9:0,
  113. this.beautifyLevel?9:0,
  114. this.beautifyLevel?0:0,
  115. );
  116. },
  117. handleLiveEvent(event) {
  118. if(event.eventName=='onRemoteUserEnterRoom'&&!this.remoteUsers.find(v=>v==event.eventData)) {
  119. this.remoteUsers.push(event.eventData);
  120. this.$emit('onRemoteUser', this.remoteUsers);
  121. }else if(event.eventName=='onRemoteUserLeaveRoom') {
  122. this.remoteUsers = this.remoteUsers.filter(v=>v!=event.eventData);
  123. this.$emit('onRemoteUser', this.remoteUsers);
  124. }else if(event.eventName=='onError') {
  125. this.$emit('onError', event.eventData.msg);
  126. uni.showToast({
  127. title: event.eventData.msg,
  128. duration: 2000
  129. });
  130. }
  131. },
  132. }
  133. };
  134. </script>
  135. <style scoped>
  136. .container-jhlive {
  137. position: relative;
  138. display: flex;
  139. flex-direction: column;
  140. align-items: stretch;
  141. background-color: black;
  142. width: 100%;
  143. height: 100%;
  144. }
  145. .liveView {
  146. flex: 1;
  147. }
  148. .top_left_box {
  149. left: 0;
  150. top: 0;
  151. margin-left: 10px;
  152. margin-top: 10px;
  153. position: absolute;
  154. z-index: 100;
  155. background-color:rgba(0, 0, 0, 0.4);
  156. border-radius: 1000px;
  157. display: flex;
  158. flex-direction: row;
  159. padding: 10px;
  160. }
  161. .top_left_box_img {
  162. width: 80rpx;
  163. height: 80rpx;
  164. border-radius: 1000px;
  165. background-color: white;
  166. }
  167. .top_left_box_text {
  168. margin-left: 10px;
  169. flex: 1;
  170. }
  171. .top_left_box_text1 {
  172. font-size: 28rpx;
  173. color: white;
  174. }
  175. .top_left_box_text2 {
  176. font-size: 20rpx;
  177. color: white;
  178. }
  179. .top-right-box {
  180. right: 0;
  181. top: 0;
  182. margin-top: 10px;
  183. margin-right: 10px;
  184. position: absolute;
  185. z-index: 100;
  186. display: flex;
  187. flex-direction: row;
  188. }
  189. .top-right-box-btn {
  190. color: white;
  191. margin-left: 5px;
  192. }
  193. .top-right-box-btn-text {
  194. color: white;
  195. }
  196. .bottom-left-box {
  197. left: 0;
  198. bottom: 0;
  199. margin-left: 10px;
  200. margin-bottom: 10px;
  201. position: absolute;
  202. z-index: 100;
  203. }
  204. .bottom-left-box-login {
  205. color: white;
  206. }
  207. .bottom-left-box-messages {
  208. }
  209. .bottom-left-box-message {
  210. }
  211. .bottom-left-box-input-box {
  212. }
  213. .bottom-left-box-input {
  214. color: #fff;
  215. font-size: 30rpx;
  216. }
  217. .bottom-right-box {
  218. right: 0;
  219. bottom: 0;
  220. margin-bottom: 10px;
  221. margin-right: 10px;
  222. position: absolute;
  223. z-index: 100;
  224. display: flex;
  225. flex-direction: row;
  226. }
  227. .bottom-right-box-btn {
  228. color: white;
  229. margin-left: 5px;
  230. }
  231. .bottom-right-box-btn-text {
  232. color: white;
  233. }
  234. </style>