My Account | Buy CometChat

documentation

Creating a New Plugin

Overview

Plugins can be used to enhance one-on-one and chatrooms functionality.

Plugin development requires working knowledge of PHP and JavaScript. Take a few minutes going through the PHP and JS API.

Workflow

  1. When the user clicks on a plugin, the init() function is called and the user’s ID is sent as a parameter. In case of chatrooms, the chatroom ID is sent as a parameter
  2. Using the ID and AJAX, PHP files can be called and functionality can be added accordingly.
  3. To get the logged in user’s ID, PHP must be used.

Creating your first plugin

Hello world

  1. Create a new folder in plugins directory e.g. sample
  2. Create a 16×16 icon and upload it as plugins/sample/icon.png
  3. Add code.php file with the following contents

  4. Create a init.js file with the following contents

    (function($){ $.ccsample = (function () { var title = ‘Activate Sample Plugin’; return { getTitle: function() { return title;
    }, init: function (id) { baseUrl = $.cometchat.getBaseUrl(); alert(‘Hello world’); }, }; })(); })(jqcc);