Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FM-27 added device_token for push subscription #136

Merged
merged 15 commits into from
Oct 23, 2024
Merged
2 changes: 1 addition & 1 deletion APIs/JSON/controllers/push_notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PushNotificationsController extends BaseJSONController {
async push_subscription_create(ws, data) {
const {
id: requestId,
push_subscription_create: { platform, web_endpoint, web_key_auth, web_key_p256dh, device_udid },
push_subscription_create: { web_endpoint, web_key_auth, web_key_p256dh, device_udid },
Oleksandr1414 marked this conversation as resolved.
Show resolved Hide resolved
} = data

const sessionService = ServiceLocatorContainer.use("SessionService")
Expand Down
39 changes: 17 additions & 22 deletions APIs/JSON/validations/push_notifications_schema_validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,30 @@ export const pushNotificationsSchemaValidation = {
cause: ERROR_STATUES.INCORRECT_PLATFROM_TYPE,
})
),
web_endpoint: Joi.string()
.required()
.error(
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
cause: ERROR_STATUES.INCORRECT_TOKEN,
})
),
web_key_auth: Joi.string()
.required()
.error(
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
cause: ERROR_STATUES.INCORRECT_KEYS,
})
),
web_key_p256dh: Joi.string()
.required()
.error(
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
cause: ERROR_STATUES.INCORRECT_KEYS,
})
),
web_endpoint: Joi.string().error(
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
cause: ERROR_STATUES.INCORRECT_TOKEN,
})
),
web_key_auth: Joi.string().error(
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
cause: ERROR_STATUES.INCORRECT_KEYS,
})
),
web_key_p256dh: Joi.string().error(
new Error(ERROR_STATUES.INCORRECT_TOKEN.message, {
cause: ERROR_STATUES.INCORRECT_KEYS,
})
),
device_udid: Joi.string()
.required()
.error(
new Error(ERROR_STATUES.INCORRECT_DEVICE_ID.message, {
cause: ERROR_STATUES.INCORRECT_DEVICE_ID,
})
),
}).required(),
device_token: Joi.string(),
}).or("web_endpoint", "device_token"),
push_subscription_list: Joi.object({
user_id: Joi.alternatives()
.try(Joi.object(), Joi.string(), Joi.number())
Expand Down
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,43 @@ Read complete medium posts **Introducing SAMA** and **What is SAMA** about what

Frontend app (web + mobile) is available at https://github.com/SAMA-Communications/sama-client

## Development
## Local development

- Make sure you have `Node 18.20.x` installed.
- Make sure you have latest `Node 18` installed.
- Copy `.env.example` to `.env`.
- Run `docker-compose up` to run dependant services (MongoDB, Minio, Redis)
- Run `docker-compose -f docker-compose.yml -f docker-compose.development.yml up` to run dependant services (MongoDB, Minio, Redis)
- `npm install` to install dependencies
- `npm run migrate-mongo-up` to run DB migrations
- `npm run start` to run server
- `npm run start` to run server (in a case of running under Windows - see https://github.com/SAMA-Communications/sama-server/issues/128)
- Now the server will be listening for incoming connections at `ws://localhost:9001`

There are also other components. Make sure to check [Deploying SAMA chat server stack: a comprehensive guide](https://medium.com/sama-communications/deploying-sama-chat-server-stack-a-comprehensive-guide-294ddb9a2d78)
There are also other components available in SAMA stack - check it out [Deploying SAMA chat server stack: a comprehensive guide](https://medium.com/sama-communications/deploying-sama-chat-server-stack-a-comprehensive-guide-294ddb9a2d78)


## Deployment

Deploying the SAMA application can be done easily with Docker, whether you want a complete setup with all dependencies or a local environment with the main applications. Below are the steps to follow:

### Docker one-command deployment

To build and run the `SAMA` with all dependencies, you can use the following command:
This approach builds and runs the entire SAMA application, including all dependencies, in a single command. It is ideal for setting up the full environment quickly.

To deploy using this method, run:

```
docker-compose -f docker-compose-full.yml up --build
```

If you only want to run dependency services (for local development without Docker), use this command:
### Docker local deployment

```
docker-compose up
```

Run dependency services with `SAMA` main apps:
To run the dependency services along with the main `SAMA` applications (`sama-client`, `sama-server`, and `sama-push-daemon`), use:

```
RUN_SAMA=true docker-compose up --build
docker-compose up --build
```

:warning: If you are using MacOS or Windows, and want run `SAMA` apps, add these two variables before the launch command:

MacOS

```
Expand Down Expand Up @@ -198,9 +203,12 @@ class Controller {
}
```

## Clustering
## Community and Support

[Clustering documentation](docs/CLUSTERING.md)
Join our community for support and discussions:
- [GitHub Issues - SAMA server](https://github.com/SAMA-Communications/sama-server/issues), [GitHub Issues - SAMA client](https://github.com/SAMA-Communications/sama-client/issues)
- [SAMA on Medium](https://medium.com/sama-communications)
- Get help - [Discord 💬](https://discord.gg/bHSm9a7DpC)

## Roadmap

Expand All @@ -214,4 +222,6 @@ class Controller {

Any thoughts, feedback is welcome! Please create a GitHub issue for any feedback you have.

Want to support us with [some coffee?](https://www.buymeacoffee.com/khomenkoigor). Will be much appreciated!
Want to support us?

<a href="https://www.buymeacoffee.com/khomenkoigor" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
1 change: 1 addition & 0 deletions app/models/push_subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class PushSubscription extends BaseModel {
"web_key_auth",
"web_key_p256dh",
"device_udid",
"device_token",
Oleksandr1414 marked this conversation as resolved.
Show resolved Hide resolved
]
}
}
23 changes: 23 additions & 0 deletions docker-compose.development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3.8"

services:
sama-client:
# Define the service here as an empty object to effectively exclude it
# Or simply leave it out if you want to remove it completely
# Example:
deploy:
replicas: 0

sama-server:
# Define the service here as an empty object to effectively exclude it
# Or simply leave it out if you want to remove it completely
# Example:
deploy:
replicas: 0

sama-push-daemon:
# Define the service here as an empty object to effectively exclude it
# Or simply leave it out if you want to remove it completely
# Example:
deploy:
replicas: 0
155 changes: 25 additions & 130 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,150 +10,45 @@ networks:

services:
sama-client:
build:
context: ./prefs/client
dockerfile: Dockerfile.frontend
environment:
- RUN_SAMA=${RUN_SAMA:-false}
entrypoint: >
sh -c "if [ \$$RUN_SAMA = 'true' ]; then
npm run start;
else
sleep infinity;
fi"
networks:
sama_network:
ipv4_address: 172.25.0.8
ports:
- "3000:3000"
volumes:
- ./prefs/client/.env.frontend:/app/.env
extends:
file: ./prefs/docker-compose/services/frontend.yml
service: sama-client

sama-server:
build:
context: .
dockerfile: Dockerfile
depends_on:
mongo:
condition: service_healthy
environment:
- RUN_SAMA=${RUN_SAMA:-false}
- MINIO_ENDPOINT=${MINIO_ENDPOINT:-172.25.0.2}
- MINIO_PORT=${MINIO_PORT:-9000}
entrypoint: >
sh -c "if [ \$$RUN_SAMA = 'true' ]; then
npm run migrate-mongo-up;
npm run start;
else
sleep infinity;
fi"
networks:
sama_network:
ipv4_address: 172.25.0.7
volumes:
- ./.env.local:/app/.env
ports:
- "9000:9001"
extends:
file: ./prefs/docker-compose/services/backend.yml
service: sama-server

sama-push-daemon:
build:
context: ./prefs/push
dockerfile: Dockerfile.push
environment:
- RUN_SAMA=${RUN_SAMA:-false}
entrypoint: >
sh -c "if [ \$$RUN_SAMA = 'true' ]; then
npm run start;
else
sleep infinity;
fi"
networks:
sama_network:
ipv4_address: 172.25.0.10
volumes:
- ./prefs/push/.env.push:/app/.env
extends:
file: ./prefs/docker-compose/services/push-daemon.yml
service: sama-push-daemon

s3:
image: minio/minio
networks:
sama_network:
ipv4_address: 172.25.0.2
ports:
- "9011:9001"
- "9010:9000"
volumes:
- data:/data
env_file:
- ./.env.local
command: server --address 0.0.0.0:9000 --console-address :9001 /data
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 30s
timeout: 20s
retries: 3
extends:
file: ./prefs/docker-compose/services/s3.yml
service: s3

s3-service:
image: minio/mc
networks:
sama_network:
ipv4_address: 172.25.0.3
depends_on:
s3:
condition: service_healthy
env_file:
- ./.env.local
entrypoint: >
/bin/sh -c "
/usr/bin/mc alias set sama http://s3:9000 $${MINIO_ROOT_USER} $${MINIO_ROOT_PASSWORD};
/usr/bin/mc mb sama/samabucket;
/usr/bin/mc policy set public sama/samabucket;
/usr/bin/mc admin user svcacct add --access-key $${MINIO_ACCESS_KEY} --secret-key $${MINIO_SECRET_KEY} sama $${MINIO_ROOT_USER}
"
extends:
file: ./prefs/docker-compose/services/s3.yml
service: s3-service

mongo:
platform: linux/x86_64
image: mongo:4.4
networks:
sama_network:
ipv4_address: 172.25.0.4
container_name: server_mongo_database
restart: always
volumes:
- mongo:/data/db
environment:
- MONGO_INITDB_DATABASE=samadb
ports:
- "27017:27017"
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/samadb --quiet
interval: 30s
timeout: 20s
retries: 3
extends:
file: ./prefs/docker-compose/services/db.yml
service: mongo

redis:
image: redis
networks:
sama_network:
ipv4_address: 172.25.0.5
container_name: server_redis_database
restart: always
ports:
- "6379:6379"
extends:
file: ./prefs/docker-compose/services/db.yml
service: redis

redis-commander:
container_name: redis-commander
hostname: redis-commander
image: rediscommander/redis-commander:latest
networks:
sama_network:
ipv4_address: 172.25.0.6
restart: always
environment:
- REDIS_HOSTS=local:redis:6379
ports:
- "8081:8081"
extends:
file: ./prefs/docker-compose/services/db.yml
service: redis-commander

volumes:
data:
mongo:
mongo-tests:
mongo:
3 changes: 2 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
request: {
user_login: {
login: "user_1",
password: "user_paswword_1"
password: "user_paswword_1",
device_id: "xxx-yyy-zzz"
},
id: "421cda83-7f39-45a9-81e8-5f83cfa0733c"
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"url": "git@KhomenkoIgor:IgorKhomenko/SAMA.git"
},
"author": "Igor Khomenko",
"license": "AGPL-3.0-or-later",
"license": "GPL-3.0",
"dependencies": {
"@aws-sdk/client-s3": "^3.327.0",
"@aws-sdk/s3-request-presigner": "^3.328.0",
Expand Down
4 changes: 2 additions & 2 deletions prefs/client/Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM alpine/git as clone

WORKDIR /app

RUN git clone https://github.com/SAMA-Communications/sama-client.git .
RUN git config --global http.version HTTP/1.1
RUN git clone https://github.com/SAMA-Communications/sama-client.git . --depth 1

FROM node:18.16.0 as builder

Expand Down
Loading