앱 연동 매뉴얼

기존 앱의 화면에 캐릭터를 연결하는 개발자용 매뉴얼이다. 현재 SDK는 비공개 패키지이므로 저장소 접근 권한이 필요하다.

1. 준비 사항

패키지를 읽을 CharacterPackageReaderV1, 캐릭터 렌더러, 대상의 ID와 역할, 앱에서 실행할 activation 콜백을 준비한다. 각 세션과 서비스의 생명주기는 앱에서 관리한다.

2. API 선택

일반 Runtime은 @charaweave/runtime의 명령/스냅샷 인터페이스다. 일반 브라우저 앱에는 Core V10의 createCoreSession과 createBrowserSession을 사용한다. React는 CharaWeaveProvider와 useCharaWeaveHost를 지원한다. 기존 Platform 구성은 V6 projection을 사용한다. Content V11은 확장 행동 정보를 읽지만 전체 V11 CharacterSession을 생성하는 단일 Public SDK는 없다.

실행 예제는 Web 연동과 React 연동에 있다.

3. 패키지 읽기

import { loadCharacterContentV11 } from "@charaweave/content";
import type { CharacterPackageReaderV1 } from "@charaweave/content";

declare const reader: CharacterPackageReaderV1;
const result = await loadCharacterContentV11({
  reader,
  characterId: "example.simple-cat:cat",
});
if (!result.ok) {
  throw new Error(`Invalid Character package: ${result.issues.length} issue(s)`);
}
const characterContent = result.character;

reader에서 파일의 읽기와 존재 여부를 구현한다. 렌더러는 로더가 반환한 에셋을 별도로 가져오고 디코딩한다.

4. 기존 Platform V6 브라우저 구성

import { createConsumerSession } from "@charaweave/platform";
import { createBrowserEnvironment } from "@charaweave/platform/browser";
import { createCharacterViewportPlacement } from "@charaweave/browser-runtime";
import type { CharacterPackageReaderV1 } from "@charaweave/content";
import type { AutonomyTargetSessionPolicyV1 } from "@charaweave/autonomy";
import type { CharacterViewportPlacementV1 } from "@charaweave/browser-runtime";

declare const reader: CharacterPackageReaderV1;
declare const targetSessionPolicy: AutonomyTargetSessionPolicyV1;
declare const characterElement: HTMLElement;
declare function openPhoto(surfaceId: string): Promise<void>;
let placement: CharacterViewportPlacementV1 = createCharacterViewportPlacement(0, 0);

const session = await createConsumerSession({
  character: { reader, characterId: "example.simple-cat:cat" },
  targetSessionPolicy,
});
const browser = createBrowserEnvironment(session, {
  character: {
    getElement: () => characterElement,
    getCurrentPlacement: () => placement,
    applyPlacement: (next) => { placement = next; },
  },
  approachClearancePx: 16,
  motionDurationMs: 280,
});

CharacterPackageReaderV1은 @charaweave/content에서 가져온다. 위 이동 거리와 시간 설정은 예시다. characterElement가 연결된 상태에서 위치 변경을 실제 DOM에 반영한다.

5. 대상 등록

const attachment = browser.attachHost({
  element: photoCardElement,
  id: "feed.photo.42",
  role: "photo-card",
  capabilities: ["activate"],
  onActivate: async ({ surfaceId }) => openPhoto(surfaceId),
});
session.start();

id, role, capabilities는 앱이 정한다. activate에는 앱에서 제공한 콜백이 필요하다. visit는 접근만 수행한다. inspect 역시 제품 데이터의 접근 권한을 새로 부여하지 않는다.

6. 대상 교체와 해제

제품 데이터가 바뀌면 이전 연결을 해제하고 새로운 ID로 등록한다. 동일한 대상의 DOM만 바뀌는 경우에도 어댑터 생명주기에 맞춰 재연결한다. 등록 세대는 이전 실행과 현재 등록을 구별한다. useCharaWeaveHost, useConsumerHost, useCharaSurface로 연결한 요소를 수동 API로 다시 등록하지 않는다.

7. 화면 표현 완료 처리

이미지 로딩, 디코딩, 위치, 프레임 시간, 유한 클립의 종료 전달을 앱에서 구현한다. 오래된 완료가 새 터치나 복구 활동을 덮어쓰지 않도록 현재 실행 세대를 사용한다. DOMRect는 viewport CSS 픽셀이다. 캐릭터가 화면의 기존 접근성을 방해하지 않도록 처리한다.

8. 터치와 콜백

선택한 세션의 interaction 명령을 사용한다. 활성화는 앱의 콜백으로 실행한다. 패키지 데이터에 URL 실행이나 스크립트 등의 권한을 부여하지 않는다. 취소·실패는 완료로 처리하지 않는다.

9. 종료

Platform V6에서는 연결과 실행을 정리하고 세션을 dispose한다.

attachment.detach();
session.stop();
session.dispose(); // also disposes its registered Browser environment and Runtime

ConsumerSession.dispose()는 등록된 Browser 환경 및 소유 Runtime/Autonomy를 정리한다. 중복 호출은 안전하며 BrowserEnvironment에는 별도 public dispose()가 없다. Core/Browser의 독립 구성은 Browser를 먼저 종료하고 Core를 닫는다. 직접 구성한 서비스의 경우 생성한 계층에서 역순으로 정리한다.

10. 제품 화면 테스트

실제 앱에서 요소의 마운트와 언마운트, 대상 교체, 활성화, 등록 해제 후 늦게 도착하는 결과를 확인한다. 터치 반응과 복구, 대기 상태로의 복귀도 시험한다. Studio의 대상은 테스트용이므로 제품 화면에서의 연동 검증을 대신할 수 없다.