jhlive.nvue 9.2 KB

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