|
@@ -1,17 +1,15 @@
|
|
|
<template>
|
|
|
- <view
|
|
|
- class="container"
|
|
|
- :style="'width: '+windowWidth+'px; height: '+windowHeight+'px;'">
|
|
|
+ <view class="container" :style="'width: '+windowWidth+'px; height: '+windowHeight+'px;'">
|
|
|
<jhlive
|
|
|
ref="jhlive"
|
|
|
class="jhlive"
|
|
|
- :sdkAppID="1400430241"
|
|
|
- secretKey="941e01ca06e94057de3013b235b67a784ea28b45c43decbd518e765f7d5fc140"
|
|
|
- userid="123"
|
|
|
- roomid="1"
|
|
|
- :isAuthor="false"
|
|
|
- :linkMic="false"
|
|
|
- :avtar="avtar"
|
|
|
+ :sdkAppID="sdkAppID"
|
|
|
+ :secretKey="secretKey"
|
|
|
+ userid="userId"
|
|
|
+ roomid="roomId"
|
|
|
+ :isAuthor="isAuthor"
|
|
|
+ :linkMic="linkMic"
|
|
|
+ :avatar="avatar"
|
|
|
:num="num"
|
|
|
:likes="likes"
|
|
|
:name="name"
|
|
@@ -33,15 +31,19 @@
|
|
|
components: { jhlive },
|
|
|
data() {
|
|
|
return {
|
|
|
+ isAuthor: true,
|
|
|
+ linkMic: false,
|
|
|
+ sdkAppID:API.sdkAppID,
|
|
|
+ secretKey:API.secretKey,
|
|
|
windowWidth: 0,
|
|
|
windowHeight: 0,
|
|
|
- userId: '123',
|
|
|
- roomID: '1',
|
|
|
+ userId: '',
|
|
|
+ roomId: '',
|
|
|
liveId: '',
|
|
|
num: 0,
|
|
|
likes: 0,
|
|
|
name:"",
|
|
|
- avtar:"../static/images/loginLogo.png",
|
|
|
+ avatar:"../static/images/loginLogo.png",
|
|
|
userData: {},
|
|
|
imReady: false,
|
|
|
imMsgs: [],
|
|
@@ -53,94 +55,58 @@
|
|
|
let info = uni.getSystemInfoSync();
|
|
|
this.windowWidth = info.windowWidth;
|
|
|
this.windowHeight = info.windowHeight;
|
|
|
- return;
|
|
|
-
|
|
|
- NET.request(API.getBindedLiveGoods, {
|
|
|
- liveId: this.liveId
|
|
|
- }, 'GET').then(res => {
|
|
|
- let goodsIds = res.data.map(site => {
|
|
|
- return site.productId
|
|
|
- }).join(',')
|
|
|
- this.getAllGoods(goodsIds)
|
|
|
- }).catch(res => {
|
|
|
- this.$refs.uTips.show({
|
|
|
- title: '获取已绑定商品失败',
|
|
|
- type: 'warning',
|
|
|
- })
|
|
|
- })
|
|
|
- NET.request(API.creatLive, {
|
|
|
- liveId: this.liveId,
|
|
|
- liveStatus: 1
|
|
|
- }, 'GET').then(res => {}).catch(res => {
|
|
|
- this.$refs.uTips.show({
|
|
|
- title: '开启直播失败',
|
|
|
- type: 'warning',
|
|
|
- })
|
|
|
- })
|
|
|
- NET.request(API.startLivePushMessage + options.liveId, {}, 'GET').then(res => {
|
|
|
-
|
|
|
- }).catch(res => {
|
|
|
-
|
|
|
- })
|
|
|
- NET.request(API.getLiveData + this.liveId, {}, 'POST').then(res => {
|
|
|
- this.enterRoom({
|
|
|
- roomID: Number(res.data.roomId),
|
|
|
- userID: this.userData.userId,
|
|
|
- template: "grid",
|
|
|
- });
|
|
|
- this.avtar = res.data.imgUrl;
|
|
|
- this.name = res.data.liveName;
|
|
|
- this.roomID = Number(res.data.roomId);
|
|
|
- setTimeout(()=>{
|
|
|
- this.$refs.jhlive&&this.$refs.jhlive.enterRoom();
|
|
|
- }, 500)
|
|
|
- }).catch(res => {
|
|
|
- this.$refs.uTips.show({
|
|
|
- title: '获取直播设置参数失败',
|
|
|
- type: 'warning',
|
|
|
- })
|
|
|
- })
|
|
|
},
|
|
|
onReady() {
|
|
|
- setTimeout(()=>{
|
|
|
- this.jhim = new Jhim(this.userId, 1400430241, '941e01ca06e94057de3013b235b67a784ea28b45c43decbd518e765f7d5fc140');
|
|
|
+ this.init();
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ this.exitRoom();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ init() {
|
|
|
+ NET.request(API.startStream+2, 'GET').then(res => {
|
|
|
+ this.avatar = res.data.imgUrl;
|
|
|
+ this.name = res.data.liveName;
|
|
|
+ this.roomId = Number(res.data.roomId);
|
|
|
+ this.$nextTick(() => this.enterRoom());
|
|
|
+ }).catch(res => {
|
|
|
+ uni.showToast({
|
|
|
+ title: error.data.msg,
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ })
|
|
|
+ },
|
|
|
+ enterRoom() {
|
|
|
+ this.jhim = new Jhim(this.userData.userId, this.sdkAppID, this.secretKey);
|
|
|
this.jhim.on('onIMMessageReceived', event=>{
|
|
|
this.imMsgs = this.imMsgs.concat(event);
|
|
|
+ }).on('onIMGroupTipElem', res=>{
|
|
|
+ this.num = res.memberCount;
|
|
|
}).on('onIMSDKNotReady', event=>{
|
|
|
this.imReady = false;
|
|
|
}).on('onIMSDKReady', event=>{
|
|
|
this.imReady = true;
|
|
|
})
|
|
|
- this.jhim
|
|
|
- .login('name', 'avatar')
|
|
|
- .then(()=>this.jhim.ready)
|
|
|
- .then(()=>this.jhim.createGroup(this.roomID))
|
|
|
+ this.jhim.login('name', 'avatar').then(()=>this.jhim.createGroup(this.roomId))
|
|
|
+
|
|
|
this.$refs.jhlive&&this.$refs.jhlive.enterRoom();
|
|
|
- }, 500)
|
|
|
- },
|
|
|
- onUnload() {
|
|
|
- this.jhim.exitGroup();
|
|
|
- if(this.isAuthor) this.jhim.dismissGroup();
|
|
|
- this.jhim.logout();
|
|
|
-
|
|
|
- // NET.request(API.creatLive, {
|
|
|
- // liveId: this.liveId,
|
|
|
- // liveStatus: 2
|
|
|
- // }, 'GET').then(res => {}).catch(res => {
|
|
|
- // this.$refs.uTips.show({
|
|
|
- // title: '关闭直播失败',
|
|
|
- // type: 'warning',
|
|
|
- // })
|
|
|
- // })
|
|
|
- },
|
|
|
- methods: {
|
|
|
+ },
|
|
|
+ exitRoom() {
|
|
|
+ if(this.isAuthor) this.jhim.dismissGroup().then(()=>this.jhim.logout());
|
|
|
+ if(!this.isAuthor) this.jhim.exitGroup().then(()=>this.jhim.logout());
|
|
|
+ this.$refs.jhlive&&this.$refs.jhlive.exitRoom();
|
|
|
+
|
|
|
+ NET.request(API.creatLive, {
|
|
|
+ liveId: this.liveId,
|
|
|
+ liveStatus: 2
|
|
|
+ }, 'GET').then(res => {}).catch(res => {
|
|
|
+ this.$refs.uTips.show({
|
|
|
+ title: '关闭直播失败',
|
|
|
+ type: 'warning',
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
handleImSend(msg) {
|
|
|
- let msgObj = {
|
|
|
- data: msg,
|
|
|
- description: this.userData.headImage,
|
|
|
- extension: this.userData.userName
|
|
|
- };
|
|
|
-
|
|
|
this.jhim.sendGroupText(msg).then(msg=>{
|
|
|
this.imMsgs.push(msg);
|
|
|
});
|
|
@@ -154,14 +120,14 @@
|
|
|
</script>
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
- .container {
|
|
|
- position: relative;
|
|
|
- display: flex;
|
|
|
- flex-direction: column;
|
|
|
- align-items: stretch;
|
|
|
- }
|
|
|
+.container {
|
|
|
+ position: relative;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ align-items: stretch;
|
|
|
+}
|
|
|
|
|
|
- .jhlive {
|
|
|
- flex: 1;
|
|
|
- }
|
|
|
+.jhlive {
|
|
|
+ flex: 1;
|
|
|
+}
|
|
|
</style>
|