jhlive.nvue 10 KB

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