Download the PHP package joni-jones/yii2-wschat without Composer
On this page you can find all versions of the php package joni-jones/yii2-wschat. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-wschat
Web Socket Chat
Online chat based on web sockets and ratchet php
![Demo] (doc/demo.gif)
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Usage
-
The chat extension can use any database storage supported by yii.
If
mongodb
extension specified the chat will be try to use it as message history storage, otherwise extension will be use specified in application config db component.The simple example how to use mongodb storage is listed below. Install MongoDB and yii2-mongodb extension to store messages history and you need just specify connection in
console
config:In created mongodb database you need to create collection named as
history
;IMPORTANT: if you use db component - you need to create table
history
in your database. The simple examples postgresql and mysql you can see intests/codeception
directory. -
To start chat server need to create console command and setup it as demon:
-
Create controller which extends
yii\console\Controller
: - Create action to start server:
If you want to use chat for auth users, you must to specify
userClassName
property forChatManager
instance. For example:- Now, you can run chat server with
yii
console command:
-
-
To add chat on page just call:
or if you want to use chat for auth users just add config as parameter:
List of available options: auth - boolean, default: false user_id - mixed, default: null port - integer, default: 8080 chatList - array (allow to set list of preloaded chats), default: [ id => 1, title => 'All' ], add_room - boolean, default: true (allow to user create new chat rooms)
You can also store added chat, just specify js callback for vent events:
Chat.vent('chat:add', function(chatModel) {
console.log(chatModel);
});
This code snipped may be added in your code, but after chat widget loading. In the callback you will get access to Chat.Models.ChatRoom
backbone model. Now, you need add your code to save chat room instead console.log()
.
If
YII_DEBUG
is enabled - all js scripts will be loaded separately.
Also by default chat will try to load two images:
/avatar_16.png
and /avatar_32.png
from assets folder.
Possible issues
If you don't see any messages in console log, check flushInterval
and exportInterval
of your log configuration component. The simple configuration may looks like this:
If you use https
protocol chat will try to connect to wss
instead ws
. But Ratchet PHP does not support work via SSL, so
you need to use some proxy like stunnel.
License
MIT
All versions of yii2-wschat with dependencies
yiisoft/yii2-mongodb Version 2.1.*
yiisoft/yii2-bootstrap Version *
cboden/ratchet Version 0.3.*
bower-asset/jquery Version 2.*
bower-asset/underscore Version 1.8.3
bower-asset/backbone Version 1.2.*
bower-asset/js-cookie Version 2.1.*
bower-asset/pnotify Version 2.0.*
bower-asset/fontawesome Version 4.*