jhlive.nvue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. <image v-if="showFav" class="top_left_box_collect" :src="isFav?collect:notCollect" @click="$emit('onFav', isFav)"></image>
  13. </view>
  14. <view class="bottom-message">
  15. <!-- 对话信息 -->
  16. <view v-if="showIm" class="jhim-message-box">
  17. <view class="jhim-message" v-for="(item, index) in imMsgs.slice(0,5)" :key="index">
  18. <text class="jhim-message-text" style="color: #C8C8C8;">{{item.name}}:</text>
  19. <text class="jhim-message-text">{{item.text}}</text>
  20. </view>
  21. </view>
  22. <!-- 下方功能 -->
  23. <view v-if="showIm||btns.length" class="bottom-box">
  24. <view v-if="showIm&&!imStatus" class="jhim-input-box">
  25. <image class="jhim-icon" :src="inputIcon"/>
  26. <input
  27. class="jhim-input"
  28. placeholder="请输入"
  29. placeholder-style="color:#fff;font-size: 14px;"
  30. v-model="imInput"
  31. confirm-type="send" @confirm="$emit('onImSend', imInput)" />
  32. </view>
  33. <view v-if="showIm&&imStatus" class="jhim-logining"><text class="jhim-logining-text">{{imStatus}}</text></view>
  34. <view v-if="!showIm" class="jhim-logining"></view>
  35. <!-- 按钮 -->
  36. <view class="bottom-box-btns">
  37. <!-- <view class="" v-if="isAuthor && showBeauty" @click="btnBeautify"> -->
  38. <view v-if="isAuthor&&showBeauty" class="bottom-box-btns-arr" @click="btnBeautify">
  39. <image class="btns-icon" :src="beautyIcon"/>
  40. </view>
  41. <!-- <view class="" v-if="isAuthor && showSwitch" @click="btnChangeCamera"> -->
  42. <view v-if="isAuthor&&showSwitch" class="bottom-box-btns-arr" @click="btnChangeCamera">
  43. <image class="btns-icon" :src="switchIcon"/>
  44. </view>
  45. <view class="bottom-box-btns-arr" v-for="(item,index) in btns" :key="index" @click="clickBtns(index, item)">
  46. <image class="btns-icon" :src="item.picture"/>
  47. <text v-if="item.title" class="btns-text">{{item.title}}</text>
  48. </view>
  49. <view v-if="showLike" class="bottom-box-btns-arr" @click="btnLike">
  50. <image class="btns-icon" :src="likeIcon"/>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import LibGenerateTestUserSig from "./lib-generate-test-usersig-es.min";
  59. // #ifdef MP-WEIXIN
  60. import JhliveApp from './live-wechat';
  61. //#endif
  62. const LOGTAG = '--JHLIVE--:';
  63. const EXPIRETIME = 604800;
  64. export default {
  65. name: 'jhlive',
  66. // #ifdef MP-WEIXIN
  67. components: {
  68. JhliveApp
  69. },
  70. //#endif
  71. data() {
  72. return {
  73. imInput: '',
  74. userSig: '',
  75. beautifyLevel: false,
  76. collect:"./live-collect.png", // 已收藏图标
  77. notCollect: "./live-notCollect.png", // 未收藏图标
  78. inputIcon: "./live-chat.png", // 输入框图标
  79. beautyIcon:"./live-beauty.png", // 美颜图标
  80. switchIcon: "./live-switch.png", // 切换摄像头图标
  81. likeIcon: "./live-support.png"
  82. };
  83. },
  84. props: {
  85. sdkAppID: Number,
  86. secretKey: String,
  87. userId: String,
  88. roomId: String,
  89. isAuthor: Boolean,
  90. linkMic: Boolean,
  91. title: String,
  92. avatar: String,
  93. subtitle: String,
  94. isFav: {default: false,type: Boolean}, // 是否显示收藏
  95. showFav: {default: false,type: Boolean}, // 是否显示收藏
  96. showBeauty: {default: false,type: Boolean}, // 是否显示美颜
  97. showSwitch: {default: false,type: Boolean}, // 是否显示切换摄像头
  98. showLike: {default: false,type: Boolean},
  99. showIm: {default: false,type: Boolean},
  100. btns:{
  101. default: [],
  102. type: Array
  103. }, // 按钮数组
  104. imMsgs:{
  105. default: [],
  106. type: Array
  107. },
  108. imStatus:{
  109. default: '',
  110. type: String
  111. }
  112. },
  113. mounted() {
  114. this.init();
  115. },
  116. unmounted() {
  117. this.destroy();
  118. },
  119. methods: {
  120. init() {
  121. this.remoteUsers = [];
  122. uni.setKeepScreenOn({
  123. keepScreenOn: true
  124. });
  125. },
  126. destroy() {
  127. uni.setKeepScreenOn({
  128. keepScreenOn: false
  129. });
  130. this.exitRoom()
  131. },
  132. enterRoom() {
  133. if (!this.$refs.liveView) {
  134. console.log(LOGTAG + 'no jhlive');
  135. uni.showToast({
  136. title: '直播组件初始化失败',
  137. duration: 2000
  138. });
  139. return;
  140. }
  141. console.log(LOGTAG + 'enterRoom', this.isAuthor, this.linkMic, this.sdkAppID, this.secretKey, this.userId, this.roomId);
  142. const generator = new LibGenerateTestUserSig(this.sdkAppID, this.secretKey, EXPIRETIME);
  143. this.userSig = generator.genTestUserSig(String(this.userId));
  144. this.$nextTick(() => this.$refs.liveView && this.$refs.liveView.enterRoom && this.$refs.liveView.enterRoom());
  145. },
  146. exitRoom() {
  147. console.log(LOGTAG + 'exitRoom');
  148. this.$refs.liveView.exitRoom();
  149. },
  150. cleanImInput() {
  151. this.imInput = '';
  152. },
  153. btnChangeCamera() {
  154. console.log(LOGTAG + 'btnChangeCamera');
  155. this.$refs.liveView.switchCarema();
  156. },
  157. btnBeautify() {
  158. console.log(LOGTAG + 'btnBeautify', this.beautifyLevel);
  159. // blv - 美颜级别取值范围0 - 9; 0表示关闭,1 - 9值越大
  160. // wlv - 亮度级别取值范围0 - 9; 0表示关闭,1 - 9值越大
  161. // beautyStyle 美颜风格.三种美颜风格:0 :光滑 1:自然 2:朦胧
  162. this.beautifyLevel = !this.beautifyLevel;
  163. this.$refs.liveView.setBeauty(
  164. this.beautifyLevel ? 9 : 0,
  165. this.beautifyLevel ? 9 : 0,
  166. this.beautifyLevel ? 0 : 0,
  167. );
  168. },
  169. handleLiveEvent(event) {
  170. if (event.eventName == 'onRemoteUserEnterRoom' && !this.remoteUsers.find(v => v == event.eventData)) {
  171. this.remoteUsers.push(event.eventData);
  172. this.$emit('onRemoteUser', this.remoteUsers);
  173. } else if (event.eventName == 'onRemoteUserLeaveRoom') {
  174. this.remoteUsers = this.remoteUsers.filter(v => v != event.eventData);
  175. this.$emit('onRemoteUser', this.remoteUsers);
  176. } else if (event.eventName == 'onError') {
  177. this.$emit('onError', event.eventData.msg);
  178. uni.showToast({
  179. title: event.eventData.msg,
  180. duration: 2000
  181. });
  182. }
  183. },
  184. onError: (e) => {
  185. uni.showToast({
  186. title: e.detail,
  187. duration: 2000
  188. });
  189. this.$emit('onError', e.detail);
  190. },
  191. onRemoteUserEnterRoom: (e) => {
  192. if (this.remoteUsers.find(v => v == e.detail)) {
  193. this.remoteUsers.push(e.detail);
  194. this.$emit('onRemoteUser', this.remoteUsers);
  195. }
  196. },
  197. onRemoteUserLeaveRoom: (e) => {
  198. this.remoteUsers = this.remoteUsers.filter(v => v != e.detail);
  199. this.$emit('onRemoteUser', this.remoteUsers);
  200. },
  201. clickBtns(index, item) {
  202. this.$emit("onBtnClick", index, item);
  203. }
  204. }
  205. };
  206. </script>
  207. <style scoped>
  208. .container-jhlive {
  209. position: relative;
  210. display: flex;
  211. flex-direction: column;
  212. align-items: stretch;
  213. background-color: black;
  214. width: 100%;
  215. height: 100%;
  216. }
  217. .liveView {
  218. flex: 1;
  219. /* z-index: -1; */
  220. }
  221. .top_left_box {
  222. left: 0;
  223. top: 0;
  224. margin-left: 10px;
  225. margin-top: 10px;
  226. position: absolute;
  227. z-index: 100;
  228. background-color: rgba(115, 111, 117, 0.4);
  229. border-radius: 1000px;
  230. display: flex;
  231. flex-direction: row;
  232. padding: 5px;
  233. justify-content: center;
  234. align-items: center;
  235. }
  236. .top_left_box_img {
  237. width: 80rpx;
  238. height: 80rpx;
  239. border-radius: 1000px;
  240. background-color: white;
  241. }
  242. .top_left_box_collect {
  243. width: 26px;
  244. height: 26px;
  245. }
  246. .top_left_box_text {
  247. margin-left: 10px;
  248. margin-right: 10px;
  249. }
  250. .top_left_box_text1 {
  251. font-size: 28rpx;
  252. color: white;
  253. margin-bottom: 5px;
  254. }
  255. .top_left_box_text2 {
  256. font-size: 20rpx;
  257. color: white;
  258. }
  259. .bottom-message {
  260. width: 750rpx;
  261. display: flex;
  262. flex-direction: column;
  263. position: absolute;
  264. bottom: 0px;
  265. }
  266. .bottom-box {
  267. width: 750rpx;
  268. display: flex;
  269. flex-direction: row;
  270. bottom: 0px;
  271. background-color:rgba(0, 0, 0, 0.4);
  272. }
  273. .jhim-message-box {
  274. /* position: absolute; */
  275. /* padding: 5;
  276. left: 5px; */
  277. /* display: flex; */
  278. /* z-index: 100; */
  279. }
  280. .jhim-message {
  281. /* flex: 1; */
  282. display: flex;
  283. flex-direction: row;
  284. align-items: center;
  285. background-color: rgba(115,119,120,0.3);
  286. padding: 5px;
  287. border-radius: 12px;
  288. margin-bottom: 10px;
  289. }
  290. .jhim-message-text {
  291. color: #fff;
  292. font-size: 14px;
  293. }
  294. .jhim-input-box {
  295. padding: 10px;
  296. margin: 10px;
  297. align-items: center;
  298. display: flex;
  299. flex-direction: row;
  300. background-color:rgba(50, 50, 50, 0.3);
  301. border-radius: 15px;
  302. flex: 1;
  303. }
  304. .jhim-icon {
  305. width: 14px;
  306. height: 14px;
  307. margin-right: 5px;
  308. }
  309. .jhim-input {
  310. flex: 1;
  311. color: #fff;
  312. font-size: 28rpx;
  313. }
  314. .jhim-logining {
  315. padding: 5px;
  316. flex: 1;
  317. }
  318. .jhim-logining-text {
  319. color: #fff;
  320. font-size: 28rpx;
  321. }
  322. .bottom-box-btns {
  323. display: flex;
  324. flex-direction: row;
  325. align-items: center;
  326. }
  327. .bottom-box-btns-arr {
  328. margin-right: 5px;
  329. }
  330. .btns-icon {
  331. width: 40px;
  332. height: 40px;
  333. }
  334. .btns-text {
  335. text-align: center;
  336. }
  337. </style>