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
- 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
- Using the ID and AJAX, PHP files can be called and functionality can be added accordingly.
- To get the logged in user’s ID, PHP must be used.
Creating your first plugin
Hello world
- Create a new folder in plugins directory e.g. sample
- Create a 16×16 icon and upload it as plugins/sample/icon.png
Add code.php file with the following contents
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);