takielias / codeigniter4-websocket

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

Not working with CodeIgniter 4.5.2 #15

Open Sosko opened 1 month ago

Sosko commented 1 month ago

I was using older CodeIgniter version 4.4.* with this library, but after I updated to the version 4.5.2 (and fix breaking changes) the library would't load and I getting this error:

CRITICAL - 2024-06-28 07:37:11 --> Error: Call to a member function set_callback() on null
[Method: CLI, Route: webserver]
in APPPATH/Controllers/Websocket.php on line 41.
 1 SYSTEMPATH/CodeIgniter.php(933): App\Controllers\Websocket->start()
 2 SYSTEMPATH/CodeIgniter.php(509): CodeIgniter\CodeIgniter->runController()
 3 SYSTEMPATH/CodeIgniter.php(355): CodeIgniter\CodeIgniter->handleRequest()
 4 SYSTEMPATH/Boot.php(325): CodeIgniter\CodeIgniter->run()
 5 SYSTEMPATH/Boot.php(67): CodeIgniter\Boot::runCodeIgniter()
 6 FCPATH/index.php(56): CodeIgniter\Boot::bootWeb(

The code in start is of class is:

namespace App\Controllers;

use CodeIgniter\Controller;
use App\Libraries\CodeigniterWebsocket;

class Websocket extends Controller {

    /**
     * @var Config
     */
    protected $config;

    /**
     * @var CodeigniterWebsocket 
     */
    protected  $service = null;

    public function __construct() {
        $this->config = config('CodeigniterWebsocket');
    }

    public function start() {
        $this->service = service('CodeigniterWebsocket');
        $this->service->set_callback('auth', array($this, '_auth')); // line 41
        $this->service->set_callback('citimer', array($this, 'citimer'));
        $this->service->set_callback('event', array($this, '_event'));
        $this->service->set_callback('watched', array($this, 'watched'));
        while (true) {
            try {
                $this->service->run();
            } catch (Exception $exc) {
                $this->logger->error($exc->getTraceAsString());
            }
        }
    }
.....
takielias commented 4 days ago

@Sosko Feel free to make a PR for this.