package com.ejada.hmg.utils

import com.ejada.hmg.MainActivity
import com.ejada.hmg.opentok.OpenTok
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

class OpenTokPlatformBridge(private var flutterEngine: FlutterEngine, private var mainActivity: MainActivity) {

    private lateinit var channel: MethodChannel
    private lateinit var openTok: OpenTok

    companion object {
        private const val CHANNEL = "OpenTok-Platform-Bridge"
    }

    fun create(){
        openTok = OpenTok(mainActivity, flutterEngine)
        channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
        channel.setMethodCallHandler { call: MethodCall, result: MethodChannel.Result ->
            when (call.method) {
                "initSession" -> {
                    openTok.initSession(call, result)
                }
                "swapCamera" -> {
                    openTok.swapCamera(call, result)
                }
                "toggleAudio" -> {
                    openTok.toggleAudio(call, result)
                }
                "toggleVideo" -> {
                    openTok.toggleVideo(call, result)
                }
                "hangupCall" -> {
                    openTok.hangupCall(call, result)
                }
                else -> {
                    result.notImplemented()
                }
            }
        }
    }

}
