チャット アプリケーションを構築するためのサービスである 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) の 1 つのルートで実行します。
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 でプル リクエストを送信する前に、すべてのベスト プラクティスに従い、該当する場合はテストを追加してください。あなたのコードを公式リポジトリにマージできることを非常に嬉しく思います。最初に必ずコントリビューターライセンス契約 (CLA) に署名してください。詳細については、ライセンス ファイルを参照してください。
開発のヒントについては、CONTRIBUTING.md にアクセスしてください。
最近、3,800 万ドルのシリーズ B 資金調達ラウンドを完了し、積極的に成長を続けています。当社の API は 10 億人を超えるエンドユーザーによって使用されており、世界中の最も強力なエンジニアのチーム内で製品に大きな影響を与えるチャンスがあります。
現在の募集を確認し、Stream の Web サイトから応募してください。