Stream Chat 的官方 JavaScript API 用戶端,這是一種用於建立聊天應用程式的服務。
探索文件 »
報告錯誤·請求功能
您可以在我們的「開始」頁面註冊 Stream 帳戶。
該庫可供前端和後端應用程式使用。對於前端,我們有基於該程式庫的框架,例如 Flutter、React 和 Angular SDK。有關更多信息,請查看我們的文件。
npm install stream-chat
yarn add stream-chat
< script src =" https://cdn.jsdelivr.net/npm/stream-chat " > </ script >
StreamChat 用戶端設定為允許在實例化時透過使用泛型來擴展基本類型。預設實例化將所有泛型設定為Record<string, unknown>
。
import { StreamChat } from 'stream-chat' ;
// Or if you are on commonjs
const StreamChat = require ( 'stream-chat' ) . StreamChat ;
const client = StreamChat . getInstance ( 'YOUR_API_KEY' , 'API_KEY_SECRET' ) ;
const channel = client . channel ( 'messaging' , 'TestChannel' ) ;
await channel . create ( ) ;
或者您可以自訂泛型:
type ChatChannel = { image : string ; category ?: string } ;
type ChatUser1 = { nickname : string ; age : number ; admin ?: boolean } ;
type ChatUser2 = { nickname : string ; avatar ?: string } ;
type UserMessage = { country ?: string } ;
type AdminMessage = { priorityLevel : number } ;
type ChatAttachment = { originalURL ?: string } ;
type CustomReaction = { size ?: number } ;
type ChatEvent = { quitChannel ?: boolean } ;
type CustomCommands = 'giphy' ;
type StreamType = {
attachmentType : ChatAttachment ;
channelType : ChatChannel ;
commandType : CustomCommands ;
eventType : ChatEvent ;
messageType : UserMessage | AdminMessage ;
reactionType : CustomReaction ;
userType : ChatUser1 | ChatUser2 ;
} ;
const client = StreamChat . getInstance < StreamType > ( 'YOUR_API_KEY' , 'API_KEY_SECRET' ) ;
// Create channel
const channel = client . channel ( 'messaging' , 'TestChannel' ) ;
await channel . create ( ) ;
// Create user
await client . upsertUser ( {
id : 'vishal-1' ,
name : 'Vishal' ,
} ) ;
// Send message
const { message } = await channel . sendMessage ( { text : `Test message` } ) ;
// Send reaction
await channel . sendReaction ( message . id , { type : 'love' , user : { id : 'vishal-1' } } ) ;
初始化客戶端時提供的自訂類型將延續到所有客戶端返回,並為查詢提供智慧感知。
在此儲存庫的根目錄中執行
yarn link
在stream-chat-react-native
儲存庫中的範例應用程式之一(SampleApp/TypeScriptMessaging)的根目錄中執行
yarn link stream-chat
yarn start
開啟metro.config.js
檔案並將 watchFolders 的值設為
const streamChatRoot = '{{CHANGE_TO_THE_PATH_TO_YOUR_PROJECT}}/stream-chat-js'
module . exports = {
// the rest of the metro config goes here
...
watchFolders : [ projectRoot ] . concat ( alternateRoots ) . concat ( [ streamChatRoot ] ) ,
resolver : {
// the other resolver configurations go here
...
extraNodeModules : {
// the other extra node modules go here
...
'stream-chat' : streamChatRoot
}
}
} ;
確保根據您的目錄結構將{{CHANGE_TO_THE_PATH_TO_YOUR_PROJECT}}
替換為stream-chat-js
資料夾的正確路徑。
在此儲存庫的根目錄中執行
yarn start
請造訪 docs/typescript.md 以了解更多範例。
我們歡迎改進此程式庫或解決問題的程式碼更改,請確保遵循所有最佳實踐並添加測試(如果適用),然後再在 Github 上提交 Pull 請求。我們很高興將您的程式碼合併到官方儲存庫中。請務必先簽署我們的貢獻者許可協議 (CLA)。有關更多詳細信息,請參閱我們的許可證文件。
前往 CONTRIBUTING.md 了解一些開發技巧。
我們最近完成了 3800 萬美元的 B 輪融資,並且我們一直在積極發展。我們的 API 被超過 10 億最終用戶使用,您將有機會在全球最強大的工程師團隊中對產品產生巨大影響。
查看我們目前的空缺職位並透過 Stream 網站進行申請。