jhlive.nvue 10 KB

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