SDKの概要
@urth/metatell-sdkは、metatell内で動作するブラウザープラグイン向けのSDKです。
ユーザー、チャット、入力、音声、アバター、メディアデバイスなどのホスト機能を型付きAPIで利用できます。
📚 APIドキュメント: https://sdk.metatell.io/web/
インストール
npm install @urth/metatell-sdk
SDKはES Modulesとして読み込みます。
import { user, getWaypoints } from "@urth/metatell-sdk";
import { onMessage, send } from "@urth/metatell-sdk/chat";
ルートエントリとサブパスでは、利用できるAPIが異なります。
| インポート元 | 主な用途 |
|---|---|
@urth/metatell-sdk | user、Avatar、Camera、Mic、Screen、metrics、Way Point |
@urth/metatell-sdk/user | 自分のID、プロフィール、アバター、移動制御 |
@urth/metatell-sdk/users | 他ユーザーの一覧と在室イベント |
@urth/metatell-sdk/chat | チャット送受信、返信、メンション解析 |
@urth/metatell-sdk/input | ポインター、ホバー、視線、Raycast |
@urth/metatell-sdk/voice | 自分のマイクレベルと発話状態 |
@urth/metatell-sdk/emote | エモートの実行と購読 |
@urth/metatell-sdk/events | 低レベルの型付きイベントバス |
@urth/metatell-sdk/auth | 外部API向けの認証トークン取得 |
実行環境
SDKはmetatellのプラグイン実行環境から提供されるホスト機能を利用します。 通常のWebページやNode.jsだけで実行した場合、一部のAPIはホスト未接続として動作しません。
購読を必ず解除する
onから始まる購読APIは、解除用の関数を返します。
プラグインの終了処理で呼び出してください。
import { onMessage } from "@urth/metatell-sdk/chat";
import { onJoin } from "@urth/metatell-sdk/users";
const unsubscribers = [
onMessage((message) => console.log(message.text)),
onJoin((remoteUser) => console.log(remoteUser.profile.displayName)),
];
export function teardown() {
for (const unsubscribe of unsubscribers) {
unsubscribe();
}
}
send()やraycast()などの要求APIはPromiseを返します。
タイムアウトやホスト未接続で失敗する場合があるため、tryとcatchで処理してください。
本ガイドは安定APIを対象とし、実験的APIは掲載していません。
パッケージにはobjectsやtriggersなどの実験的なサブパスもあります。
利用する場合は、対象版の型宣言を確認してください。