/// <reference path="../../../Pages/OnlineLearning/OnlineLearningStudentView.aspx" />
/// <reference path="../../../Pages/OnlineLearning/OnlineLearningStudentView.aspx" />
(function () {
    //alert("join");
    //Version Upgrade related changes
    console.log('checkFeatureRequirements');
    console.log(JSON.stringify(ZoomMtg.checkFeatureRequirements()));

    // it's option if you want to change the WebSDK dependency link resources. setZoomJSLib must be run at first
    // if (!china) ZoomMtg.setZoomJSLib('https://source.zoom.us/3.8.0/lib', '/av'); // CDN version default
    // else ZoomMtg.setZoomJSLib('https://jssdk.zoomus.cn/3.8.5/lib', '/av'); // china cdn option 
    // ZoomMtg.setZoomJSLib('http://localhost:9999/node_modules/@zoomus/websdk/dist/lib', '/av'); // Local version default, Angular Project change to use cdn version
    ZoomMtg.preLoadWasm();
    ZoomMtg.prepareWebSDK();

    // var API_KEY = 'LQydYcchSKmgKSQvtigwgw';

    /**
     * NEVER PUT YOUR ACTUAL API SECRET IN CLIENT SIDE CODE, THIS IS JUST FOR QUICK PROTOTYPING
     * The below generateSignature should be done server side as not to expose your api secret in public
     * You can find an eaxmple in here: https://marketplace.zoom.us/docs/sdk/native-sdks/web/essential/signature
     */
    // var API_SECRET = 'T65Mym2wTz8dhtly9GoCslkiEcAevOeQXhGD';

    testTool = window.testTool;
    //document.getElementById('display_name').value = "CDN" + ZoomMtg.getJSSDKVersion()[0] + testTool.detectOS() + "#" + testTool.getBrowserInfo();

    document.getElementById('join_meeting').addEventListener('click', function (e) {
        debugger;
        e.preventDefault();
        // alert("join");
        if (!this.form.checkValidity()) {
            alert("Enter Name and Meeting Number");
            return false;
        }


        var meetConfig = {
            apiKey: document.getElementById('StudentApi_Key').value,
            apiSecret: document.getElementById('StudentSecret_Key').value,
            meetingNumber: parseInt(document.getElementById('meeting_number').value),
            userName: document.getElementById('display_name').value,
            passWord: document.getElementById('meeting_pwd').value,
            leaveUrl: 'OnlineLearningStudentView.aspx',
            role: parseInt(document.getElementById('meeting_role').value, 10)
        };


        var signature = ZoomMtg.generateSDKSignature({
            meetingNumber: meetConfig.meetingNumber,
            sdkKey: meetConfig.apiKey,
            sdkSecret: meetConfig.apiSecret,
            role: meetConfig.role,
            success: function (res) {
                console.log(res.result);
            }
        });

        ZoomMtg.init({
            leaveUrl: 'OnlineLearningStudentView.aspx',
            isSupportAV: true,
            disableInvite: true,
            meetingInfo: [ 
              'topic',
              'host'
            ],
            success: function () {
                ZoomMtg.join(
                    {
                        meetingNumber: meetConfig.meetingNumber,
                        userName: meetConfig.userName,
                        signature: signature,
                        sdkKey: meetConfig.apiKey,
                        passWord: meetConfig.passWord,
                        success: function (res) {
                            $('#nav-tool').hide();
                            console.log('join meeting success');
                        },
                        error: function (res) {
                            console.log(res);
                        }
                    }
                );
                ZoomMtg.showInviteFunction({
                    show: false
                })
            },
            
            error: function (res) {
                console.log(res);
            }
        });

    });

})();
