123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <template>
- <view id="pageBox"><trtc-room id="trtcroom" :config="trtcConfig"></trtc-room></view>
- </template>
- <script>
- import { getSig } from '@/api/record.js';
- export default {
- data() {
- return {
- trtcConfig: {
- debugMode: false,
- sdkAppID: '1400396944',
- userID: '',
- userSig: '',
- template: '1v1',
- enableCamera: true,
- enableMic: true,
- enableAns: true,
- enableAgc: true,
- enableAutoFocus: true
- },
- roomId: '',
- template: '1v1',
- timestamp: []
- };
- },
- onLoad(option) {
- let obj = this;
- obj.trtcConfig.userID = option.userId;
- obj.callGetRoom().then(e => {
- obj.trtcConfig.userSig = e;
- console.log('开始调用初始化');
- obj.info();
- });
- obj.roomId = option.roomId;
- },
- methods: {
-
- callGetRoom() {
- let obj = this;
- return new Promise(function(resolve, reject) {
- getSig({})
- .then(e => {
- resolve(e.data.UserSig);
- })
- .catch(e => {
- reject(e);
- });
- });
- },
- info() {
- let obj = this;
-
- let trtcRoomContext = this.selectComponent('#trtcroom');
- let EVENT = trtcRoomContext.EVENT;
- trtcRoomContext.setData(
- {
- trtcConfig: obj.trtcConfig
- },
- e => {
- if (trtcRoomContext) {
- trtcRoomContext.on(EVENT.LOCAL_JOIN, event => {
- console.log('进入房间成功');
-
- trtcRoomContext.publishLocalVideo().then(() => {
- console.log('发布成功1');
-
- });
- trtcRoomContext.publishLocalAudio().then(() => {
- console.log('发布成功2');
-
- });
- });
-
- trtcRoomContext.on(EVENT.REMOTE_VIDEO_ADD, event => {
- console.log('视频流变动');
-
- let userID = event.data.userID;
- let streamType = event.data.streamType;
- trtcRoomContext.subscribeRemoteVideo({ userID: userID, streamType: streamType });
- });
-
- trtcRoomContext.on(EVENT.REMOTE_AUDIO_ADD, event => {
- console.log('音频变动’');
-
- let userID = event.data.userID;
- trtcRoomContext.subscribeRemoteAudio({ userID: userID });
- });
-
- trtcRoomContext.on(EVENT.REMOTE_USER_JOIN, event => {
- console.log('* room REMOTE_USER_JOIN', event, trtcRoomContext.getRemoteUserList());
- this.timestamp.push(new Date());
-
- });
-
- trtcRoomContext.on(EVENT.REMOTE_USER_LEAVE, event => {
- console.log('* room REMOTE_USER_LEAVE', event, trtcRoomContext.getRemoteUserList());
- if (this.template === '1v1') {
- this.timestamp = [];
- }
- if (this.template === '1v1' && this.remoteUser === event.data.userID) {
- this.remoteUser = null;
- }
- });
-
- trtcRoomContext.on(EVENT.REMOTE_VIDEO_ADD, event => {
-
- const userList = trtcRoomContext.getRemoteUserList();
- const data = event.data;
-
- this.remoteUser = data.userID;
- trtcRoomContext.subscribeRemoteVideo({
- userID: data.userID,
- streamType: data.streamType
- });
- });
-
- trtcRoomContext.on(EVENT.ERROR, event => {
- console.log('* room ERROR', event);
- });
-
- trtcRoomContext.enterRoom({ roomID: obj.roomId }).catch(res => {
- console.error('room joinRoom 进房失败:', res);
- });
- }
- }
- );
- }
- }
- };
- </script>
- <style>
- #trtcroom,
- page,
- #pageBox {
- height: 100%;
- width: 100%;
- }
- </style>
|