swooletw / laravel-swoole

High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
MIT License
4.04k stars 390 forks source link

Websocket Emit ErrorException #489

Closed RicardoGuiliani closed 3 years ago

RicardoGuiliani commented 3 years ago

Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks! (Any non-English issues will be closed immediately.)

  1. Please provide your PHP and Swoole version. (php -v and php --ri swoole)
php -v

PHP 8.0.5 (cli) (built: May  3 2021 11:30:57) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.5, Copyright (c) Zend Technologies
with Zend OPcache v8.0.5, Copyright (c), by Zend Technologies
php --ri swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.6.7-dev
Built => May  8 2021 16:50:55
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1f  31 Mar 2020
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. Please provide your Laravel/Lumen version. Laravel Framework Lumen (8.2.3) (Laravel Components ^8.0)

  2. Which release version of this package are you using? v2.8.1

  3. What did you do? If possible, provide a recipe for reproducing the error.

<?php

use Illuminate\Http\Request;
use SwooleTW\Http\Websocket\Facades\Websocket;

/*
|--------------------------------------------------------------------------
| Websocket Routes
|--------------------------------------------------------------------------
*/

Websocket::on('connect', function ($websocket, $request) {
  // in connect callback, illuminate request will be injected here
  $websocket->emit('message', 'welcome');
});
  1. What did you expect to see? Emit the 'message' event as it's shown above. I'm using socket.io v4.0 on client side and it connects properly to server, even I'm able to print a console message on connect event, but when I try to emit an event from server it fails and if I emit an event from the client side to the server, the server doesn't detect it.

  2. What did you see instead?

ErrorException: Required parameter $server follows optional parameter $message in /var/www/myapp/vendor/swooletw/laravel-swoole/src/Websocket/Pusher.php:64
Stack trace:
#0 /var/www/myapp/vendor/composer/ClassLoader.php(478): Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}()
#1 /var/www/myapp/vendor/composer/ClassLoader.php(478): include()
#2 /var/www/myapp/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile()
#3 /var/www/myapp/vendor/swooletw/laravel-swoole/src/Concerns/InteractsWithWebsocket.php(207): Composer\Autoload\ClassLoader->loadClass()
#4 /var/www/myapp/vendor/swooletw/laravel-swoole/src/Server/Manager.php(281): SwooleTW\Http\Server\Manager->pushMessage()
#5 [internal function]: SwooleTW\Http\Server\Manager->onTask()
#6 /var/www/myapp/vendor/swooletw/laravel-swoole/src/Server/Manager.php(99): Swoole\Server->start()
#7 /var/www/myapp/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(137): SwooleTW\Http\Server\Manager->run()
#8 /var/www/myapp/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(98): SwooleTW\Http\Commands\HttpServerCommand->start()
#9 /var/www/myapp/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(74): SwooleTW\Http\Commands\HttpServerCommand->runAction()
#10 /var/www/myapp/vendor/illuminate/container/BoundMethod.php(36): SwooleTW\Http\Commands\HttpServerCommand->handle()
#11 /var/www/myapp/vendor/illuminate/container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#12 /var/www/myapp/vendor/illuminate/container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#13 /var/www/myapp/vendor/illuminate/container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#14 /var/www/myapp/vendor/illuminate/container/Container.php(610): Illuminate\Container\BoundMethod::call()
#15 /var/www/myapp/vendor/illuminate/console/Command.php(136): Illuminate\Container\Container->call()
#16 /var/www/myapp/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute()
#17 /var/www/myapp/vendor/illuminate/console/Command.php(121): Symfony\Component\Console\Command\Command->run()
#18 /var/www/myapp/vendor/symfony/console/Application.php(971): Illuminate\Console\Command->run()
#19 /var/www/myapp/vendor/symfony/console/Application.php(290): Symfony\Component\Console\Application->doRunCommand()
#20 /var/www/myapp/vendor/symfony/console/Application.php(166): Symfony\Component\Console\Application->doRun()
#21 /var/www/myapp/vendor/illuminate/console/Application.php(92): Symfony\Component\Console\Application->run()
#22 /var/www/myapp/vendor/laravel/lumen-framework/src/Console/Kernel.php(116): Illuminate\Console\Application->run()
#23 /var/www/myapp/artisan(35): Laravel\Lumen\Console\Kernel->handle()
#24 {main
RicardoGuiliani commented 3 years ago

Solved here #476