Skip to content

Commit

Permalink
fix received event argument error
Browse files Browse the repository at this point in the history
  • Loading branch information
BUGOVER committed Jan 24, 2024
1 parent e644adb commit 4662e6a
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 94 deletions.
168 changes: 168 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$rules = [
'psr12' => true,
'array_indentation' => true,
'no_unused_imports' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => ['=>' => null],
],
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => [
'statements' => ['return'],
],
'braces' => true,
'cast_spaces' => true,
'class_attributes_separation' => [
'elements' => [
'const' => 'one',
'method' => 'one',
'property' => 'one',
'trait_import' => 'none',
],
],
'class_definition' => [
'multi_line_extends_each_single_line' => true,
'single_item_single_line' => true,
'single_line' => true,
],
'concat_space' => [
'spacing' => 'none',
],
'constant_case' => ['case' => 'lower'],
'declare_equal_normalize' => true,
'elseif' => true,
'encoding' => true,
'full_opening_tag' => true,
'fully_qualified_strict_types' => true, // added by Shift
'function_declaration' => true,
'function_typehint_space' => true,
'general_phpdoc_tag_rename' => true,
'heredoc_to_nowdoc' => true,
'include' => true,
'increment_style' => ['style' => 'post'],
'indentation_type' => true,
'linebreak_after_opening_tag' => true,
'line_ending' => true,
'lowercase_cast' => true,
'lowercase_keywords' => true,
'lowercase_static_reference' => true, // added from Symfony
'magic_method_casing' => true, // added from Symfony
'magic_constant_casing' => true,
'method_argument_space' => [
'on_multiline' => 'ignore',
],
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'native_function_casing' => true,
'no_alias_functions' => true,
'no_extra_blank_lines' => [
'tokens' => [
'extra',
'throw',
'use',
],
],
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_closing_tag' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => [
'use' => 'echo',
],
'no_multiline_whitespace_around_double_arrow' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_after_function_name' => true,
'no_spaces_around_offset' => [
'positions' => ['inside', 'outside'],
],
'no_spaces_inside_parenthesis' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => [
'statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield'],
],
'no_unreachable_default_argument_value' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'not_operator_with_successor_space' => true,
'object_operator_without_whitespace' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'psr_autoloading' => true,
'phpdoc_indent' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_summary' => false,
'phpdoc_to_comment' => false,
'phpdoc_tag_type' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'self_accessor' => true,
'short_scalar_cast' => true,
'simplified_null_return' => false,
'single_blank_line_at_eof' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => [
'elements' => ['const', 'property'],
],
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'single_line_comment_style' => [
'comment_types' => ['hash'],
],
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'switch_case_semicolon_to_colon' => true,
'switch_case_space' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'visibility_required' => [
'elements' => ['method', 'property'],
],
'whitespace_after_comma_in_array' => true,
];


