Open kelvin-yuang opened 3 years ago
could i have some method like swoole websocktet can be use Curl post data to "onRequest" ?
Hi!
I think you need to use other events, like: onStart, onOpen, etc.
Please, take a look at: https://github.com/swooletw/laravel-swoole/wiki/7.-Websocket and https://www.swoole.co.uk/docs/modules/swoole-websocket-server
The first is Thank for you answer my question. but, you maybe misunderstood,I meat used Router->controller->function->sendMSG to All fd. Execution by controller to send MSG 。 like that: https://wiki.swoole.com/#/websocket_server?id=onrequest PHP can use curl function to touch websocket do something.
if use events,the first is get MSG to do ->controller->function,that is contrary. router/websocket.php->bind Controller->function。
The document is very clear. see here
eg:
// routes/web.php
use SwooleTW\Http\Websocket\Facades\Websocket;
Route::get('test', function(){
$userId = Websocket::getUserId();
Websocket::toUserId($userId)->emit('message', 'hi there');
});
I try it, Laravel8 show me some error: Illuminate\Contracts\Container\BindingResolutionException "Target class [swoole.websocket] does not exist.",
config/app.php have add "SwooleTW\Http\LaravelServiceProvider::class," routes/web.app have add "use SwooleTW\Http\Websocket\Facades\Websocket;"
i found querstion from: https://github.com/swooletw/laravel-swoole/issues/415 It's still unresolved
I also try make a controller files
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use SwooleTW\Http\Websocket\Facades\Websocket; use SwooleTW\Http\Websocket\Facades\Room;
class WebSocketController extends Controller
{
public function test(){
$userId = Websocket::getUserId();
Websocket::toUserId($userId)->emit('message', 'hi there');
}
}
still show error : Illuminate\Contracts\Container\BindingResolutionException Target class [swoole.websocket] does not exist.
webscket.php is run allright , client connect also ok, just routes can't run Illuminate\Contracts\Container\BindingResolutionException ? looke like Providers register have some wrong ?
i found some info use $userId = Websocket::getUserId();
TypeError Argument 1 passed to SwooleTW\Http\Websocket\Rooms\TableRoom::getRooms() must be of the type int, null given, called in /var/www/html/laravel8/vendor/swooletw/laravel-swoole/src/Websocket/Authenticatable.php on line 103
public function getUserId() { if (! is_null($this->userId)) { return $this->userId; } $rooms = $this->room->getRooms($this->getSender()); foreach ($rooms as $room) { if (count($explode = explode(static::USER_PREFIX, $room)) === 2) { $this->userId = $explode[1]; } } return $this->userId; }
I try it, Laravel8 show me some error: Illuminate\Contracts\Container\BindingResolutionException "Target class [swoole.websocket] does not exist.",
config/app.php have add "SwooleTW\Http\LaravelServiceProvider::class," routes/web.app have add "use SwooleTW\Http\Websocket\Facades\Websocket;"
i found querstion from: #415 It's still unresolved
I also try make a controller files
emit('message', 'hi there'); } } still show error : Illuminate\Contracts\Container\BindingResolutionException Target class [swoole.websocket] does not exist. webscket.php is run allright , client connect also ok, just routes can't run Illuminate\Contracts\Container\BindingResolutionException ? looke like Providers register have some wrong ?
Have you resolved this issue? I met the same.
Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks! (Any non-English issues will be closed immediately.)
Please provide your PHP and Swoole version. (
php -v
andphp --ri swoole
) PHP 7.3.25 Swoole => enabled Version => 4.4.23Please provide your Laravel/Lumen version. Laravel8.x
Which release version of this package are you using? I think is fix ok
What did you do? If possible, provide a recipe for reproducing the error. i don't konw how to use controller@method to make websocket send MSG