create-prisma-php-app 1.3.9 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -186
- package/composer-websocket.lock +1993 -0
- package/dist/index.js +1 -1
- package/dist/prisma-client-php/index.enc +1 -1
- package/dist/settings/bs-config.cjs +2 -0
- package/dist/settings/restartWebsocket.cjs +53 -0
- package/dist/settings/restart_websocket.bat +30 -0
- package/dist/src/app/js/index.js +1 -4
- package/dist/src/lib/websocket/ConnectionManager.php +39 -0
- package/dist/src/lib/websocket/server.php +19 -0
- package/package.json +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const { spawn } = require("child_process");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
// Define paths
|
|
5
|
+
const phpPath = "php"; // Adjust if necessary to include the full path to PHP
|
|
6
|
+
const serverScriptPath = path.join(
|
|
7
|
+
__dirname,
|
|
8
|
+
"..",
|
|
9
|
+
"src",
|
|
10
|
+
"lib",
|
|
11
|
+
"websocket",
|
|
12
|
+
"server.php"
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
// Hold the server process
|
|
16
|
+
let serverProcess = null;
|
|
17
|
+
|
|
18
|
+
const restartServer = () => {
|
|
19
|
+
// If a server process already exists, kill it
|
|
20
|
+
if (serverProcess) {
|
|
21
|
+
console.log("Stopping WebSocket server...");
|
|
22
|
+
serverProcess.kill("SIGINT"); // Adjust the signal as necessary for your environment
|
|
23
|
+
serverProcess = null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Start a new WebSocket server process
|
|
27
|
+
console.log("Starting WebSocket server...");
|
|
28
|
+
serverProcess = spawn(phpPath, [serverScriptPath]);
|
|
29
|
+
|
|
30
|
+
serverProcess.stdout.on("data", (data) => {
|
|
31
|
+
console.log(`WebSocket Server: ${data}`);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
serverProcess.stderr.on("data", (data) => {
|
|
35
|
+
console.error(`WebSocket Server Error: ${data}`);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
serverProcess.on("close", (code) => {
|
|
39
|
+
console.log(`WebSocket server process exited with code ${code}`);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Initial start
|
|
44
|
+
restartServer();
|
|
45
|
+
|
|
46
|
+
// Watch for changes and restart the server
|
|
47
|
+
const chokidar = require("chokidar");
|
|
48
|
+
chokidar
|
|
49
|
+
.watch(path.join(__dirname, "..", "src", "lib", "websocket", "**", "*"))
|
|
50
|
+
.on("change", (event, path) => {
|
|
51
|
+
console.log(`${event}: ${path}`);
|
|
52
|
+
restartServer();
|
|
53
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
set PORT=8080
|
|
3
|
+
set "PHP_PATH=php"
|
|
4
|
+
set "SERVER_SCRIPT_PATH= src\lib\websocket\server.php"
|
|
5
|
+
|
|
6
|
+
echo [INFO] Checking for processes using port %PORT%...
|
|
7
|
+
netstat -aon | findstr :%PORT%
|
|
8
|
+
|
|
9
|
+
for /f "tokens=5" %%a in ('netstat -aon ^| findstr :%PORT%') do (
|
|
10
|
+
echo [INFO] Found PID: %%a
|
|
11
|
+
taskkill /F /PID %%a
|
|
12
|
+
if %ERRORLEVEL% == 0 (
|
|
13
|
+
echo [SUCCESS] Killed process %%a.
|
|
14
|
+
) else (
|
|
15
|
+
echo [ERROR] Failed to kill process %%a.
|
|
16
|
+
)
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
:: Ensure the previous command's failure does not prevent the server from starting
|
|
20
|
+
:: Wait a bit to ensure the port is freed
|
|
21
|
+
timeout /t 2
|
|
22
|
+
|
|
23
|
+
:: Start the WebSocket server
|
|
24
|
+
echo [INFO] Starting WebSocket server on port %PORT%...
|
|
25
|
+
%PHP_PATH% %SERVER_SCRIPT_PATH%
|
|
26
|
+
if %ERRORLEVEL% == 0 (
|
|
27
|
+
echo [SUCCESS] WebSocket server started.
|
|
28
|
+
) else (
|
|
29
|
+
echo [ERROR] Failed to start WebSocket server.
|
|
30
|
+
)
|
package/dist/src/app/js/index.js
CHANGED
|
@@ -138,12 +138,9 @@ class StateManager {
|
|
|
138
138
|
*
|
|
139
139
|
* @param {*} update
|
|
140
140
|
*/
|
|
141
|
-
setState(update
|
|
141
|
+
setState(update) {
|
|
142
142
|
this.state = { ...this.state, ...update };
|
|
143
143
|
this.listeners.forEach((listener) => listener(this.state));
|
|
144
|
-
if (saveToStorage) {
|
|
145
|
-
this.saveState();
|
|
146
|
-
}
|
|
147
144
|
}
|
|
148
145
|
|
|
149
146
|
/**
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Lib\Websocket;
|
|
4
|
+
|
|
5
|
+
use Ratchet\MessageComponentInterface;
|
|
6
|
+
use Ratchet\ConnectionInterface;
|
|
7
|
+
|
|
8
|
+
class ConnectionManager implements MessageComponentInterface
|
|
9
|
+
{
|
|
10
|
+
protected $clients;
|
|
11
|
+
|
|
12
|
+
public function __construct()
|
|
13
|
+
{
|
|
14
|
+
$this->clients = new \SplObjectStorage;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public function onOpen(ConnectionInterface $conn)
|
|
18
|
+
{
|
|
19
|
+
$this->clients->attach($conn);
|
|
20
|
+
echo "New connection! ({$conn->resourceId})\n";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public function onMessage(ConnectionInterface $from, $msg)
|
|
24
|
+
{
|
|
25
|
+
// Message handling code
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public function onClose(ConnectionInterface $conn)
|
|
29
|
+
{
|
|
30
|
+
$this->clients->detach($conn);
|
|
31
|
+
echo "Connection {$conn->resourceId} has disconnected\n";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public function onError(ConnectionInterface $conn, \Exception $e)
|
|
35
|
+
{
|
|
36
|
+
echo "An error has occurred: {$e->getMessage()}\n";
|
|
37
|
+
$conn->close();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
require __DIR__ . '/../../../vendor/autoload.php';
|
|
4
|
+
|
|
5
|
+
use Ratchet\Server\IoServer;
|
|
6
|
+
use Ratchet\Http\HttpServer;
|
|
7
|
+
use Ratchet\WebSocket\WsServer;
|
|
8
|
+
use Lib\Websocket\ConnectionManager;
|
|
9
|
+
|
|
10
|
+
$server = IoServer::factory(
|
|
11
|
+
new HttpServer(
|
|
12
|
+
new WsServer(
|
|
13
|
+
new ConnectionManager()
|
|
14
|
+
)
|
|
15
|
+
),
|
|
16
|
+
8080
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
$server->run();
|