jhlive.nvue 9.1 KB

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