meetingController.js 9.6 KB
var userModel =  require('../model/userModel');
var siteModel =  require('../model/siteModel');
const moment = require('moment')
var saitMd5 = require('../util/saltMD5')
var status = require('../util/resTemplate') 
const meetingService = require('../services/meetingService')
const uuid = require('../util/UuidUtil')
const emailUtil = require('../util/emailUtil')
const request = require('request')
const xml2js = require('xml2js');
const requestUtil = require('../util/requestUtil')
const builder = new xml2js.Builder();  // JSON->xml
const parser = new xml2js.Parser();   //xml -> json



 function meetingController(){

};

meetingController.prototype.createMeeting = async(ctx,next)=>{
    try {
        let meetingbody = ctx.request.body;
        if(!meetingbody.presenterPassword){
            return status.paramError('meetingName');
        }else if(!meetingbody.meetingName){
            return status.paramError('meetingName','不能为空');        
        }
        let num = JSON.stringify(Math.floor(Math.random() * 99999) + 1000)
        let site = await siteModel.findOne({where:{siteId:meetingbody.siteId}})
        let authIdMd5 = site.siteKey+meetingbody.siteId+num+meetingbody.userId+meetingbody.userType+123321
        console.log(authIdMd5)
        let meeting = {
              siteId:meetingbody.siteId, //站点ID
              mtgKey:meetingbody.mtgKey ? meetingbody.mtgKey:num,//课堂序号
              mtgTitle:meetingbody.meetingName, //课堂名字
              language:2,//语言
              userId:meetingbody.userId,
              userName:meetingbody.userName,//用户名
              userType:meetingbody.userType, //用户类型用户类型:1:主持人(所有权限)2:主讲人(不能操作摄像头) 8:普通与会者32: 监课人员
              meetingType:meetingbody.meetingType ,//1、互动 2、直播;默认为1
              timestamp:123321,
              autoRecord:meetingbody.autoRecord, //是否自动录制:(1是,0否)
              interaction:meetingbody.interaction,
              backUrl:meetingbody.backUrl,// 课堂结束回调地址
              mediaID:meetingbody.mediaID,//伴音id
              meetingContent:meetingbody.meetingContent, //课堂描述
              create_user:ctx.request.userName,  //创建用户名
              duration:ctx.request.duration,//持续时长
              presenterPassword:meetingbody.presenterPassword, //主讲人密码            
              startTime: moment(meetingbody.beginTime).format("YYYY-MM-DD HH:MM:SS "), //开始时间
              endTime: moment(meetingbody.endTime).format("YYYY-MM-DD HH:MM:SS"), // 结束时间
              isPublic:meetingbody.isPublic,  //是否公开课
              hostPwd:meetingbody.hostPwd,
              //repeatmode:meetingbody.repeatmode, //是否重复周期
              meetingType:meetingbody.meetingType, //课堂类型
              h5Module:Number( meetingbody.h5Module), // 是否支持H5
              //attendeePassword:meetingbody.attendeePassword, //学生密码
              videoModule:meetingbody.videoModule, //视频是否启用
              //chatInterval:meetingbody.chatInterval, //聊天延时时间
              //aheadTime:Number( meetingbody.aheadTime), // 提前进入课堂时间
              maxVideoChannels:meetingbody.maxVideoChannels, //最大视频路数
              maxAudioChannels:meetingbody.max_audioChannels, // 最大音频路数
              videoQuality:meetingbody.video_quality, //视频画质
              //pagenaviUserprivilege:meetingbody.pagenaviUserprivilege, //换页权限是否开启
              //markerUserprivilege:meetingbody.markerUserprivilege, // 批注权限是否开启
              //chatToNormalUserprivilege:meetingbody.chatToNormalUserprivilege, //与参会者聊天权限是否开启
              //chatToHostUserprivilege:meetingbody.chatToHostUserprivilege, //与主持人聊天权限是否开启
              docModule:meetingbody.docModule, //文档共享是否开启
              screenModule:meetingbody.screenModule, //屏幕共享是否开启
              mediaModule:meetingbody.mediaModule, //媒体共享是否开启 
              whiteboardModule:meetingbody.whiteboardModule, //白板共享是否开启
              recordModule:meetingbody.recordModule, //录制是否启用
              //chatModule:meetingbody.chatModule, //聊天模式是否启用
              authId:saitMd5.md5(authIdMd5)
        }
        
        builder.options.rootName = 'param'
        console.log(JSON.stringify(meeting))
        var xml =  builder.buildObject(meeting);
        console.log(xml)
        let info = await requestUtil.post('http://markettest.xuedianyun.com/3m/meeting/join_mtg.do',xml);
        var jsonXml =  await requestUtil.json2xml(info);        
        console.log('json string',jsonXml)
        let backJsonMeeting ={
            code:jsonXml.result.errorCode,
            meetingUrl:jsonXml.result.url[0]//+'?param='+jsonXml.result.param[0],
        }
        return backJsonMeeting;
    } catch (error) {
        throw error;
    }
}