$finder = Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/config',
__DIR__ . '/database',
__DIR__ . '/resources',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new Config())
->setFinder($finder)
->setRules($rules)
->setRiskyAllowed(true)
->setUsingCache(true);
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bugover/laravel-websocket",
"description": "An easy to use WebSocket server",
"version": "1.14.7",
"version": "1.14.8",
"keywords": [
"beyondcode",
"laravel-websockets"
Expand Down Expand Up @@ -43,7 +43,8 @@
"roave/security-advisories": "dev-latest",
"mockery/mockery": "^1.3.3",
"orchestra/testbench": "^4.0|^5.0|^6.0|^7.0|^8.0",
"phpunit/phpunit": "^8.0|^9.0|^10.0"
"phpunit/phpunit": "^8.0|^9.0|^10.0",
"friendsofphp/php-cs-fixer": "^3.0.0"
},
"autoload": {
"psr-4": {
Expand Down
60 changes: 32 additions & 28 deletions resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://js.pusher.com/4.3/pusher.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>

<body>

<div class="container" id="app">
<div class="card col-xs-12 mt-4">
<div class="card-header">
Expand Down Expand Up @@ -87,6 +88,7 @@
</div>
</div>
</div>

<script>
new Vue({
el: '#app',
Expand All @@ -101,7 +103,7 @@
form: {
channel: null,
event: null,
data: null
data: null,
},
logs: [],
},
Expand All @@ -122,14 +124,14 @@
auth: {
headers: {
'X-CSRF-Token': "{{ csrf_token() }}",
'X-App-ID': this.app.id
}
'X-App-ID': this.app.id,
},
},
enabledTransports: ['ws', 'flash']
enabledTransports: ['ws', 'flash'],
});
this.pusher.connection.bind('state_change', states => {
$('div#status').text("Channels current state is " + states.current);
$('div#status').text('Channels current state is ' + states.current);
});
this.pusher.connection.bind('connected', () => {
Expand All @@ -145,10 +147,10 @@
this.pusher.connection.bind('error', event => {
if (event.error.data.code === 4100) {
$('div#status').text("Maximum connection limit exceeded!");
$('div#status').text('Maximum connection limit exceeded!');
this.connected = false;
this.logs = [];
throw new Error("Over capacity");
throw new Error('Over capacity');
}
});
Expand All @@ -169,29 +171,29 @@
x: data.peak_connections.x,
y: data.peak_connections.y,
type: 'lines',
name: '# Peak Connections'
name: '# Peak Connections',
},
{
x: data.websocket_message_count.x,
y: data.websocket_message_count.y,
type: 'bar',
name: '# Websocket Messages'
name: '# Websocket Messages',
},
{
x: data.api_message_count.x,
y: data.api_message_count.y,
type: 'bar',
name: '# API Messages'
}
name: '# API Messages',
},
];
let layout = {
margin: {
l: 50,
r: 0,
b: 50,
t: 50,
pad: 4
}
pad: 4,
},
};
this.chart = Plotly.newPlot('statisticsChart', chartData, layout);
Expand All @@ -207,25 +209,27 @@
'subscribed',
'client-message',
'api-message',
].forEach(channelName => this.subscribeToChannel(channelName))
].forEach(channelName => this.subscribeToChannel(channelName));
},
subscribeToChannel(channel) {
this.pusher.subscribe('{{ \BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger::LOG_CHANNEL_PREFIX }}' + channel)
.bind('log-message', (data) => {
this.pusher.subscribe(
'{{ \BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger::LOG_CHANNEL_PREFIX }}' + channel).
bind('log-message', (data) => {
this.logs.push(data);
});
},
subscribeToStatistics() {
this.pusher.subscribe('{{ \BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger::LOG_CHANNEL_PREFIX }}statistics')
.bind('statistics-updated', (data) => {
var update = {
x: [[data.time], [data.time], [data.time]],
y: [[data.peak_connection_count], [data.websocket_message_count], [data.api_message_count]]
};
this.pusher.subscribe(
'{{ \BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger::LOG_CHANNEL_PREFIX }}statistics').
bind('statistics-updated', (data) => {
var update = {
x: [[data.time], [data.time], [data.time]],
y: [[data.peak_connection_count], [data.websocket_message_count], [data.api_message_count]],
};
Plotly.extendTraces('statisticsChart', update, [0, 1, 2]);
Plotly.extendTraces('statisticsChart', update, [0, 1, 2]);
});
},
Expand Down Expand Up @@ -257,8 +261,8 @@
}).fail(() => {
alert('Error sending event.');
});
}
}
},
},
});
</script>
</body>
Expand Down
6 changes: 6 additions & 0 deletions src/Server/Logger/ConnectionLogger.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace BeyondCode\LaravelWebSockets\Server\Logger;

use Ratchet\ConnectionInterface;
Expand All @@ -9,6 +11,10 @@ class ConnectionLogger extends Logger implements ConnectionInterface
/** @var ConnectionInterface */
protected $connection;

/**
* @param ConnectionInterface $app
* @return self
*/
public static function decorate(ConnectionInterface $app): self
{
$logger = app(self::class);
Expand Down
12 changes: 9 additions & 3 deletions src/Server/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@

class Router
{
/** @var RouteCollection */
protected $routes;
protected $customRoutes;
/**
* @var RouteCollection|null
*/
protected ?RouteCollection $routes = null;

/**
* @var Collection|null
*/
protected ?Collection $customRoutes = null;

public function __construct()
{
Expand Down
Loading

0 comments on commit 4662e6a

Please sign in to comment.