|
|
@@ -1,240 +0,0 @@
|
|
|
-import {
|
|
|
- genTestUserSig
|
|
|
-} from './unit/GenerateTestUserSig.js'
|
|
|
-import * as SocketHandle from '../../utils/socket-handle'
|
|
|
-Page({
|
|
|
-
|
|
|
- /**
|
|
|
- * 页面的初始数据
|
|
|
- */
|
|
|
- data: {
|
|
|
- userSig:'',
|
|
|
- userID: '',
|
|
|
- roomID: '1234567',
|
|
|
- userList: [], // 主播list
|
|
|
- trtcConfig: {
|
|
|
- // scene: 'rtc',
|
|
|
- // sdkAppID: '1400433526', // 开通实时音视频服务创建应用后分配的 SDKAppID
|
|
|
- sdkAppID: '1400537003', // 开通实时音视频服务创建应用后分配的 SDKAppID
|
|
|
- // userID: '1', // 用户 ID,可以由您的帐号系统指定
|
|
|
- // userSig: '', // 身份签名,相当于登录密码的作用
|
|
|
- // template: 'custom', // 画面排版模式
|
|
|
- // debugMode: true,
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
- onLoad: function (options) {
|
|
|
-
|
|
|
- this.setData({
|
|
|
- userID : this.random(1,100).toString()
|
|
|
- })
|
|
|
- let opts = {
|
|
|
- roomId: this.data.roomID,
|
|
|
- userId: this.data.userID,
|
|
|
- role: 'customer',
|
|
|
- scene_num: '1'
|
|
|
- }
|
|
|
- this.socket = SocketHandle.initSocket(this, opts)
|
|
|
- this.trtcComponent = this.selectComponent('#trtcroom')
|
|
|
- this.bindTRTCRoomEvent()
|
|
|
-
|
|
|
- },
|
|
|
- bindUserID: function(e) {
|
|
|
- this.setData({
|
|
|
- userID: e.detail.value,
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
- joinRoom() {
|
|
|
- if(this.data.userID==""){
|
|
|
- wx.showToast({
|
|
|
- title: '输入用户id',
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- this.initRoom()
|
|
|
- // this.getSignature()
|
|
|
-
|
|
|
- },
|
|
|
- getSignature(userSig){
|
|
|
- console.log('***********************')
|
|
|
- console.log(userSig)
|
|
|
- this.setData({
|
|
|
- userSig:userSig
|
|
|
- })
|
|
|
- // this.data.userSig = userSig
|
|
|
- },
|
|
|
- random(lower, upper) {
|
|
|
- return Math.floor(Math.random() * (upper - lower)) + lower;
|
|
|
- },
|
|
|
- initRoom() {
|
|
|
-
|
|
|
- const Signature = genTestUserSig(this.data.userID)
|
|
|
-
|
|
|
- this.enterRoom({
|
|
|
- sdkAppID: Signature.sdkAppID,
|
|
|
- userSig: this.data.userSig,
|
|
|
- })
|
|
|
- },
|
|
|
- enterRoom({sdkAppID,userSig}) {
|
|
|
- const template = 'custom'
|
|
|
- const roomID = this.data.roomID
|
|
|
-
|
|
|
- this.setData({
|
|
|
- trtcConfig:{
|
|
|
- sdkAppID: sdkAppID, // 您的实时音视频服务创建应用后分配的 sdkAppID
|
|
|
- userID: this.data.userID,
|
|
|
- userSig: userSig,
|
|
|
- template: template, // 1v1 grid custom
|
|
|
- debugMode: true, // 非必要参数,打开组件的调试模式,开发调试时建议设置为 true
|
|
|
- // audioVolumeType: this.data.audioVolumeType,
|
|
|
- }
|
|
|
- }, () => {
|
|
|
-
|
|
|
-
|
|
|
- this.trtcComponent.enterRoom({
|
|
|
- roomID: roomID
|
|
|
- }).then((res) => {
|
|
|
- console.log(res)
|
|
|
- wx.showToast({
|
|
|
- title: '成功进入房间',
|
|
|
- })
|
|
|
- }).catch((res) => {
|
|
|
-
|
|
|
- console.error('room 进房失败:', res)
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- bindTRTCRoomEvent: function() {
|
|
|
- const TRTC_EVENT = this.trtcComponent.EVENT
|
|
|
- // 初始化事件订阅
|
|
|
- this.trtcComponent.on(TRTC_EVENT.LOCAL_JOIN, (event)=>{
|
|
|
- console.log('* room LOCAL_JOIN', event)
|
|
|
- this.trtcComponent.publishLocalAudio()
|
|
|
- wx.showToast({
|
|
|
- title: 'LOCAL_JOIN',
|
|
|
- })
|
|
|
- // 进房成功,触发该事件后可以对本地视频和音频进行设置
|
|
|
- // if (this.data.role === 'presenter') {
|
|
|
- // this.trtcComponent.publishLocalAudio()
|
|
|
- // }
|
|
|
- })
|
|
|
- // this.trtcComponent.on(TRTC_EVENT.LOCAL_LEAVE, (event)=>{
|
|
|
- // console.log('*本地用户离开', event)
|
|
|
- // })
|
|
|
- // this.trtcComponent.on(TRTC_EVENT.ERROR, (event)=>{
|
|
|
- // console.log('* room ERROR', event)
|
|
|
- // })
|
|
|
- // 远端用户进房
|
|
|
- // this.trtcComponent.on(TRTC_EVENT.REMOTE_USER_JOIN, (event)=>{
|
|
|
- // wx.showToast({
|
|
|
- // title: '远端用户进房',
|
|
|
- // })
|
|
|
- // console.log('* room REMOTE_USER_JOIN', event, this.trtcComponent.getRemoteUserList())
|
|
|
- // const userList = this.trtcComponent.getRemoteUserList()
|
|
|
- // // this.handleOnUserList(userList).then(() => {
|
|
|
- // // console.log(this.data.userList)
|
|
|
- // // })
|
|
|
- // })
|
|
|
- // // 远端用户退出
|
|
|
- // this.trtcComponent.on(TRTC_EVENT.REMOTE_USER_LEAVE, (event)=>{
|
|
|
- // console.log('远端用户退出', event, this.trtcComponent.getRemoteUserList())
|
|
|
- // const userList = this.trtcComponent.getRemoteUserList()
|
|
|
- // // this.handleOnUserList(userList).then(() => {
|
|
|
- // // console.log(this.data.userList)
|
|
|
- // // })
|
|
|
- // })
|
|
|
- // 远端用户推送音频
|
|
|
- this.trtcComponent.on(TRTC_EVENT.REMOTE_AUDIO_ADD, (event)=>{
|
|
|
- wx.showToast({
|
|
|
- title: '远端用户推送音频',
|
|
|
- })
|
|
|
- // if (this.data.userList.length < 6) {
|
|
|
- // 订阅音频
|
|
|
- const data = event.data
|
|
|
- // 如果不订阅就不会自动播放音频
|
|
|
- const userList = this.trtcComponent.getRemoteUserList()
|
|
|
- // this.handleOnUserList(userList).then(() => {
|
|
|
- // console.log(this.data.userList)
|
|
|
- // })
|
|
|
- console.log('* room REMOTE_AUDIO_ADD', event, this.trtcComponent.getRemoteUserList())
|
|
|
- this.trtcComponent.subscribeRemoteAudio({ userID: data.userID })
|
|
|
- // }
|
|
|
- })
|
|
|
- this.trtcComponent.on('ERROR',(event)=>{
|
|
|
- console.log('ERRORERRORERRORERRORERROR')
|
|
|
- console.log(event)
|
|
|
- })
|
|
|
- // 远端用户取消推送音频
|
|
|
- // this.trtcComponent.on(TRTC_EVENT.REMOTE_AUDIO_REMOVE, (event)=>{
|
|
|
- // console.log('远端用户取消推送音频', event, this.trtcComponent.getRemoteUserList())
|
|
|
- // const userList = this.trtcComponent.getRemoteUserList()
|
|
|
- // // this.handleOnUserList(userList).then(() => {
|
|
|
- // // console.log(this.data.userList)
|
|
|
- // // })
|
|
|
- // })
|
|
|
- // this.trtcComponent.on(TRTC_EVENT.REMOTE_AUDIO_VOLUME_UPDATE, (event)=>{
|
|
|
- // const userID = event.data.target.dataset.userid
|
|
|
- // const volume = event.data.detail.volume
|
|
|
- // this.data.userList.forEach((item) =>{
|
|
|
- // if (item.userID === userID) {
|
|
|
- // item.volume = volume
|
|
|
- // }
|
|
|
- // })
|
|
|
- // this.setData({
|
|
|
- // userList: this.data.userList,
|
|
|
- // })
|
|
|
- // })
|
|
|
- },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面初次渲染完成
|
|
|
- */
|
|
|
- onReady: function () {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面显示
|
|
|
- */
|
|
|
- onShow: function () {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面隐藏
|
|
|
- */
|
|
|
- onHide: function () {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面卸载
|
|
|
- */
|
|
|
- onUnload: function () {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 页面相关事件处理函数--监听用户下拉动作
|
|
|
- */
|
|
|
- onPullDownRefresh: function () {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 页面上拉触底事件的处理函数
|
|
|
- */
|
|
|
- onReachBottom: function () {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 用户点击右上角分享
|
|
|
- */
|
|
|
- onShareAppMessage: function () {
|
|
|
-
|
|
|
- }
|
|
|
-})
|