# Video Call

videocall은 1:1 영상 통화 기능을 인터넷을 이용한 애플리케이션으로 구현한 것입니다. 통화 발신자는 caller, 착신자를 callee라는 통신 용어로 구분합니다. Omnitalk SDK를 사용하여 offerCall(), answerCall()을 각각 호출하고 해당 이벤트 메시지에 대응하는 것으로 전화 기능을 간단히 구현할 수 있습니다.

[Call Flow](/commons/call-flow.md) 에서는 audiocall의 흐름을 sequence diagram으로 보여줍니다.

## Step 1. 세션 생성

Omnitalk SDK의 초기화를 제외한 모든 API를 사용하기 위해서는 우선적으로 createSession()을 호출하여 세션을 생성해야 합니다. createSession()의 파라미터인 user\_id는 사용자를 구분하기 위한 고유한 id이며 audiocall 발신을 위한 offerCall() 호출에 사용됩니다. user\_id는 Optional 이며, 생략시 Omnitalk 서버에서 임의의 id를 부여합니다.

```typescript
await sdk.createSession(user_id);
```

## Step 2. 발신

동일한 Service Id로  세션을 생성한 사용자 중  idle state의 사용자에게 전화 요청을 할 수 있습니다.

offerCall() API로 전화 요청을 할 수 있습니다. 파라미터로 call\_type, callee의 user\_id, 녹음 여부를 전달하면 됩니다.

* call\_type: 전화 타입을 의미합니다. CALL\_TYPE은 Omnitalk SDK에서 enum type으로 제공합니다. 1:1 영상 통화를 위해서는 `videocall` 을 전달하시면 됩니다.&#x20;
* callee: callee의 user\_id를 전달하시면 됩니다.
* record: Optional 파라미터로, 녹음 여부를 의미합니다. defalut = false

```typescript
await sdk.offerCall(CALL_TYPE.VIDEO_CALL, callee, true);
```

offerCall 호출 성공시 caller는 `RINGBACK_EVEVT`, callee는 `RINGING_EVENT`를 수신합니다.

## Step 3. 수신

### callee가 RINGING\_EVENT를 받은 경우

callee가 세션을 생성한 상태에서 caller가 offerCall(전화 요청)을 하여`RINGING_EVENT`를 받은 경우, callee는 별도의 파라미터를 전달하지 않고 answerCall()을 호출하여 전화를 수신할 수 있습니다. 수신 거절을 하고싶은 경우 leave()를 호출하시면 됩니다.

```typescript
await sdk.answerCall();
```

### callee가 전화 요청(offerCall) 이후에 session을 생성한 경우

callee가 세션을 생성하기 전 caller가 offerCall(전화 요청)을 하여 `RINGING_EVENT`를 받지 못한 경우, callee는 answerCall()의 파라미터에 call\_type과 caller를 전달하여 전화를 수신할 수 있습니다. 이 경우, 애플리케이션에서 callee 에게 call\_type과 caller를 전달해 주어야 합니다.

* call\_type: 전화 타입을 의미합니다. caller가 offerCall()을 호출할 떄와 동일하게 `videocall` 을 전달하시면 됩니다.&#x20;
* caller: caller(전화 발신자)의 user\_id를 전달하시면 됩니다.

```typescript
await sdk.answerCall(CALL_TYPE.VIDEO_CALL, caller);
```

## Step 4. 연결 성공

1:1 영상 통화 연결이 성공하면 caller, callee 양측 모두 `CONNECTED_EVENT` 를 수신합니다.

## Step 5. 전화 끊기

[leave()](/typescript/api-reference.md#leave) API를 통해서 전화 연결을 끊을 수 있습니다.

```typescript
await sdk.leave();
```

## 비디오 장치 제어

### mute/unmute

영상 전화중에 영상 송출을 중단할 수 있도록 API를 제공합니다. 사용법과 자세한 내용은 API Reference의 [mute/unmute](/typescript/api-reference.md#mute-unmute) 부분을 참조 바랍니다. mute/unmute API의 파라미터인 track type은 Omnitalk SDK에서 enum type으로 제공합니다. 예시는 아래와 같습니다.

```typescript
await sdk.setMute(TRACK_TYPE.VIDEO);
```

### 입력 장치 변경

전화 연결 전, 또는 영상 전화 통화중에 입력(카메라) 장치를 변경할 수 있도록 API를 제공합니다.&#x20;

1. 우선, 사용 가능한 입력 장치 목록을 조회할 수 있는 [getDeviceList()](/typescript/api-reference.md#getdevicelist) 를 통해서 사용하고자 하는 장치의 deviceId를 획득합니다.
2. [setVideoDevice()](/typescript/api-reference.md#setvideodevice) 파라미터로 deviceId를 전달하여 입력 장치를 변경할 수 있습니다.

## 오디오 장치 제어

### mute/unmute

전화 통화중에 음소거를 할 수 있도록 API를 제공합니다. 사용법과 자세한 내용은 API Reference의 [mute/unmute](/typescript/api-reference.md#mute-unmute) 부분을 참조 바랍니다. mute/unmute API의 파라미터인 track type은 Omnitalk SDK에서 enum type으로 제공합니다. 예시는 아래와 같습니다.

```typescript
await sdk.setMute(TRACK_TYPE.AUDIO);
```

### 입력 장치 변경

전화 연결 전, 또는 전화 통화중에 입력(마이크) 장치를 변경할 수 있도록 API를 제공합니다.&#x20;

1. 우선, 사용 가능한 입력 장치 목록을 조회할 수 있는 [getDeviceList()](/typescript/api-reference.md#getdevicelist) 를 통해서 사용하고자 하는 장치의 deviceId를 획득합니다.
2. [setAudioDevice()](/typescript/api-reference.md#setaudiodevice) 파라미터로 deviceId를 전달하여 입력 장치를 변경할 수 있습니다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.omnitalk.io/typescript/developers-guide/video-call.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
