jhlive.nvue 6.0 KB

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