一部分内容
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="info">
|
||||
<LiveingWatcher></LiveingWatcher>
|
||||
<LiveingWatcher @sentext="sendtext"></LiveingWatcher>
|
||||
<div class="LivePlaying">
|
||||
<LivePlaying></LivePlaying>
|
||||
<div class="comment">
|
||||
@@ -190,7 +190,7 @@
|
||||
}
|
||||
</style>
|
||||
<script lang="ts">
|
||||
import { defineComponent, onMounted, ref } from "vue";
|
||||
import { defineComponent, onMounted, ref, resolveComponent } from "vue";
|
||||
import LivePlaying from "@/components/LivePlaying.vue";
|
||||
import LiveingWatcher from "@/components/LiveingWatcher.vue";
|
||||
import TRTC from "trtc-js-sdk"
|
||||
@@ -199,6 +199,7 @@ import { useRoute } from 'vue-router';
|
||||
import store from '@/store';
|
||||
import { message } from 'ant-design-vue';
|
||||
import { useI18n } from '@/utils/i18n';
|
||||
import TIM from 'tim-js-sdk';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -217,6 +218,7 @@ export default defineComponent({
|
||||
const roominfo = ref<any>([]);
|
||||
console.log(useRoute())
|
||||
const id = useRoute().query.id;
|
||||
let tim: any;
|
||||
TRTC.checkSystemRequirements().then((result: any) => {
|
||||
if(!result) {
|
||||
message.error(lan.$t('buzhichitonghua'))
|
||||
@@ -351,6 +353,87 @@ export default defineComponent({
|
||||
// }
|
||||
fun()
|
||||
});
|
||||
|
||||
// im 初始化
|
||||
tim = TIM.create({
|
||||
SDKAppID: 1400400340
|
||||
}); // SDK 实例通常用 tim 表示
|
||||
tim.setLogLevel(0);
|
||||
tim.on(TIM.EVENT.MESSAGE_RECEIVED, function(event: any) {
|
||||
// 收到推送的单聊、群聊、群提示、群系统通知的新消息,可通过遍历 event.data 获取消息列表数据并渲染到页面
|
||||
// event.name - TIM.EVENT.MESSAGE_RECEIVED
|
||||
// event.data - 存储 Message 对象的数组 - [Message]
|
||||
for(const i in event.data){
|
||||
console.log(event.data[i])
|
||||
}
|
||||
});
|
||||
tim.on(TIM.EVENT.GROUP_LIST_UPDATED, function(event: any) {
|
||||
// 收到群组列表更新通知,可通过遍历 event.data 获取群组列表数据并渲染到页面
|
||||
// event.name - TIM.EVENT.GROUP_LIST_UPDATED
|
||||
// event.data - 存储 Group 对象的数组 - [Group]
|
||||
console.log(event.data)
|
||||
});
|
||||
tim.login({userID: store.state.userinfo.memberid.toString(), userSig: userSig}).then((res: any)=>{
|
||||
console.log(res.data); // 登录成功
|
||||
if (res.data.repeatLogin === true) {
|
||||
// 标识账号已登录,本次登录操作为重复登录。v2.5.1 起支持
|
||||
console.log(res.data.errorInfo);
|
||||
}
|
||||
|
||||
}).catch(function(imError: any) {
|
||||
console.warn('login error:', imError); // 登录失败的相关信息
|
||||
});
|
||||
tim.on(TIM.EVENT.SDK_READY, function (){
|
||||
const promise = tim.createGroup({
|
||||
type: TIM.TYPES.GRP_AVCHATROOM,
|
||||
name: 'live',
|
||||
groupID: roominfo.value.roomid
|
||||
});
|
||||
promise.then(function(imResponse: any) { // 创建成功
|
||||
console.log(imResponse.data.group); // 创建的群的资料
|
||||
tim.joinGroup({
|
||||
groupID: roominfo.value.roomid,
|
||||
type: TIM.TYPES.GRP_AVCHATROOM
|
||||
}).then((res: any)=>{
|
||||
switch (res.data.status) {
|
||||
case TIM.TYPES.JOIN_STATUS_WAIT_APPROVAL: // 等待管理员同意
|
||||
break;
|
||||
case TIM.TYPES.JOIN_STATUS_SUCCESS: // 加群成功
|
||||
console.log(res.data.group); // 加入的群组资料
|
||||
break;
|
||||
case TIM.TYPES.JOIN_STATUS_ALREADY_IN_GROUP: // 已经在群中
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}).catch((err: any)=>{
|
||||
console.log(err)
|
||||
})
|
||||
}).catch(function(imError: any) {
|
||||
console.warn('createGroup error:', imError); // 创建群组失败的相关信息
|
||||
tim.joinGroup({
|
||||
groupID: roominfo.value.roomid,
|
||||
type: TIM.TYPES.GRP_AVCHATROOM
|
||||
}).then((res: any)=>{
|
||||
switch (res.data.status) {
|
||||
case TIM.TYPES.JOIN_STATUS_WAIT_APPROVAL: // 等待管理员同意
|
||||
break;
|
||||
case TIM.TYPES.JOIN_STATUS_SUCCESS: // 加群成功
|
||||
console.log(res.data.group); // 加入的群组资料
|
||||
break;
|
||||
case TIM.TYPES.JOIN_STATUS_ALREADY_IN_GROUP: // 已经在群中
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}).catch((err: any)=>{
|
||||
console.log(err)
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
async function fenxiang(){
|
||||
console.log(localStream)
|
||||
@@ -387,6 +470,24 @@ export default defineComponent({
|
||||
});
|
||||
}
|
||||
|
||||
function sendtext(){
|
||||
const message = tim.createTextMessage({
|
||||
to: roominfo.value.roomid,
|
||||
conversationType: TIM.TYPES.CONV_GROUP,
|
||||
payload: {
|
||||
text: 'Hello world!'
|
||||
}
|
||||
});
|
||||
const promise = tim.sendMessage(message);
|
||||
promise.then(function(imResponse: any) {
|
||||
// 发送成功
|
||||
console.log(imResponse);
|
||||
}).catch(function(imError: any) {
|
||||
// 发送失败
|
||||
console.warn('sendMessage error:', imError);
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(async ()=>{
|
||||
const si = setInterval(async ()=>{
|
||||
if(store.state.userinfo.memberid != 0 && store.state.userinfo.memberid){
|
||||
@@ -405,7 +506,8 @@ export default defineComponent({
|
||||
roominfo,
|
||||
guanbi,
|
||||
visible,
|
||||
lan
|
||||
lan,
|
||||
sendtext
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user