jhlive.nvue 7.2 KB

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