1.优化websocket连接
2.修复游戏实施对局显示错误
This commit is contained in:
@@ -4,15 +4,37 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\common\library\admin;
|
||||
|
||||
use Webman\Http\Request;
|
||||
|
||||
final class WebSocketConfigHelper
|
||||
{
|
||||
public static function wsUrl(): string
|
||||
public static function wsUrl(?Request $request = null): string
|
||||
{
|
||||
$url = trim((string) env('H5_WEBSOCKET_URL', ''));
|
||||
if ($url !== '') {
|
||||
return $url;
|
||||
}
|
||||
return 'ws://127.0.0.1:3131';
|
||||
|
||||
if ($request !== null) {
|
||||
$proto = strtolower((string) $request->header('x-forwarded-proto', ''));
|
||||
if ($proto === '') {
|
||||
$proto = strtolower((string) $request->header('x-forwarded-protocol', ''));
|
||||
}
|
||||
$isHttps = $proto === 'https'
|
||||
|| strtolower((string) $request->header('x-forwarded-ssl', '')) === 'on'
|
||||
|| strtolower((string) $request->header('x-scheme', '')) === 'https';
|
||||
$scheme = $isHttps ? 'wss' : 'ws';
|
||||
|
||||
$host = trim((string) $request->header('host', ''));
|
||||
if ($host === '') {
|
||||
$host = trim((string) $request->header('x-forwarded-host', ''));
|
||||
}
|
||||
if ($host !== '') {
|
||||
return $scheme . '://' . $host . '/ws/';
|
||||
}
|
||||
}
|
||||
|
||||
return 'ws://127.0.0.1:3131/ws/';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user