var net = require('net');
var serverHost = "47.96.84.232";
var serverPort = 6003;
var seed_tts="e46120465f5b282a723010232f2d1415"
//var seed_tts="e4621877935b4c2d72310c3b492d2616"
//var ttstring = "[m52][d][h2][v10] 我是科大讯飞中英文语音合成芯片，型号为：[n1]XFS[n1]5152[h1]CE，单次支持超过[n0]2000个中英文字符的语音合成,我已经停产了，大家后续请选用替代方案吧,再见!!!!!";

//var ttstring = "[m3][d][h2][v10] 我是宇音天下中文汉字语音合成芯片，型号为：[n1]SYN[n1]6658，单[=dan1]次支持超过[n0]2000个中文字符的语音合成,源于科大讯飞中英文语音合成芯片[n1]XFS[n1]5152[h1]CE已经停产,接下来就由我代替它为大家服务啦,我除了英文水平还需要进行训练以外，其他的技能都还可以了,我可以读车牌,如浙ABCDEFG，称[=cheng1]重量[d],[v10]如100公斤,我还可以朗读三字经,人之初，性本善。性相近，习相远。苟不教，性乃迁。教之道，贵以专。昔孟母，择邻处。子不学，断机杼,我还可以朗诵圆周率:派[=pai4]=3.14159265358979323846"var ttstring = "[v10]浙ABCD123[d]";
//var ttstring = "[v10]浙A12345[d]";

//var ttstring = "[v5]浙AQ12U5.请扫码进场[d]";
//var ttstring = "[v5]我是一颗柏树[d]";
var ttstring = "[v1]我是一颗柏树,浙A12345[d]";

var client = new net.Socket();


//trunk/src/app/srs_app_config.cpp 
//trunk/src/app/srs_app_server.cpp 
//trunk/src/app/srs_app_config.cpp 
//trunk/src/main/srs_main_ingest_hls.cpp 
//src/main/srs_main_server.cpp 


//curl -o /dev/null -v http://127.0.0.1/softdl/tmp/tts11/105.mp3 --header "Host:softdl.vipvoice.link"

// 路径中包含/audio/时播放SD本地mp3文件
// 路径中包含/purge/时清除本地已缓存的CDN文件

//CDN CACHE路径
var file11 = "rtmp://liveplay.vipvoice.link/live/db1f9155-7e3e-4e3c-8dea-1d673a1cb747?time=1603715820000&expire=3600&token=07b39abb552cdf3167fcb6097ed794af";
var file12 = "rtmp://t1.muchneo.com/live/1111";
var file13 = "http://www.0110iot.cn/DownLoad/File/Broadcast/10156/55de5f2775de4f4ab28f571f9f8d43cb.mp3"
//var file13 = "http://icloudrs.vipvoice.link/SoftWare/tmp/tts/en_US.mp3"
var file14 = "http://icloudrs.vipvoice.link/SoftWare/tmp/tts/ru_SS.mp3"
var file15 = "http://icloudrs.vipvoice.link/SoftWare/tmp/tts/zh_CN.mp3";
var file801 = "http://icloudrs.vipvoice.link/SoftWare/music/101.mp3";
var file802 = "http://icloudrs.vipvoice.link/SoftWare/music/102.mp3";
var file803 = "http://icloudrs.vipvoice.link/SoftWare/music/103.mp3";
var file804 = "http://icloudrs.vipvoice.link/SoftWare/music/104.mp3";
var file805 = "http://icloudrs.vipvoice.link/SoftWare/music/105.mp3";

//http://icloudrs.vipvoice.link/
//中文+-+%2csdfd%2c.%245.。。。。.mp3
//中文 - ,sdfd,.$5.。。。。.mp3

//CDN PURGE路径
var file201 = "http://127.0.0.1/purge/SoftWare/music/101.mp3";
var file202 = "http://127.0.0.1/purge/SoftWare/music/102.mp3";
var file203 = "http://127.0.0.1/purge/SoftWare/music/103.mp3";
var file204 = "http://127.0.0.1/purge/SoftWare/music/104.mp3";
var file205 = "http://127.0.0.1/purge/SoftWare/music/105.mp3";

//本地SD卡路径
var file101 = "http://127.0.0.1/audio/softdl/tmp/tts11/101.mp3";
var file102 = "http://127.0.0.1/audio/softdl/tmp/tts11/102.mp3";
var file103 = "http://127.0.0.1/audio/softdl/tmp/tts11/103.mp3";
var file104 = "http://127.0.0.1/audio/softdl/tmp/tts11/104.mp3";
var file105 = "http://127.0.0.1/audio/softdl/tmp/tts11/105.mp3";


var file22 = "http://softdl.vipvoice.link/softdl/tmp/mp3.txt";


//直播地址
var file302 = "rtmp://liveplay.muchneo.com:8935/live/119911";

/*
	A0 //修改中心源地址
	A1 //添加播放到列表
	A2 //添加到缓存队列
	A3 //添加到更新文件队列
	A4 //停止且清空当前队列  添加新的队列到播放列表
	A5 //停止并清空当前队列
	4) "[payload removed: 232 characters]"
	G*  表示从 redis 获取seed组名 list
*/
  
//A1();

