Skip to content

Instantly share code, notes, and snippets.

@Arunshaik2001
Created November 28, 2022 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arunshaik2001/fbdf14f741af08dd8515e32f769b475a to your computer and use it in GitHub Desktop.
Save Arunshaik2001/fbdf14f741af08dd8515e32f769b475a to your computer and use it in GitHub Desktop.
@Composable
fun VideoCallCompose() {
Scaffold(
content = { MyContent() }
)
}
@Composable
fun MyContent() {
val mUrl = "file:android_asset/call.html"
var isAudio by remember {
mutableStateOf(true)
}
var isVideo by remember {
mutableStateOf(true)
}
var webViewCompose: WebView? by remember {
mutableStateOf(null)
}
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
AndroidView(factory = {
val layoutInflater: LayoutInflater = LayoutInflater.from(it)
val view: View = layoutInflater.inflate(R.layout.activity_call, null, false)
view
}, update = { view ->
val webView: WebView = view.findViewById(R.id.webView)
webViewCompose = webView
webView.loadUrl(mUrl)
WebRTCUtil.setupWebView(webView)
})
Column(verticalArrangement = Arrangement.Bottom, modifier = Modifier.fillMaxHeight()) {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
Image(
modifier = Modifier.clickable {
isAudio = !isAudio
WebRTCUtil.callJavaScriptFunction(
webViewCompose!!,
"javascript:toggleAudio(\"$isAudio\")"
);
},
painter = painterResource(id = if (isAudio) R.drawable.btn_mute_normal else R.drawable.btn_unmute_normal),
contentDescription = "audio"
)
Image(
modifier = Modifier.clickable {
WebRTCUtil.callJavaScriptFunction(
webViewCompose!!,
"javascript:disconnectCall()"
);
mainActivity.finish()
},
painter = painterResource(id = R.drawable.btn_endcall_normal),
contentDescription = "end"
)
Image(
modifier = Modifier.clickable {
isVideo = !isVideo
WebRTCUtil.callJavaScriptFunction(
webViewCompose!!,
"javascript:toggleVideo(\"$isVideo\")"
);
},
painter = painterResource(id = if (isVideo) R.drawable.btn_video_muted else R.drawable.btn_video_normal),
contentDescription = "video"
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment