/**
 * Created by kimber on 2021/9/1
 */

import axios from 'axios';



var videoList = [
	{
		name:'1号大棚东南角',
		id:'F84267312',
		captcha:'XMRBLL',
	},{
		name:'2号大棚东北角',
		id:'F84267478',
		captcha:'QORLYM',
	},{
		name:'供电室',
		id:'F84266423',
		captcha:'HCRQUD',
	},{
		name:'2号大棚东南角',
		id:'F93614378',
		captcha:'DWCGKA',
	},{
		name:'4号大棚西南角',
		id:'F93615797',
		captcha:'GQFJGD',
	},{
		name:'1号大棚内部小区',
		id:'F84267305',
		captcha:'KDGHYN',
	},{
		name:'1号大棚内部大区',
		id:'F84267454',
		captcha:'CCQUKT',
	},{
		name:'2号大棚西北角',
		id:'F81374339',
		captcha:'VBETJU',
	},{
		name:'1号大棚西南角',
		id:'F84266468',
		captcha:'FOWQYS',
	},{
		name:'DS-IPC-B12HV2-IA',
		id:'G01704279',
		captcha:'IWHGMK',
	},{
		name:'DS-IPC-B12HV2-IA',
		id:'G01704127',
		captcha:'OLBKBF',
	},{
		name:'4号大棚内部',
		id:'F84267313',
		captcha:'FZHEBC',
	}
];


/**
  * 获取Token
  * @param: {String} appKey
  * @param: {String} appSecret
  *	@example1: getAccessToken('appKey', 'appSecret').then(accessToken => {});
  * @return: 
  * @author: Kimber
  * @updatetime: 
  * @createtime: 2021/9/1
  */
var getAccessToken = function(appKey, appSecret) {
	var dataJson = 'appKey='+appKey+'&appSecret='+appSecret;
	var request = axios.create({});
	request.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
	return request.post("https://open.ys7.com/api/lapp/token/get", dataJson).then(res=>{
		var data = res.data || {};
		if (data['code'] == '200') {
			return data['data']['accessToken']
		}else{
			return null
		}
	}).catch(err=>{
		console.log(err);
		return err
	})
};

export function getVideoIframe(index){
	var item = videoList[index];
	var captcha = item.captcha;
	var id = item.id;

	return getAccessToken('1fede438435146ed9427d92f9926c44c', '494905d1f924b4eaec0142b52eac4697').then(accessToken => {
		var medaUrl = 'ezopen://'+captcha+'@open.ys7.com/'+id+'/1.live&autoplay=1&audio=1&accessToken='+accessToken+'&templete=2';

		return "<iframe src='https://open.ys7.com/ezopen/h5/iframe_se?url="+medaUrl+"' width=\"100%\" height=\"100%\" frameborder=\"no\" border=\"0\" allowfullscreen> </iframe>";
	})
}


export var videoList = videoList;