Skip to content

Instantly share code, notes, and snippets.

@chanakaDe
Last active July 12, 2018 08:37
Show Gist options
  • Save chanakaDe/123080fa5427c38c37f36afdac10be7c to your computer and use it in GitHub Desktop.
Save chanakaDe/123080fa5427c38c37f36afdac10be7c to your computer and use it in GitHub Desktop.
//Some import statements are missing here. Not added.
var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
// Creating the socket connection.
io.sockets.on('connection', function (socket) {
socket.on('join', function (data) {
socket.join(data.id);
});
});
module.exports = function (app, express) {
var api = express.Router();
var gps_location = "";
api.post('/device_location/:child_id', function (req, res) {
var child_id = req.body.child_id;
io.sockets.in(child_id).emit('new_msg', {msg: 'gps_data'}); //Sending request to registered android device.
socket.on("gpsdata", data => {
gps_location = data;
})
//Here i want to take GPS data from android client.
res.json({ type: "success", code: 200, data: gps_location }); //Then i can send the response to anyone who need that.
});
return api;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment