メディア、エモート、ルーム
マイク、カメラ、画面共有
ルートエントリのMic、Camera、Screenは、ホストから届くメディアイベントをコールバックで受け取ります。
import { Camera, Mic, Screen } from "@urth/metatell-sdk";
const mic = new Mic();
mic.onSpeechEnd = (file) => console.log(file);
mic.onChangeDevice = (device) => console.log(device.status);
const camera = new Camera();
camera.onChangeCamera = (transform) => console.log(transform.position);
const videoElement = document.querySelector<HTMLVideoElement>("#screen-share");
if (!videoElement) {
throw new Error("画面共有を表示するvideo要素が見つかりません");
}
const screen = new Screen();
screen.onScreenShare = (stream) => {
videoElement.srcObject = stream;
};
画面共有が終了すると、onScreenShareにはnullが渡されます。
発話状態を取得する
import { getLocalLevel, onSpeaking } from "@urth/metatell-sdk/voice";
const level = getLocalLevel();
const unsubscribe = onSpeaking((event) => {
console.log(event.speaking, event.level);
});
getLocalLevel()は自分の最新マイクレベルを返します。
他ユーザーの発話状態は@urth/metatell-sdk/usersのonSpeaking()で購読してください。
エモート
import { onEmote, trigger } from "@urth/metatell-sdk/emote";
trigger("wave");
const unsubscribe = onEmote((event) => {
console.log(event.sessionId, event.name, event.at);
});
利用できるエモート名はホスト側の設定に依存します。
Way Point
import { getWaypoints, warpToWaypoint } from "@urth/metatell-sdk";
const waypoints = getWaypoints();
for (const waypoint of waypoints ?? []) {
console.log(waypoint.id, waypoint.name, waypoint.position);
}
warpToWaypoint("entrance");
getWaypoints()はデータがない場合にnullを返します。
warpToWaypoint()にはIDではなくWay Pointの名前を渡します。
計測イベント
metricsは、metatellの計測基盤へイベントを送ります。
import { metrics } from "@urth/metatell-sdk";
metrics.click("click_button", { button_name: "help" });
metrics.transition("https://example.com", {
position: { x: 1, y: 2, z: 3 },
});
metrics.sendEvent("custom_event", { category: "mini_game" });
利用者IDを 取得できる場合はSDKが自動で付与します。 計測機能が利用できない環境では送信されません。