Commit 1c9f1bcf authored by Rolando Neira's avatar Rolando Neira

Incorporación del websocket cliente en el api rest de las pantallas

parent f31329c7
//https://medium.com/@asfo/desarrollando-una-sencilla-api-rest-con-nodejs-y-express-cab0813f7e4b
const express = require("express"),
bodyParser = require('body-parser'),
app = express(),
apiRoutes = require("./routes/api-routes")
port = process.env.PORT || 3000;
//===================================Variables de la api================================================================================
const express = require("express"), //Importo express para ejecutar mi servidor
bodyParser = require('body-parser'), // Importo body para parsear la respueta que e devolvera a la peticion
app = express(),//Creo una instancia de epress paa el servidor
apiRoutes = require("./routes/api-routes"), //Importo las rutas de las apis
appport = process.env.PORT || 3000; //puerto de la aplicacion express
//===================================Fin Variables de la api================================================================================
//======================================Api====================================================
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use('/api', apiRoutes);
......@@ -19,6 +22,7 @@ app.use(function (req, res, next) {
res.status(404).send(respuesta);
});
app.listen(port, () => {
console.log("El servidor está inicializado en el puerto: " + port);
});
\ No newline at end of file
app.listen(appport, () => {
console.log("El servidor está inicializado en el puerto: " + appport);
});
//======================================Fin Api====================================================
\ No newline at end of file
......@@ -15,10 +15,9 @@
"express": "^4.17.1",
"moment": "^2.24.0",
"mongoose": "^5.9.3",
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.0",
"underscore": "^1.9.2",
"websocket": "^1.0.31"
"sockjs": "^0.3.19",
"underscore": "^1.9.2"
},
"devDependencies": {
"nodemon": "^2.0.2"
......
//http://localhost:3000/api/setvideos/5e5fdfe92968283228069ad1
const router = require('express').Router(), mongoose = require('mongoose'), Pantalla = require('../models/Pantalla.model'), io = require("socket.io-client");
//===================================Variables del api=======================================================================================
const router = require('express').Router(),
mongoose = require('mongoose'),
Pantalla = require('../models/Pantalla.model');
//===================================Fin de variables del api================================================================================
//===================================Variables del websocketi================================================================================
var io = require('socket.io-client');
//===================================Fin Variables del websocket================================================================================
//======================================Socket===============================================================================================
var socket = io.connect('http://10.131.0.30:5000', {reconnect: true});
socket.on('connect', function (socket) {
console.log('Conexión exitosa al socket de pantallas!');
});
//======================================Fin Socket===========================================================================================
//======================================Base de datos========================================================================================
mongoose.connect('mongodb://127.0.0.1/pantallasdb');
mongoose.Promise = global.Promise;// Hacer que Mongoose use la biblioteca de forma globales
const db = mongoose.connection;//Almaceno en una variabla la conexion de mongodb
db.on('error', console.error.bind(console, 'MongoDB error de conexión:'));// Vincula la conexión al evento de error (para recibir notificaciones de errores de conexión)
//======================================Fin Base de datos====================================================================================
//======================================Api==================================================================================================
//Json de respuesta para cada api
let respuesta = {
error: false,
......@@ -14,7 +31,6 @@ let respuesta = {
mensaje: ''
};
/* Agregar una nueva pantalla */
router.post('/newpantalla', function(req, res, next) {
Pantalla.findOne({name: req.body.name}, function(error_buscar, pant){
......@@ -70,6 +86,7 @@ router.get('/setvideos/:id', function (req, res) {
codigo: 500,
mensaje: 'Error, es imposible buscar los datos.'
};
res.send(respuesta);
}else{
//Verificar si exiate la pantalla o no
if(!pant){
......@@ -77,20 +94,20 @@ router.get('/setvideos/:id', function (req, res) {
error: true,
codigo: 300,
mensaje: 'La pantalla no existe.'
};
};
res.send(respuesta);
}else{
let ioClient = io.connect("10.131.0.30:5000");
ioClient.emit("actualizar_api", {id: pant._id});
ioClient.disconnect("disconnect");
respuesta = {
error: false,
codigo: 200,
mensaje: 'Videos establecidos para la pantalla: '+ pant.name
mensaje: 'Videos establecidos para el cliente: '+ pant.name
};
}
socket.emit('actualizar_api', {id: pant._id});
res.send(respuesta);
}
}
res.send(respuesta);
});
});
// Export API routes
module.exports = router;
\ No newline at end of file
module.exports = router;
//======================================Fin de Api==================================================================================================
\ No newline at end of file
......@@ -14,14 +14,14 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_PixelRect:
serializedVersion: 2
x: 0
y: 43.2
width: 1536
height: 781
x: 7.2000003
y: 50.4
width: 1522
height: 767
m_ShowMode: 4
m_Title:
m_RootView: {fileID: 2}
m_MinSize: {x: 950, y: 300}
m_MinSize: {x: 950, y: 548}
m_MaxSize: {x: 10000, y: 10000}
--- !u!114 &2
MonoBehaviour:
......@@ -43,9 +43,9 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1536
height: 781
m_MinSize: {x: 950, y: 300}
width: 1522
height: 767
m_MinSize: {x: 950, y: 548}
m_MaxSize: {x: 10000, y: 10000}
--- !u!114 &3
MonoBehaviour:
......@@ -64,7 +64,7 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1536
width: 1522
height: 30
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
......@@ -85,8 +85,8 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 761
width: 1536
y: 747
width: 1522
height: 20
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
......@@ -109,8 +109,8 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 30
width: 1536
height: 731
width: 1522
height: 717
m_MinSize: {x: 787, y: 498}
m_MaxSize: {x: 16012, y: 14048}
vertical: 0
......@@ -134,12 +134,12 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1145
height: 731
width: 1135
height: 717
m_MinSize: {x: 510, y: 498}
m_MaxSize: {x: 12010, y: 14048}
vertical: 1
controlID: 95
controlID: 75
--- !u!114 &7
MonoBehaviour:
m_ObjectHideFlags: 52
......@@ -160,8 +160,8 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1145
height: 457
width: 1135
height: 443
m_MinSize: {x: 510, y: 224}
m_MaxSize: {x: 12010, y: 4024}
vertical: 0
......@@ -183,8 +183,8 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 328
height: 457
width: 325
height: 443
m_MinSize: {x: 202, y: 224}
m_MaxSize: {x: 4002, y: 4024}
m_ActualView: {fileID: 14}
......@@ -207,10 +207,10 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 328
x: 325
y: 0
width: 364
height: 457
width: 361
height: 443
m_MinSize: {x: 204, y: 224}
m_MaxSize: {x: 4004, y: 4024}
m_ActualView: {fileID: 15}
......@@ -233,10 +233,10 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 692
x: 686
y: 0
width: 453
height: 457
width: 449
height: 443
m_MinSize: {x: 104, y: 124}
m_MaxSize: {x: 4004, y: 4024}
m_ActualView: {fileID: 16}
......@@ -261,8 +261,8 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 457
width: 1145
y: 443
width: 1135
height: 274
m_MinSize: {x: 232, y: 274}
m_MaxSize: {x: 10002, y: 10024}
......@@ -291,10 +291,10 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 1145
x: 1135
y: 0
width: 391
height: 731
width: 387
height: 717
m_MinSize: {x: 277, y: 74}
m_MaxSize: {x: 4002, y: 4024}
m_ActualView: {fileID: 23}
......@@ -349,17 +349,17 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 0
y: 73.6
width: 326
height: 437
x: 7.2000003
y: 80.8
width: 323
height: 423
m_PersistentViewDataDictionary: {fileID: 0}
m_SceneHierarchy:
m_TreeViewState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_SelectedIDs: 30310000
m_LastClickedID: 0
m_ExpandedIDs: b2fbffff
m_ExpandedIDs: 24f4ffffa2f4ffff0cf5ffff78f5ffffc6f5ffff34f6ffff56f7ffff58f8ffffb4f9ffffb2fbffff
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
......@@ -404,10 +404,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 328
y: 73.6
width: 360
height: 437
x: 332
y: 80.8
width: 357
height: 423
m_PersistentViewDataDictionary: {fileID: 0}
m_MaximizeOnPlay: 0
m_Gizmos: 0
......@@ -440,25 +440,25 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 17
width: 360
height: 420
m_Scale: {x: 0.2734375, y: 0.2734375}
m_Translation: {x: 180, y: 210}
width: 357
height: 406
m_Scale: {x: 0.2643229, y: 0.2643229}
m_Translation: {x: 178.5, y: 203}
m_MarginLeft: 0
m_MarginRight: 0
m_MarginTop: 0
m_MarginBottom: 0
m_LastShownAreaInsideMargins:
serializedVersion: 2
x: -658.2857
x: -675.31036
y: -768
width: 1316.5714
width: 1350.6207
height: 1536
m_MinimalGUI: 1
m_defaultScale: 0.2734375
m_defaultScale: 0.2643229
m_TargetTexture: {fileID: 0}
m_CurrentColorSpace: 0
m_LastWindowPixelSize: {x: 450, y: 546.25}
m_LastWindowPixelSize: {x: 446.25, y: 528.75}
m_ClearInEditMode: 1
m_NoCameraWarning: 1
m_LowResolutionForAspectRatios: 01000000000100000100
......@@ -484,10 +484,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 692
y: 73.6
width: 449
height: 437
x: 693.60004
y: 80.8
width: 445
height: 423
m_PersistentViewDataDictionary: {fileID: 0}
m_WindowGUID: c387872c2041eab4aaccd64c53906429
m_SceneLighting: 1
......@@ -564,9 +564,9 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 0
y: 530.4
width: 1143
x: 7.2000003
y: 523.2
width: 1133
height: 254
m_PersistentViewDataDictionary: {fileID: 0}
m_SearchFilter:
......@@ -581,19 +581,19 @@ MonoBehaviour:
m_ShowAllHits: 0
m_SearchArea: 1
m_Folders:
- Assets/importados/youtube
- Assets/escenas
m_ViewMode: 1
m_StartGridSize: 16
m_LastFolders:
- Assets/importados/youtube
- Assets/escenas
m_LastFoldersGridSize: 16
m_LastProjectPath: C:\Users\ROLAS\Documents\NODOLAB\GIT\pantallas\PantallitaNodo_V2.0\PantallaNodo
m_LockTracker:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 391}
m_SelectedIDs: de480000
m_LastClickedID: 18654
scrollPos: {x: 0, y: 0}
m_SelectedIDs: 1c490000
m_LastClickedID: 18716
m_ExpandedIDs: 00000000742f000062360000ae360000bc360000f03600007e3800003c3a0000543c00004a3d00001e3e0000c03f0000a4400000f8410000364200007043000018440000e44700001c490000f84b00001453000016530000185300001a5300001c530000
m_RenameOverlay:
m_UserAcceptedRename: 0
......@@ -649,22 +649,22 @@ MonoBehaviour:
m_ListAreaState:
m_SelectedInstanceIDs:
m_LastClickedInstanceID: 0
m_HadKeyboardFocusLastEvent: 0
m_HadKeyboardFocusLastEvent: 1
m_ExpandedInstanceIDs: c6230000243b000068380000925a0000903100009c400000b648000086fd000090490000024400003257000028720000384a00002e5700008e590000226b0000063b00003e8e0000a8d3feff023b0000b84b0000068a0000565b00007e4b0000ba4c0000445b0000d04b0000083700003e2f0000e03f000080e0fbff720df5ff483700002e510000cc400000404000006c7100003a2f00001e610000bc40000070340000744c0000f0480000204600007664000086390000284100008c40000082340000e24e00007a4b0000c23d000070380000a25700005cb2fcff72380000fe42000092350000cc36000020490000f630000026360000a2bc0000c44f0000963500007a350000882a0000642a00000e2b0000f432000044ca0000cc2f000028370000982e00007a360000d82d0000ea3c0000a62e0000323f0000523f0000c61f0100d61e010044180000ee1d00005619000008170000f8320500f6320500701c0000024300003c3200000236000096440000283900002c3e0000e6410000663d00007c3b0000ec360000243600006e460000b4800000483401004c3401005c340100c23f0000e8480000363c0000a04100007c46000076350000d87500005a370000a0470000f4430000bc4300005a2f0000e83a0000763b0000444b0000743c000062370000a84700006263000068450000446e0000344c000050510000185d000032420000083800009e3c0000305a000000000000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
m_OriginalName:
m_Name: SceneLoadingData
m_OriginalName: SceneLoadingData
m_EditFieldRect:
serializedVersion: 2
x: 0
y: 0
width: 0
height: 0
m_UserData: 0
m_UserData: 12592
m_IsWaitingForDelay: 0
m_IsRenaming: 0
m_OriginalEventType: 11
m_OriginalEventType: 0
m_IsRenamingFilename: 1
m_ClientGUIView: {fileID: 11}
m_CreateAssetUtility:
......@@ -698,9 +698,9 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 0
y: 530.4
width: 1143
x: 7.2000003
y: 523.2
width: 1133
height: 254
m_PersistentViewDataDictionary: {fileID: 0}
--- !u!114 &19
......@@ -1627,10 +1627,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 1144.8
y: 73.6
width: 389
height: 711
x: 1142.4
y: 80.8
width: 385
height: 697
m_PersistentViewDataDictionary: {fileID: 0}
m_ObjectsLockedBeforeSerialization: []
m_InstanceIDsLockedBeforeSerialization:
......
sceneSetups:
- path: Assets/importados/youtube/Evereal/YoutubeDLPlayer/Scenes/Demo_03_UI.unity
- path: Assets/escenas/SceneLoadingData.unity
isLoaded: 1
isActive: 1
Base path: C:/Program Files/Unity/Editor/Data
Cmd: initializeCompiler
Cmd: initializeCompiler
Cmd: initializeCompiler
Cmd: initializeCompiler
Cmd: initializeCompiler
Cmd: initializeCompiler
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment