VRED 웹 API

소개

VRED는 Python API, 웹 API 및 대기 시간이 짧은 동영상 스트리밍을 제공하는 통합 웹 서버와 함께 제공됩니다. 웹 API는 RPC API(원격 절차 호출 API)이고 Python API v2와 동일한 기반을 토대로 하며 JavaScript를 통해 액세스할 수 있습니다. 동일한 함수 및 매개변수를 지원하므로 Python API v2에 대한 설명서를 사용하십시오.

웹 API의 장점은 Python API보다 사용하기 쉽고 웹 응용프로그램에 더 쉽게 통합할 수 있다는 것입니다. 또한 웹 API는 클라이언트에게 실시간으로 변경 사항을 알리는 이벤트 리스너(Python의 신호)를 지원합니다.

끝점

웹 API 끝점은 {schema}://{host}:{port}/api/{module}/{procedure}입니다.

예를 들어 TLS를 사용하여 로컬 인스턴스에 연결하는 URI는 다음과 같습니다.

http://localhost:8888/api/vrAnnotationService/getAnnotations

JavaScript 클라이언트 API

VRED는 웹 사이트 또는 앱에 쉽게 통합할 수 있는 통합된 JavaScript 클라이언트 라이브러리와 함께 제공됩니다.

클라이언트 라이브러리는 {schema}://{host}:{port}/api.js에서 사용할 수 있습니다.

예:

http://localhost:8888/api.js

클라이언트 라이브러리가 VRED 웹 서버 이외에서 로드되는 경우 기본 URL을 변경할 수 있습니다.

api.setBaseUrl(`${schema}://${host}:${port}`);

클라이언트 라이브러리 사용 방법에 대한 간단한 예는 아래에 나와 있습니다. 더 많은 예가 VRED와 함께 제공되며 예제 폴더에서 찾을 수 있습니다.

import { api } from 'http://localhost:8888/api.js';

// Connect event listener (signal)
api.vrAnnotationService.annotationsAdded.connect(() => console.log('Annotations added'));

// Add a new annotation
api.vrAnnotationService.createAnnotation('Annotation1')
  .then(() => {
    api.vrAnnotationService.findAnnotation('Annotation1')
      .then(a => a.setText('Lorem ipsum'));
  })
  .catch(() => console.error('Add annotation failed'));

// Get all annotations
api.vrAnnotationService.getAnnotations()
  .then(annotations => annotations.forEach(a => console.log(a)))
  .catch(() => console.error('Get annotations failed'));

OpenAPI 사양

또한 VRED는 Swagger UI 및 기타 유용한 API 도구와 함께 사용할 수 있는 웹 API용 OpenAPI 사양을 제공합니다.

사양은 {schema}://{host}:{port}/api.json에서 사용할 수 있습니다.

예:

http://localhost:8888/api.json