meetingController.prototype.getMeeting = async(ctx,next) =>{
    try {
        var sql = `SELECT
                        id,
                        meeting_number AS meetingNumber,
                        meeting_name AS meetingName,
                        meeting_content AS meetingContent,
                        create_user,
                        create_time AS createTime,
                        begin_time AS beginTime,
                        end_time AS endTime,
                        invite_user AS inviteUser,
                        meeting_type AS meetingType,
                        meeting_status AS meetingStatus,
                        user_ip AS userIp,
                        meeting_key AS meetingKey,
                        host_password AS hostPassword,
                        presenter_password AS presenterPassword,
                        assistant_password AS assistantPassword,
                        attendee_password AS attendeePassword,
                        capacity,
                        top_node_id AS topNodeId,
                        top_node_addr AS topNodeAddr,
                        user_data AS userData,
                        site_id AS siteId,
                        classroom_number AS classroomNumber,
                        ui_language AS uiLanguage,
                        is_public AS isPublic,
                        control_mode AS controlMode,
                        mic_auto AS micAuto,
                        has_interaction AS hasInteraction,
                        auto_record AS autoRecord,
                        max_videoChannels AS maxVideoChannels,
                        max_audioChannels AS maxAudioChannels,
                        video_quality AS videoQuality,
                        pagenavi_Userprivilege AS pagenaviUserprivilege,
                        marker_Userprivilege AS markerUserprivilege,
                        chatToNormal_Userprivilege AS chatToNormalUserprivilege,
                        chatToHost_Userprivilege AS chatToHostUserprivilege,
                        doc_module AS docModule,
                        screen_module AS screenModule,
                        media_module AS mediaModule,
                        whiteboard_module AS whiteboardModule,
                        record_module AS recordModule,
                        video_module AS videoModule,
                        userList_module AS userListModule,
                        chat_module AS chatModule,
                        cycle,
                        repeatmode,
                        endmode,
                        finalenddate,
                        endcount,
                        repeatday,
                        repeatweek,
                        repeatmonthday,
                        repeatmonthweekweek,
                        repeatmonthweekday,
                        frequency,
                        month_type AS monthType,
                        inviter_radio AS inviterRadio,
                        ahead_time AS aheadTime,
                        chat_interval AS chatInterval,
                        h5_Module AS h5Module
                    FROM
                        3m_meeting AS 3m_meeting
                    WHERE
                        3m_meeting.site_id = 'networkschool'
                    ORDER BY
                        3m_meeting.create_time DESC
                    LIMIT 0,
                    4;`
        let meetingbody = ctx.request.body;
        if(!meetingbody.siteId){
            return status.paramError('siteId');            
        }
        let page = ctx.header.page ? Number(ctx.header.page):ctx.header.page;
        let pageno = ctx.header.pageno ? Number(ctx.header.pageno):ctx.header.pageno;
        var meetingData = await meetingService.getMeeting(meetingbody,page,pageno);
        console.log(meetingData.meetingInfo)
        return meetingData;        
    } catch (error) {
        throw error;
    }
}

meetingController.prototype.delMeeting = async(ctx,next) =>{
    try {
        const meetingId =  ctx.params.meetingId;
        let delMeetingData = await meetingService.delMeeting(meetingId); 
        return delMeetingData       
    } catch (error) {
        throw error;
    }
}
meetingController.prototype.updateMeeting = async(ctx,next) =>{
    try {
        let params = ctx.request.body;
        const meetingId =  ctx.params.meetingId;        
        let updateMeeting = meetingService.updateMeeting(params,meetingId)
        return updateMeeting;
    } catch (error) {
        console.log(error)
        throw error
    }
}

module.exports = new meetingController()