takielias / codeigniter4-websocket

Codeigniter 4 Websocket Built for real-time application
https://ebuz.xyz
MIT License
81 stars 26 forks source link

ssociate it to a controller #4

Open KokeroO opened 2 years ago

KokeroO commented 2 years ago

How can I associate it to a controller that, when interacting with the controller, sends messages to all clients?

KokeroO commented 2 years ago
namespace App\Controllers\Admin;

use CodeIgniter\API\ResponseTrait;
use WebSocket\Client;
use Takielias\CodeigniterWebsocket\Libraries\Server;
class AnprIntelbras extends \CodeIgniter\Controller
{
    use ResponseTrait;
    public $db;

    protected $configWeb;

    protected $ConnectionInterface;

    public $config = array();

    public function __construct(){
        $this->db = \Config\Database::connect();
        $this->VeiculosModel = new \App\models\VeiculosModel();
        $this->ConfigAnprModel = new \App\models\ConfigAnprModel();
        $this->configWeb = config('CodeigniterWebsocket');
    }

    public function test() {
        $this->client = new Client('ws://localhost:8282');
        $this->server = new Server($this->configWeb, null);
        $this->server->onMessage($this->client, 'Test');
    }

I would like that whenever I interact with this controller method it will be able to send a message. As I discover the best way to do this, I believe I will be able to adapt to my project.

hiagodeoliveiratv commented 9 months ago

Hello friend, have you made it yet?

KokeroO commented 9 months ago

Não me recordo se foi diretamente pelo codeigniter, vejo mais tarde e te retorno. Qualquer coisa me lembre via ZAP. 44 999701349

Obter o Outlook para Androidhttps://aka.ms/AAb9ysg


From: Hiago de Oliveira @.> Sent: Monday, November 20, 2023 11:58:27 AM To: takielias/codeigniter4-websocket @.> Cc: KokeroO @.>; Author @.> Subject: Re: [takielias/codeigniter4-websocket] ssociate it to a controller (#4)

Hello friend, have you made it yet?

— Reply to this email directly, view it on GitHubhttps://github.com/takielias/codeigniter4-websocket/issues/4#issuecomment-1819225443, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AG7H7Q2J5TGBYR56Q76GFKDYFNVZHAVCNFSM5DNI33AKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRHEZDENJUGQZQ. You are receiving this because you authored the thread.Message ID: @.***>

takielias commented 9 months ago

@KokeroO Did you check the Example Project?