Quick Start
Omnitalk SDK๋ฅผ ์ด๋ป๊ฒ ํ์ฉํ ์ ์๋์ง์ ๋ํ ๊ฐ๋จํ ์์์ ๋๋ค. ์์ธํ ์ฌ์ฉ๋ฒ์ Android API Reference๋ฅผ ์ฐธ์กฐ ๋ฐ๋๋๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก ๋ชจ๋ API๋ suspend fun ์ผ๋ก ์์ฑ ๋์์ผ๋ฉฐ, ์์ฒญ์ด ์คํจํ ๊ฒฝ์ฐ ์๋ฌ๋ฅผ throw ํฉ๋๋ค. ์์์ ๋ฐ๋ชจ์์๋ CoroutineScope๋ฅผ ์ฌ์ฉํฉ๋๋ค.
๋ฐ๋ชจ ์ฑ ์์ค์ฝ๋: https://github.com/omnistory-labs/omnitalk.android.sdk/tree/demo
1:1 ์์ ํตํ
1. ์ด๋ํก ๊ฐ์ฒด ์์ฑ
์ฝ์์์ ๋ฐ๊ธ๋ฐ์ Service ID์ Service KEY๋ก Omnitalk ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค.
import io.omnitalk.sdk.Omnitalk
Omnitalk.sdkInit(
serviceId = "YOUR_SERVICE_ID",
serviceKey = "YOUR_SERVICE_KEY",
applicationContext = applicationContext
)
val sdk = Omnitalk.getInstance()
2. ์ธ์
์์ฑ
์ธ์๋ก ์ ๋ฌํ userId๋ก ์ธ์ ์ ์์ฑํ๊ฒ ๋ฉ๋๋ค. userId๋ Optional์ด๋ฉฐ, null์ผ ๊ฒฝ์ฐ ์๋ฒ์์ ์์์ userId๋ฅผ ์์ฑํฉ๋๋ค.
val createSessionResult = sdk.createSession(userId = "alice")
3. ๋ฐ์
1:1 ์์ ํตํ๋ฅผ ๊ตฌํํ๊ธฐ ์ํ ๋ฐ์ ๊ธฐ๋ฅ์ offerCall() API๋ฅผ ์ด์ฉํฉ๋๋ค. ์์ ๊ณผ ์๋๋ฐฉ์ ์์์ ํ๋ฉด์ ์ฌ์ํ๊ธฐ ์ํด์ ํ๋ผ๋ฏธํฐ์ ์์์ ์ถ๋ ฅํ SurfaceViewRenderer
๊ฐ์ฒด๋ฅผ ์ ๋ฌํฉ๋๋ค. ํด๋น ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ธฐ ์ํด์ WebRTC ๋ชจ๋์ import ํด์ผ ํฉ๋๋ค. ( Omnitalk SDK ์ค์น์ ํฌํจ๋ ํจํค์ง )
offerCall ํธ์ถ์ด ์ฑ๊ณตํ๋ฉด caller์๊ฒ๋ RINGBACK_EVENT
๊ฐ, callee์๊ฒ๋ RINGING_EVENT
๊ฐ ์ ๋ฌ๋ฉ๋๋ค.
import org.webrtc.SurfaceViewRenderer
import io.omnitalk.sdk.types.PublicTypes
val callee = "[email protected]"
val localView = findViewById<SurfaceViewRenderer>(R.id.localView)
val remoteView = findViewById<SurfaceViewRenderer>(R.id.remoteView)
sdk.offerCall(
callType = PublicTypes.CALL_TYPE.videocall,
callee = callee,
record = true,
localView = localView,
remoteView = remoteView
)
4. ์์
callee์ธก์์๋ RINGING_EVENT
๋ฅผ ๋ฐ๊ณ ํตํ๋ฅผ ์๋ฝํ๊ฑฐ๋ ๊ฑฐ์ ํ ์ ์์ต๋๋ค. ํตํ ์๋ฝ์ answerCall() API๋ฅผ ์ด์ฉํฉ๋๋ค. ์์ ๊ณผ ์๋๋ฐฉ์ ์์์ ์ฌ์ํ๊ธฐ ์ํด์ ํ๋ผ๋ฏธํฐ์ ์์์ ์ถ๋ ฅํ SurfaceViewRenderer
๊ฐ์ฒด๋ฅผ ์ ๋ฌํฉ๋๋ค. ํด๋น ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ธฐ ์ํด์ WebRTC ๋ชจ๋์ import ํด์ผ ํฉ๋๋ค. ( Omnitalk SDK ์ค์น์ ํฌํจ๋ ํจํค์ง )
answerCall์ด ์ ์์ ์ผ๋ก ์ํ๋๋ฉด caller, callee ์์ธก์ CONNECTED_EVENT
๋ฅผ ๋ฐ์ต๋๋ค. ์์ ๊ฑฐ์ ์ leave() API๋ฅผ ์ด์ฉํ์๋ฉด ๋ฉ๋๋ค.
override fun onEvent(eventName: OmniEvent, message: Any) {
when(eventName) {
OmniEvent.RINGING_EVENT -> {
sdk.answerCall(localView = localView, remoteView = remoteView)
}
OmniEvent.CONNECTED_EVENT -> {
...
}
}
}
์์ ํ์
1. ์ด๋ํก ๊ฐ์ฒด ์์ฑ
์ฝ์์์ ๋ฐ๊ธ๋ฐ์ Service ID์ Service KEY๋ก Omnitalk ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค.
import io.omnitalk.sdk.Omnitalk
Omnitalk.sdkInit(
serviceId = "YOUR_SERVICE_ID",
serviceKey = "YOUR_SERVICE_KEY",
applicationContext = applicationContext
)
val sdk = Omnitalk.getInstance()
2. ์ธ์
์์ฑ
์ธ์๋ก ์ ๋ฌํ userId๋ก ์ธ์ ์ ์์ฑํ๊ฒ ๋ฉ๋๋ค. userId๋ Optional์ด๋ฉฐ, null์ผ ๊ฒฝ์ฐ ์๋ฒ์์ ์์์ userId๋ฅผ ์์ฑํฉ๋๋ค.
val createSessionResult = sdk.createSession(userId = "alice")
3. ๋ฃธ ์์ฑ
์์ ํ์๋ฅผ ์ํ ๋ฃธ์ ์์ฑํฉ๋๋ค. roomType์ ์ ์ธํ ๋๋จธ์ง ํ๋ผ๋ฏธํฐ๋ Optional ์ ๋๋ค.
import io.omnitalk.sdk.types.PublicTypes
val createRoomResult = sdk.createRoom(
roomType = PublicTypes.VIDEOROOM_TYPE.videoroom,
subject = "subject",
secret = "secret",
startDate = null,
endDate = null
)
4. ๋ฃธ ์ฐธ์ฌ
๋ฃธ์ ์ฐธ์ฌํ๊ฒ ๋๋ฉด ์์ฑ๊ณผ ์ฑํ ๋ฉ์์ง๋ฅผ ์ฃผ๊ณ ๋ฐ์ ์ ์๋ ์ํ๊ฐ ๋ฉ๋๋ค. roomId์ ์ ์ธํ ๋๋จธ์ง ํ๋ผ๋ฏธํฐ๋ Optional ์ ๋๋ค.
val roomId = createRoomResult.roomId
sdk.joinRoom(roomId = roomId, secret = "secret", userName = "userName")
5. ๋ฐฉ์ก ์์
๋ก์ปฌ์ ์์์ ์ก์ถํฉ๋๋ค. publish API๋ roomType VIDEO_ROOM
๋๋ WEBINAR
์์๋ง ํ์ํ ๊ธฐ๋ฅ์
๋๋ค.
์์์ ์ฌ์ํ๊ธฐ ์ํด์ ํ๋ผ๋ฏธํฐ์ ์์์ ์ถ๋ ฅํ SurfaceViewRenderer
๊ฐ์ฒด๋ฅผ ์ ๋ฌํฉ๋๋ค. ํด๋น ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ธฐ ์ํด์ WebRTC ๋ชจ๋์ import ํด์ผ ํฉ๋๋ค. ( Omnitalk SDK ์ค์น์ ํฌํจ๋ ํจํค์ง )
import org.webrtc.SurfaceViewRenderer
val localView = findViewById<SurfaceViewRenderer>(R.id.localView)
sdk.publish(localView = localView)
6. ๋ฐฉ์ก ๊ตฌ๋
๊ตฌ๋
ํ๊ณ ์๋ ๋ฐฉ์ก์ session์ ์ธ์๋ก ์ ๋ฌํ๋ฉด ํด๋น ๋ฐฉ์ก์ ๊ตฌ๋
ํ ์ ์์ต๋๋ค. ์๋๋ฐฉ ์์์ ์ฌ์ํ๊ธฐ ์ํด์ ํ๋ผ๋ฏธํฐ์ ์์์ ์ถ๋ ฅํ SurfaceViewRenderer
๊ฐ์ฒด๋ฅผ ์ ๋ฌํฉ๋๋ค. ํด๋น ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ธฐ ์ํด์ WebRTC ๋ชจ๋์ import ํด์ผ ํฉ๋๋ค. ( Omnitalk SDK ์ค์น์ ํฌํจ๋ ํจํค์ง )
import org.webrtc.SurfaceViewRenderer
val remoteView = findViewById<SurfaceViewRenderer>(R.id.remoteView)
sdk.subscribe(publisherSession = publisherSession, remoteView = remoteView)
Last updated