process.argv.forEach(function(val,index,array){
if (val==0){
	A0();
}else if (val=='HTTP'){
	HTTP();
}else if (val=='RTMP'){
	RTMP();
}else if (val==2){
	A2();
}else if (val==3){
	A3();
}else if (val==4){
	A4();
}else if (val=='STOP'){
	STOP();
}else if (val==101){
	A101();
}else if (val==302){
	A302();
}else if (val==1001){
	A1001();
}else if (val=='VOL'){
	VOL();
}else if (val=='VOLX'){
	VOLX();	
}else if (val=='TTS'){
	TTS();
}else if (val=='PURGE'){
	PURGE();
}
});

function STOP(){
	client.connect(serverPort, serverHost, function() 
	{
		console.log('CONNECTED TO:' + serverHost + ':' + serverPort);
		json_content = '{"cmd":"FORCESTOP","snlist":["'+seed_tts+'"] }';
		client.write( json_content);
		console.log(json_content );

        client.on('data', function(data) {
		console.log('Received: '+ data);
		client.destroy();	
	});
	}); 	
}

function PURGE(){
	client.connect(serverPort, serverHost, function() 
	{
		console.log('CONNECTED TO:' + serverHost + ':' + serverPort);
		json_content = '{"cmd":"PURGEFILE","snlist":["'+seed_tts+'"],"filelist":["'+file201+'","'+file202+'","'+file203+'","'+file204+'","'+file205+'"]}';
		client.write( json_content);
		console.log(json_content );
		client.end();
	}); 	
}
function A2(){
	client.connect(serverPort, serverHost, function()
	{
		console.log('CONNECTED TO:' + serverHost + ':' + serverPort);
		json_content = '{"cmd":"PRECACHE","snlist":["'+seed_code+'"],"filelist":["'+file22+'"]}';
		client.write( json_content);
		console.log(json_content );
		client.end();
	}); 	
}
function HTTP(){
	client.connect(serverPort, serverHost, function()
	{
		console.log('CONNECTED TO:' + serverHost + ':' + serverPort);
	//	json_content = '{"cmd":"PLAYOFF","snlist":["'+seed_tts+'"],"filelist":["'+file801+'","'+file802+'","'+file803+'","'+file804+'","'+file805+'"],"loopcount":5}';
		json_content = '{"cmd":"PLAYOFF","snlist":["'+seed_tts+'"],"filelist":["'+file13+'","'+file14+'","'+file15+'"],"loopcount":1}';
		
		client.write( json_content);
		console.log(json_content );
		client.end();
	}); 	
}

function RTMP(){
	client.connect(serverPort, serverHost, function() 
	{
		console.log('CONNECTED TO:' + serverHost + ':' + serverPort);
		json_content = '{"cmd":"PLAYOFF","snlist":["'+seed_tts+'"],"filelist":["'+file302+'"]}';
		
		client.write( json_content);
		console.log(json_content );
			client.on('data', function(data) {
	    console.log('Received: '+ data);
			client.destroy();	
			});
	}); 	
}

function A0(){
	client.connect(serverPort, serverHost, function()
	{
		console.log('CONNECTED TO:' + serverHost + ':' + serverPort);
		json_content = '{"cmd":"MDIFYCENTER","snlist":["'+seed_tts+'"],"originurl":"icloudrs.vipvoice.link:99"}';
		client.write( json_content);
		console.log(json_content );

			client.on('data', function(data) {
	    console.log('Received: '+ data);
			client.destroy();	
			});
	});
}


function A1001(){ 
client.connect(serverPort, serverHost, function() 
{
    console.log('CONNECTED TO:' + serverHost + ':' + serverPort);
    json_content = '{"mode":1001 ,"snlist":["'+seed_tts+'"]}'
    //json_content = '{"mode":1001,"sippwd":"" }'
    client.write(json_content);
    console.log(json_content);

        client.on('data', function(data) {
		console.log('Received: '+ data);
		client.destroy();	
	});
});
}


function VOL(){ 
client.connect(serverPort, serverHost, function() 
{
    console.log('CONNECTED TO:' + serverHost + ':' + serverPort);
    json_content = '{"mode":1009,"snlist":["'+seed_tts+'"],"vol":50}'
    client.write(json_content);
    console.log(json_content);

    client.on('data', function(data) {
		console.log('Received: '+ data);
		client.destroy();	
	});
});
}



function VOLX(){ 
client.connect(serverPort, serverHost, function() 
{
    console.log('CONNECTED TO:' + serverHost + ':' + serverPort);
    json_content = '{"mode":1003,"sn":"'+seed_lanya+'","vol":0}'
    client.write(json_content);
    console.log(json_content);

    client.on('data', function(data) {
		console.log('Received: '+ data);
		client.destroy();	
	});
});
}


function TTS(){ 
client.connect(serverPort, serverHost, function() 
{
    console.log('CONNECTED TO:' + serverHost + ':' + serverPort);
    json_content = '{"cmd":"PLAYTTS","snlist":["'+seed_tts+'"],"ttscontent":"'+ttstring+'"}'
    client.write(json_content);
    console.log(json_content);

        client.on('data', function(data) {
		console.log('Received: '+ data);
		client.destroy();	
	});
});
}


 
//rtmp://192.168.2.100/live/hdevtest
