Commit d6448432965247d73326feaea375b8057e2e0bad
1 parent
ddb716b4
Exists in
master
and in
1 other branch
Supporting callback argument
Showing
1 changed file
with
58 additions
and
9 deletions
Show diff stats
server.js
@@ -125,16 +125,65 @@ app.post('/api', function(req, res){ | @@ -125,16 +125,65 @@ app.post('/api', function(req, res){ | ||
125 | // console.log(stdout); | 125 | // console.log(stdout); |
126 | }); | 126 | }); |
127 | 127 | ||
128 | - /* Listener que dispara quando a requisição ao core finaliza */ | ||
129 | - child.on('close', function(code, signal){ | ||
130 | - res.send(200, { 'response' : 'http://' + SERVER_IP + ':' + port + '/' + ID_FROM_BD + '.flv' }); | ||
131 | - ID_FROM_BD++; | ||
132 | - }); | 128 | + if (req.query.callback === undefined) { |
129 | + /* Listener que dispara quando a requisição ao core finaliza */ | ||
130 | + child.on('close', function(code, signal){ | ||
131 | + res.send(200, { 'response' : 'http://' + SERVER_IP + ':' + port + '/' + ID_FROM_BD + '.flv' }); | ||
132 | + ID_FROM_BD++; | ||
133 | + }); | ||
133 | 134 | ||
134 | - /* Listener que dispara quando a requisição ao core da erro */ | ||
135 | - child.on('error', function(code, signal){ | ||
136 | - res.send(500, parameters.errorMessage('Erro na chamada ao core')); | ||
137 | - }); | 135 | + /* Listener que dispara quando a requisição ao core da erro */ |
136 | + child.on('error', function(code, signal){ | ||
137 | + res.send(500, parameters.errorMessage('Erro na chamada ao core')); | ||
138 | + }); | ||
139 | + } else { | ||
140 | + | ||
141 | + var path = url.parse(req.query.callback); | ||
142 | + | ||
143 | + var data = querystring.stringify({ 'response' : 'http://' + SERVER_IP + ':' + port + '/' + ID_FROM_BD + '.flv' }); | ||
144 | + | ||
145 | + var options = { | ||
146 | + host: path.hostname, | ||
147 | + port: path.port, | ||
148 | + path: path.path, | ||
149 | + method: 'POST', | ||
150 | + headers: { | ||
151 | + 'Content-Type': 'application/x-www-form-urlencoded', | ||
152 | + 'Content-Length': Buffer.byteLength(data) | ||
153 | + } | ||
154 | + }; | ||
155 | + | ||
156 | + var requesting = http.request(options, function(res) { | ||
157 | + res.setEncoding('utf8'); | ||
158 | + }); | ||
159 | + | ||
160 | + requesting.write(data); | ||
161 | + requesting.end(); | ||
162 | + | ||
163 | + /* Listener que dispara quando a requisição ao core da erro */ | ||
164 | + child.on('error', function(code, signal){ | ||
165 | + | ||
166 | + var data = querystring.stringify(parameters.errorMessage('Erro na chamada ao core')); | ||
167 | + | ||
168 | + var options = { | ||
169 | + host: path.hostname, | ||
170 | + port: path.port, | ||
171 | + path: path.path, | ||
172 | + method: 'POST', | ||
173 | + headers: { | ||
174 | + 'Content-Type': 'application/x-www-form-urlencoded', | ||
175 | + 'Content-Length': Buffer.byteLength(data) | ||
176 | + } | ||
177 | + }; | ||
178 | + | ||
179 | + var requesting = http.request(options, function(res) { | ||
180 | + res.setEncoding('utf8'); | ||
181 | + }); | ||
182 | + | ||
183 | + requesting.write(data); | ||
184 | + requesting.end(); | ||
185 | + }); | ||
186 | + } | ||
138 | }); | 187 | }); |
139 | } else { | 188 | } else { |
140 | res.send(500, parameters.errorMessage('Vídeo com Extensão Inválida')); | 189 | res.send(500, parameters.errorMessage('Vídeo com Extensão Inválida')); |