1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to load libraries?

Discussion in 'Development' started by FUGAMARU, Mar 4, 2017.

  1. FUGAMARU

    FUGAMARU Spider

    Messages:
    14
    Now, I'm developing a web service to synchronize chats with the web and PocketMine-MP.
    The web server uses Node.js. And using Socket.IO for chat synchronization.
    I found this library when I was looking for a library that can use Socket.IO in PHP.
    So I used the composer to install the library.
    In order to load the library from the PocketMine-MP plugin after installing the library, I wrote the following code.

    PHP:
    <?php
    namespace EasyCHAT;

    require_once 
    __DIR__ '/vendor/autoload.php';
    use 
    PHPSocketIO\SocketIO;
    use 
    Workerman\Worker;

    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\utils\Config;

    class 
    EasyCHAT extends PluginBase implements Listener{
    public 
    $client;

    public function 
    onEnable(){
    global 
    $client;
        require_once 
    __DIR__ '/vendor/autoload.php';
        if(!
    file_exists($this->getDataFolder())){
        
    mkdir($this->getDataFolder(), 0744true);
        
    $this->config = new Config($this->getDataFolder()."Data.json"Config::JSON);
        
    $this->config->set("ID""");
        
    $this->config->save();
        }
        
    $this->config = new Config($this->getDataFolder()."Data.json"Config::JSON);
        
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        
    $io = new SocketIO('http://192.168.1.10:3000');
        
    $io->emit('roomin''123456');
    }

    public function 
    onChat(PlayerChatEvent $event){
        global 
    $io;
        
    $Message $event->getMessage();
        
    $PlayerName $event->getPlayer()->getName();
        
    $array['id'] = $this->config->get('ID');
        
    $array['message'] = 'TESTMESSAGE';
        
    $io->emit('send'json_encode($array));
        
    Worker::runAll();
    }
    }
    I tried starting up the server. But,
    This error was output to the console.
    The location of files is as follows.

    Easy-CHAT.php
    src|
    -These files
    vendor|
    Files placed by composer

    How to disappear errors and WebSocket communication will be possible?
    Give me advices.
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    I doubt the autoloader is even working or composer even works with PMMP based plugin
    I havent bothered to read the code of the libary but i am doubting it would work nicely with PMMP you may need to tweak it a bit
    it kinda uses a "react" style or whatever it's called which i suspect blocks the main thread
    but you should take my word as a grain of salt
     
  3. FUGAMARU

    FUGAMARU Spider

    Messages:
    14
    I used Miner to install.
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    i honesty dont know
    when i need a library i just forcefully hack it inside manually installing it so maybe that can be your last resort as miner is quite outdated if my guess is right
     
  5. FUGAMARU

    FUGAMARU Spider

    Messages:
    14
    Then, what should I do?
     
  6. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    i bet someone will have a better idea then me, but my first attempt would be try to squish them into your source folder and see if it works
     
  7. FUGAMARU

    FUGAMARU Spider

    Messages:
    14
    Are there other Socket.IO libraries that can be used with PMMP?
    However, there are cases where Node.js sends messages to PMMP.
     
  8. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    You have to register the namespace with PocketMine's auto Loader for it work.
     
  9. FUGAMARU

    FUGAMARU Spider

    Messages:
    14
    What file namespace?
    I found such a sentence in Miner's thread.
    Could you tell me how to register with PocketMine's Autoloader?
    Sorry to bother you again...
     
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    What have you tried?

    You just need to register a custom PSR-4 autoloader... PHP spl_autoload_register never required that there must only be one autoloader.
     
  11. FUGAMARU

    FUGAMARU Spider

    Messages:
    14
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.