 import Foundation
 import AVFoundation
 
-
 class PluginGetUserMedia {
-	static var rtcVideoSource: RTCAVFoundationVideoSource?
-	let kARDMediaStreamId = "ARDAMS";
-	let kARDAudioTrackId = "ARDAMSa0";
-	let kARDVideoTrackId = "ARDAMSv0";
-	let kARDVideoTrackKind = "video";
 
 	var rtcPeerConnectionFactory: RTCPeerConnectionFactory
 
-
 	init(rtcPeerConnectionFactory: RTCPeerConnectionFactory) {
 		NSLog("PluginGetUserMedia#init()")
-
 		self.rtcPeerConnectionFactory = rtcPeerConnectionFactory
 	}
-
 
 	deinit {
 		NSLog("PluginGetUserMedia#deinit()")
 	}
-
 
 	func call(
 		_ constraints: NSDictionary,

				optionalConstraints: [:]
			)

			if(PluginGetUserMedia.rtcVideoSource == nil){
				PluginGetUserMedia.rtcVideoSource = self.rtcPeerConnectionFactory.avFoundationVideoSource(with: constraints);
			}

			PluginGetUserMedia.rtcVideoSource?.useBackCamera = !usingFront
			
			// If videoSource state is "ended" it means that constraints were not satisfied so
			// invoke the given errback.
			if (PluginGetUserMedia.rtcVideoSource!.state == RTCSourceState.ended) {
				NSLog("PluginGetUserMedia() | PluginGetUserMedia.rtcVideoSource.state is 'ended', constraints not satisfied")

				errback("constraints not satisfied")
				return
			}

			rtcVideoTrack = self.rtcPeerConnectionFactory.videoTrack(with: PluginGetUserMedia.rtcVideoSource!, trackId: UUID().uuidString)

			rtcMediaStream.addVideoTrack(rtcVideoTrack!)
		}

	) {
		NSLog("PluginGetUserMedia#call()")

		let    audioRequested = constraints.object(forKey: "audio") as? Bool ?? false
		let    videoRequested = constraints.object(forKey: "video") as? Bool ?? false
		let    videoDeviceId = constraints.object(forKey: "videoDeviceId") as? String
		let    audioDeviceId = constraints.object(forKey: "audioDeviceId") as? String
		let    videoMinWidth = constraints.object(forKey: "videoMinWidth") as? Int ?? 0
		let    videoMaxWidth = constraints.object(forKey: "videoMaxWidth") as? Int ?? 640
		let    videoMinHeight = constraints.object(forKey: "videoMinHeight") as? Int ?? 0
		let    videoMaxHeight = constraints.object(forKey: "videoMaxHeight") as? Int ?? 640
		let    videoMinFrameRate = constraints.object(forKey: "videoMinFrameRate") as? Float ?? 0.0
		let    videoMaxFrameRate = constraints.object(forKey: "videoMaxFrameRate") as? Float ?? 25.0

		var rtcMediaStream: RTCMediaStream
		var pluginMediaStream: PluginMediaStream?
		var rtcAudioTrack: RTCAudioTrack?
		var rtcVideoTrack: RTCVideoTrack?
		var rtcVideoCapturer: RTCCameraVideoCapturer?
		var rtcVideoSource: RTCVideoSource?
		var videoDevice: AVCaptureDevice?
		var mandatoryConstraints: [String: String] = [:]
		var constraints: RTCMediaConstraints

