-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManagerServer.js
More file actions
160 lines (115 loc) · 3.12 KB
/
ManagerServer.js
File metadata and controls
160 lines (115 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//Creates a socket on localhost with port of 5001
//var socket = require('socket.io-client')('http://3.83.222.75:5001');
var socket = require('socket.io-client')('http://localhost:5001');
//Allows for server to take user input
//this is for testing
//TODO make the manager server cool and good
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
})
//global vars for this server
var sessionId = "";
/*
//takes user console inputs
*/
//creates a new session
function createSession(){
socket.emit("start", (a) =>{
console.log("Created session with id of " + a);
sessionId = a;
});
}
//merges to an old session
function mergeSession(){
socket.emit("resume", sessionId, (a) => {
if(a == "Y"){
console.log("Merged with session: " + a);
}else{
console.log("Failed to merge with session: " + a);
}
});
}
function makeVideo(){
let videoObject = {
subreddit: "askreddit",
harshness: 3,
numberOfPosts: 5,
resolution: [1920, 1080]
}
socket.emit("makeVideo", sessionId, "comment", videoObject, (a) => {
console.log(a);
});
}
//when a user/server connects to the server through sockets
socket.on('connect', function(){
console.log("Connected with server");
if(sessionId == ""){
createSession();
}else{
mergeSession();
}
});
//when a user/server disconects
socket.on('disconnect', function(){
console.log("Disconnected from server");
});
//when the server gets a video update
socket.on('serverUpdate', (a, c) => {
console.log(a);
});
var recursiveAsyncMenu = () => {
readline.question(`\nWhat do you want to do?\nC: create new session\nM: merge with session\nV: make a video\nS: get status\n\n`, (a) => {
if(a == "C"){
createSession();
}
if(a == "M"){
}
if(a == "V"){
console.log("making video ")
makeVideo();
}
if(a == "S"){
}
readline.close()
recursiveAsyncMenu();
});
}
recursiveAsyncMenu();
/*
//
//
//Used for getting the status of the video server
//
//when the server recieves the 'getStatus' message
function bar(timeout = 10000) {
return new Promise((resolve, reject) => {
socket.emit('status', 'test', function(response) {
console.log("client got ack response", response);
resolve(response);
});
});
}
var status = ""
let getStatus = bar().then(value => {
var c = "";
status = String(value);
});
function GetStatus(){
getStatus;
return status;
}
function MakeVideo(videoType, subreddit, harshness, max_length){
socket.emit("makeVideo", videoType, subreddit, harshness, max_length, function(response){
if(response == "yes"){
console.log("making video with type: " + videoType);
}else{
console.log("sever said no :(");
}
});
}
var sserver = () => {
console.log("yeet " + GetStatus());
MakeVideo("comments", "askreddit", 1000, 10);
}
*/