From d3045b70f533fdf6d0d9fe0b57f890c2bfa435ed Mon Sep 17 00:00:00 2001 From: johan Date: Wed, 4 Jan 2023 15:46:07 +0100 Subject: [PATCH] essai --- WEB/Controller/UserController.php | 2 +- WEB/server.js | 27 --------------------------- WEB/server.php | 27 +++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 28 deletions(-) delete mode 100644 WEB/server.js create mode 100644 WEB/server.php diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index e38daadc..87b4762d 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -205,7 +205,7 @@ class UserController $model = new UserModel(); $model->addToQueue(); $userGroup = $model->findUserGroup(); - $io = get_io(); + $io = getenv('io'); $io->to($userGroup)->emit("launchGame"); } catch (Exception $e) { $error = $e->getMessage(); diff --git a/WEB/server.js b/WEB/server.js deleted file mode 100644 index 0ed47547..00000000 --- a/WEB/server.js +++ /dev/null @@ -1,27 +0,0 @@ -//const io = require('socket.io')('http://localhost:3000'); -//modules -module = '/usr/local/lib/node_modules/'; -console.log('module'); -const express = require(module + "express"); -console.log('express'); -const socketIO = require(module +"socket.io");//('http://82.165.180.114:3000'); -console.log('socketIO'); -const app = express(); -console.log('app'); -const server = app.listen(3000); -const io =socketIO(server); -io.on('connection', socket => { - console.log("connection de l'utilisateur à l'id ". socket.id); -}) -console.log('ioOnConnection'); - -io.on('launchGame' , function () { - console.log('launch the game'); - location.reload(); -}) - -module.exports = { - io: io - }; - -console.log('iolisten'); \ No newline at end of file diff --git a/WEB/server.php b/WEB/server.php new file mode 100644 index 00000000..ff87bb21 --- /dev/null +++ b/WEB/server.php @@ -0,0 +1,27 @@ +listen(3000); + +// Créer l'objet socket.io en lui passant le serveur +$io = require('/usr/local/lib/node_modules/socket.io')($server); + +// Quand un utilisateur se connecte +$io->on('connection', function ($socket) { + echo "connection de l'utilisateur à l'id " . $socket->id; +}); + +// Quand un utilisateur lance le jeu +$io->on('launchGame', function () { + echo 'launch the game'; + header('Location: index.php'); +}); + +// Exporter l'objet socket.io +putenv("io=$io"); + +echo 'iolisten'; +?> \ No newline at end of file