[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] Add support for custom WebSocket base URL in realtime preferences

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68d4bfc2b4a59_2cdf48079ae@gitlab-sidekiq-low-urgency-cpu-bound-v2-5699cfdd5c-gbqkf.mail>

Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
e06ef7d6 by Elvis Ansima at 2025-09-25T03:58:38+00:00
[ENH] Add support for custom WebSocket base URL in realtime preferences
---
* [FIX] Correct indentation in tiki-check.php

* [FIX] Set default WebSocket port to 8080 if not specified in the base URL

* [ENH] Add support for custom WebSocket base URL in realtime preferences

See merge request tikiwiki/tiki!8621

- - - - -


5 changed files:

- lib/prefs/realtime.php
- lib/setup/javascript.php
- templates/admin/include_general.tpl
- tiki-check.php
- tiki-realtime.php


Changes:

=====================================
lib/prefs/realtime.php
=====================================
@@ -20,5 +20,17 @@ function prefs_realtime_list()
                 'feature_realtime',
             ],
         ],
+        'realtime_full_base_url' => [
+            'name' => tra('Realtime base URL'),
+            'description' => tr('Full WebSocket base URL for the realtime server. When set, it overrides host/port derived from Tiki preferences. Example: ws://localhost:8080/'),
+            'type' => 'text',
+            'size' => 5,
+            'default' => '',
+            'shorthint' => tr('Leave blank to use the instance URL and realtime_port'),
+            'tags' => ['advanced'],
+            'dependencies' => [
+                'feature_realtime',
+            ],
+        ]
     ];
 }


=====================================
lib/setup/javascript.php
=====================================
@@ -376,7 +376,12 @@ EOT;
 }
 
 if ($prefs['feature_realtime'] === 'y') {
-    $ws_url = json_encode(preg_replace('#http://#', 'ws://', preg_replace('#https://#', 'wss://', $base_url)) . 'ws/');
+    $websocket_full_base_url = $prefs['realtime_full_base_url'];
+    if (empty($websocket_full_base_url)) {
+        $ws_url = json_encode(preg_replace('#http://#', 'ws://', preg_replace('#https://#', 'wss://', $base_url)) . 'ws/');
+    } else {
+        $ws_url = json_encode($websocket_full_base_url);
+    }
     $session_token = session_id();
 
     $js .= <<<EOT


=====================================
templates/admin/include_general.tpl
=====================================
@@ -217,6 +217,7 @@
                 {preference name=feature_realtime}
                 <div class="adminoptionboxchild" id="feature_realtime_childcontainer">
                     {preference name=realtime_port}
+                    {preference name=realtime_full_base_url}
                 </div>
                 {preference name=php_cli_path}
             </fieldset>


=====================================
tiki-check.php
=====================================
@@ -4757,6 +4757,11 @@ if ($standalone && ! $nagios) {
         'MCrypt' => $criptLib->getUserCryptDataStats('mcrypt'),
     ));
     $ws_port = $prefs['realtime_port'] ? $prefs['realtime_port'] : '8080';
+    $websocket_full_base_url = $prefs['realtime_full_base_url'];
+    if (! empty($websocket_full_base_url)) {
+        $parts = parse_url($websocket_full_base_url);
+        $ws_port = $parts['port'] ?? null;
+    }
     $ws_conn = @fsockopen('localhost', $ws_port);
     if (is_resource($ws_conn)) {
         $ws_listening = true;
@@ -4791,7 +4796,11 @@ if ($standalone && ! $nagios) {
         )
     );
     $smarty->assign('realtime', $realtime);
-    $smarty->assign('realtime_url', preg_replace('#http://#', 'ws://', preg_replace('#https://#', 'wss://', $base_url)) . 'ws/');
+    if (! empty($websocket_full_base_url)) {
+        $smarty->assign('realtime_url', $websocket_full_base_url);
+    } else {
+        $smarty->assign('realtime_url', preg_replace('#http://#', 'ws://', preg_replace('#https://#', 'wss://', $base_url)) . 'ws/');
+    }
 
     $output = array();
     $locales = null;


=====================================
tiki-realtime.php
=====================================
@@ -8,6 +8,10 @@
 //
 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+
+// Turn off any compression and buffering that would delay CLI output
+$force_no_compression = true;
+
 require_once('tiki-setup.php');
 
 $access = TikiLib::lib('access');
@@ -40,21 +44,51 @@ Start WS server with the same user that Tiki web requests run as (to avoid permi
 error_reporting(E_ALL);
 ini_set('session.use_cookies', 0);
 
-// Run the server application through the WebSocket protocol on specified port (default: 8080)
-$opts = getopt("p::");
-if (isset($opts['p'])) {
-    $port = $opts['p'];
-} elseif (! empty($prefs['realtime_port'])) {
-    $port = $prefs['realtime_port'];
+$websocket_full_base_url = $prefs['realtime_full_base_url'];
+
+if (! empty($websocket_full_base_url)) {
+    $parts = parse_url($websocket_full_base_url);
+    $port = $parts['port'] ?? 8080;
+    echo "Using data from realtime full base url preference: " . $websocket_full_base_url . " \n";
 } else {
-    $port = 8080;
+    // Run the server application through the WebSocket protocol on specified port (default: 8080)
+    $opts = getopt("p::");
+    if (isset($opts['p'])) {
+        $port = $opts['p'];
+    } elseif (! empty($prefs['realtime_port'])) {
+        $port = $prefs['realtime_port'];
+    } else {
+        $port = 8080;
+    }
 }
 $tikilib->set_preference('realtime_port', $port);
+echo "Starting Tiki Realtime WebSocket Server...\n";
+echo "Port: $port\n";
+echo "Host: localhost\n";
+
+// Validate port
+if (! is_numeric($port) || $port < 1 || $port > 65535) {
+    echo "Error: Invalid port number '$port'. Port must be between 1 and 65535.\n";
+    exit(1);
+}
+
 echo "Listening on port $port...\n";
 
-$app = new Ratchet\App('localhost', $port);
-$app->route('/console', new Console(), ['*']);
-$app->route('/chat', new Chat(), ['*']);
-$app->route('ping', new Ping(), ['*']);
-$app->route('/iot-dashboard-notifier', new IotDashboardNotifier(), ['*']);
-$app->run();
+try {
+    $app = new Ratchet\App('localhost', $port);
+    $app->route('/console', new Console(), ['*']);
+    $app->route('/chat', new Chat(), ['*']);
+    $app->route('ping', new Ping(), ['*']);
+    $app->route('/iot-dashboard-notifier', new IotDashboardNotifier(), ['*']);
+    echo "WebSocket routes configured:\n";
+    echo "  - /console\n";
+    echo "  - /chat\n";
+    echo "  - /ping\n";
+    echo "  - /iot-dashboard-notifier\n";
+    echo "Server is running. Press Ctrl+C to stop.\n";
+    $app->run();
+} catch (Exception $e) {
+    echo "Error: " . $e->getMessage() . "\n";
+    echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
+    exit(1);
+}



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e06ef7d6eede58446c52ab14d9a1d6729422a529

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e06ef7d6eede58446c52ab14d9a1d6729422a529
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.