Yet another chat
npm install
npm run init
gulp
node .
- Стартоните приложение:
node . - В другом окне консоли запустите тесты:
mocha
- app — основное приложение
- assets
- css — файлы sass для модулей
- js — основной файл фронта, куда объявляются все инклуды
- components — внешние компоненты (включено в gitignore)
- configs — файлы конфига для express
- controllers — основные js-файлы express
- models — модели express
- modules — модули express
- views
- layouts — тут html-шаблон страницы, который потом копируется в public/
- components — react-компоненты
- assets
- public — все статичные файлы, здесь лежит базовый index.html, который собирается из вьюх
- assets
- css
- js
- assets
ssh-keygen -t rsa
- Можно изменить имя файла, но лучше этого не делать. Default:
id_rsa - passphrase не пишите, оставьте пустым
cat ~/.ssh/id_rsa.pub | ssh [email protected] 'cat >> ~/.ssh/authorized_keys'
Если все сделано правильно, то выполните:
ssh [email protected] "ssh -T [email protected]"Вы должны увидеть такое сообщение:
Hi
sigorilla! You've successfully authenticated, but GitHub does not provide shell access.
Для удаленного обновления используем NPM пакет pm2
npm install -g pm2@latestpm2 deploy <environment_key>, гдеenvironment_key- либоdev(тестирование, разработка), либоproduction(masterветка)
- Production будет доступна по адресу: shriek-chat.tk
- Development - по адресу: shriek-chat.tk:81
Все события отправляются с помощью socket.io. Если мы хотим получить данные то пишем:
socket.on('<name-of-event>', function (data) {
// work with 'data'
});Для отправки данных:
socket.emit('<name-of-event>', data);{
"status": "ok",
"<some-data>" : {}
}{
"status": "error",
"error_message": "<Error message>"
}Вход/регистрация пользователя
Input (emit)
| Field | Type | Description |
|---|---|---|
| username | String | Username |
| password | String | Password |
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| user | Object | user object from DB (see schema) |
error_message:
Пользователь уже вошелНеверный парольUser validation failedПользователь не найден
Пользователь подсоединился
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| user | Object | user object from DB (see schema) |
Пользователь вышел
Input (emit)
| Field | Type | Description |
|---|
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| user.username | String | Username |
error_message:
Пользователь еще не вошел
Отсоединение пользователя
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| user.username | String | Username |
Получить информацию о пользователе
Input (emit)
| Field | Type | Description |
|---|---|---|
| username | String | Username |
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| user | Object | user object from DB (see schema) |
error_message:
Пользователь должен войтиПользователь не найден
Получить информацию о пользователе
Input (emit)
| Field | Type | Description |
|---|---|---|
| username | String | Username |
| setting | Object | Field: email, image |
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| user | Object | user object from DB (see schema) |
error_message:
Пользователь должен войтиПользователь не найден
Получить список пользователей
Input (emit)
| Field | Type | Description |
|---|
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| users | Array | array of user objects from DB (see schema) |
error_message:
Пользователь должен войтиПользователей не найдено
Пользователь начал печатать
Input (emit)
| Field | Type | Description |
|---|
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| user.username | String | Username |
error_message:
Пользователь должен войтиПользователь уже печатает
Пользователь закончил печатать
Input (emit)
| Field | Type | Description |
|---|
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| user.username | String | Username |
error_message:
Пользователь должен начать печатать
Создание канала
Input (emit)
| Field | Type | Description |
|---|---|---|
| name | String | Название чата |
| description | String | Описание чата |
| privateUsers | Boolean | Приватный ли |
| userslist | String | Пользователи канала |
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| channel | Object | channel object from DB (see schema) |
error_message:
Ошибка создания чата
Получение информации о канале
Input (emit)
| Field | Type | Description |
|---|---|---|
| slug | String | Слаг чата |
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| channel | Object | channel object from DB (see schema) |
error_message:
Ошибка получения чата
Получение списка каналов с учетом привытных каналов для данного пользователя
Input (emit)
| Field | Type | Description |
|---|
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| channels | Array | array of channel objects from DB (see schema) |
error_message:
Ошибка получения чата
Получить сообщения из канала
Input (emit)
| Field | Type | Description |
|---|---|---|
| channel | String | Слаг канала |
| limit | Integer | Кол-во сообщений |
| skip | Integer | Начиная с какого |
| date | ISODate | С какой даты |
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| messages | Array | Array of message objects from DB (see schema) |
error_message:
Ошибка получения сообщений
Отправить сообщение
Input (emit)
| Field | Type | Description |
|---|---|---|
| username | String | Username |
| text | String | Message |
| channel | String | (optional) Slug of channel, default: general |
| type | String | (optional) Type of message, default: text |
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| message | Object | message object from DB (see schema) |
error_message:
Ошибка создания сообщения
Отправить сообщение
Input (emit)
| Field | Type | Description |
|---|---|---|
| channels | Array | Slugs of channel where find |
| text | String | Query string |
Output (on)
| Field | Type | Description |
|---|---|---|
| status | String | Status of error |
| messages | Array | Array of message object from DB (see schema) |
error_message:
Ошибка поиска
| Field | Type | Other |
|---|---|---|
| username | String | required, unique |
| hashedPassword | String | required |
| salt | String | required |
| created_at | ISODate | default: now |
| updated_at | ISODate | default: now |
| setting | Object | see below |
settings
| Field | Type | Other |
|---|---|---|
| String | ||
| image | String | Url of image |
| first_name | String | First name |
| last_name | String | Last name |
| full_name | String | virtual, full name |
| sex | String | ['male', 'female'] Gender of user |
| description | String | About himself |
username from 5 to 29 letters. Only latin letters, figures and underscore (_).
password from 6 letters.
| Field | Type | Other |
|---|---|---|
| name | String | required |
| description | String | |
| slug | String | required, unique |
| is_private | Boolean | required, default: false |
| created_at | ISODate | default: now |
| updated_at | ISODate | default: now |
| users | Array | Array of usernames in current channel |
| Field | Type | Other |
|---|---|---|
| username | String | required |
| channel | String | required |
| text | String | required |
| raw | String | HTML after modules |
| type | String | required |
| created_at | ISODate | default: now |
| attachments | Object | - |
Configuration file config.json example
{
"port": 3000,
"mongoose": {
"uri": "mongodb://localhost/shriek"
}
}
mongo shriek --eval "db.dropDatabase();"
You can create NPM package (ex. shriek-markdown).
- You should name package with prefix
shriek-. - Add you package via
requirein fileapp/modules/plugins.js. - Add in code
module.exports.forEvent.
- Different events have different data for your package.
As plugins for backend you can create React component as Bower package (ex. shriek-emoji).
- You should name package with prefix
shriek-. - You should exec registration function with your root component. For example, registration for message component names
registerMessagePlugin. - ...
- Profit! Now your plugin is in our chat.