Skip to content

Instantly share code, notes, and snippets.

import UIKit
import shared
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 230, height: 21))
label.center = CGPoint(x: 160, y: 285)
package xyz.vivekc.kotlinmultiplatformdemo
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
import xyz.vivekc.shared.getDate
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
package xyz.vivekc.shared
import platform.Foundation.NSDate
actual fun getCurrentDate() = NSDate().toString()
package xyz.vivekc.shared
import java.util.*
actual fun getCurrentDate() = Date().toString()
package xyz.vivekc.shared
//Mark the function dependent on platform implementation to be `expect`
expect fun getCurrentDate(): String
//This is the function which would be called by the Android or iOS app
fun getDate(): String {
return "Today's Date is ${getCurrentDate()}"
}
apply plugin: 'kotlin-multiplatform'
kotlin {
targets {
//create a target for Android from presets.jvm
fromPreset(presets.jvm, 'android')
//Xcode sets SDK_NAME environment variable - based on whether the
//target device is a simulator or a real device, the preset should vary
internal class SignallingClientKotlin {
internal interface SignalingInterface {
fun onRemoteHangUp(msg: String)
fun onOfferReceived(data: JSONObject)
fun onAnswerReceived(data: JSONObject)
class MainActivityKotlin : AppCompatActivity(), View.OnClickListener, SignallingClientKotlin.SignalingInterface {
private val rootEglBase by lazy { EglBase.create() }
private val peerConnectionFactory: PeerConnectionFactory by lazy {
//Initialize PeerConnectionFactory globals.
val initializationOptions = PeerConnectionFactory.InitializationOptions.builder(this)
.setEnableVideoHwAcceleration(true)
.createInitializationOptions()
PeerConnectionFactory.initialize(initializationOptions)
class SignallingClient {
private static SignallingClient instance;
private String roomName = null;
private Socket socket;
boolean isChannelReady = false;
boolean isInitiator = false;
boolean isStarted = false;
private SignalingInterface callback;
//This piece of code should not go into production!!
public class MainActivity extends AppCompatActivity implements View.OnClickListener, SignallingClient.SignalingInterface {
PeerConnectionFactory peerConnectionFactory;
MediaConstraints audioConstraints;
MediaConstraints videoConstraints;
MediaConstraints sdpConstraints;
VideoSource videoSource;
VideoTrack localVideoTrack;
AudioSource audioSource;
AudioTrack localAudioTrack;