uWebSockets.js提供動力
我們的消息傳遞協議和聊天服務器的意圖與其他不同的目的是為廣泛的傳播XMPP消息傳遞協議提供替代解決方案(老實說,這是當今唯一廣泛的“標準”)。
閱讀介紹薩瑪的完整中等文章,以及關於什麼是sama以及我們試圖解決什麼問題的sama是什麼:
Frontend App(Web + Mobile)可從https://github.com/sama-communications/sama-client獲得
Node 18 。.env.example為.env 。docker-compose -f docker-compose.yml -f docker-compose.development.yml up運行依賴服務(mongodb,minio,redis)npm install以安裝依賴關係npm run migrate-mongo-up運行DB遷移npm run start運行服務器(如果在Windows下運行的情況 - 請參見#128)ws://localhost:9001Sama Stack中還有其他組件 - 查看部署SAMA CHAT SERVER堆棧:綜合指南
無論您想要具有所有依賴項的完整設置還是帶有主要應用程序的本地環境,可以輕鬆地使用SAMA應用程序來完成SAMA應用程序。以下是要遵循的步驟:
這種方法在單個命令中構建並運行整個SAMA應用程序,包括所有依賴性。它是快速設置完整環境的理想選擇。
要使用此方法部署,請運行:
docker-compose -f docker-compose-full.yml up --build
與主要的SAMA應用程序( sama-client , sama-server和sama-push-daemon )一起運行依賴關係服務,請使用:
docker-compose up --build
SAMA應用程序,請在啟動命令之前添加這兩個變量:
macos
MINIO_ENDPOINT=$(ipconfig getifaddr en0) MINIO_PORT=9010
視窗
$env:MINIO_ENDPOINT = (Get-NetIPAddress | Where-Object { $_.AddressFamily -eq 'IPv4' -and $_.IPAddress -match '^192.168.|^10.|^172.(1[6-9]|2[0-9]|3[0-1]).' } | Select-Object -ExpandProperty IPAddress)[1]; $env:MINIO_PORT = 9010;
如果您遇到Web客戶端中附件的問題,則表明第一個變量中發生了錯誤。為了解決此問題,您可以簡單地使用計算機的專用IP地址更新代碼段。
現在,您可以通過以下地址訪問應用程序:
運行遷移:
docker-compose exec sama-server sh -c "MONGODB_URL=mongodb://172.25.0.4/samatests npm run migrate-mongo-up"
運行E2E測試:
docker-compose exec sama-server sh -c "MONGODB_URL=mongodb://172.25.0.4/samatests npm run test"
可以使用https://app.samacloud.io public Cloud對整個SAMA堆棧進行測試。
API參考
此外,每個API都有一組詳細文章:
一個示例如何創建和使用提供商:
使用2個文件index.js and Provider.js創建文件夾app/providers/services/my_provider
index.js應包含服務本身的實施:
export default class MyProvider {
constructor ( redisConnection , userRepo ) {
this . redisConnection = redisConnection
this . userRepo = userRepo
}
async updateAction ( ws , fields ) {
const id = await this . redisConnection . client . . .
const updatedUser = await this . userRepo . update . ...
... .
return updatedUser
}
}Provider.js應導出一個registerProvider的實例,其中包含指令如何創建具有依賴項的index.js類實例: import RegisterProvider from "@sama/common/RegisterProvider.js"
import MyProvider from "./index.js"
const name = "MyProvider"
class MyProviderRegistration extends RegisterProvider {
register ( slc ) {
const redisConnection = slc . use ( "RedisClient" )
const userRepo = slc . use ( "UserRepository" )
return new MyProvider ( redisConnection , userRepo )
}
}
export default new MyProviderRegistration ( { name , implementationName : MyProvider . name } )Provider.js的導出添加到app/providers/index.js import UserRepoProvider from "./repositories/user/Provider.js"
...
...
import MyProviderRegistration from "./services/my_provider/Provider.js"
const providers = [
UserRepoProvider ,
...
...
MyProviderRegistration
]
export default providers對於任何自定義API提供商 - 使用/APIs/[API_NAME]/providers/index.js文件:
現在,yiou可以在需要的地方使用MyProvider類,例如在控制器中:
import ServiceLocatorContainer from "@sama/common/ServiceLocatorContainer.js"
class Controller {
async edit ( ws , data ) {
const myProvider = ServiceLocatorContainer . use ( "MyProvider" )
const updatedUser = await myProvider . updateAction ( ws , data )
. ...
}
} 加入我們的社區進行支持和討論:
路線圖
GPL-3.0
任何想法,歡迎反饋!請為您的任何反饋創建一個GitHub問題。
想支持我們嗎?