 	var onSetDescriptionSuccessCallback: (() -> Void)!
 	var onSetDescriptionFailureCallback: ((_ error: Error) -> Void)!
 	var onGetStatsCallback: ((_ array: NSArray) -> Void)!
-		
+
 	var streamIds: [String] = []
+	var pluginMediaStreams: [String : PluginMediaStream]! = [:]
 	var trackIdsToSenders: [String : RTCRtpSender] = [:]
 
 	var isAudioInputSelected: Bool = false

			"stream": pluginMediaStream.getJSON()
		])
	}
	 
	/** Called when a remote peer closes a stream. */
	func peerConnection(_ peerConnection: RTCPeerConnection, didRemove stream: RTCMediaStream) {
		NSLog("PluginRTCPeerConnection | onremovestream")

		// Let the plugin remove it from its dictionary.
		self.eventListenerForRemoveStream(stream.streamId)

		self.eventListener([
			"type": "removestream",
			"streamId": stream.streamId
		])
	}
	
	/** Called when the SignalingState changed. */
	
	// TODO: remove on M75
	// This was already fixed in M-75, but note that "Issue 740501: RTCPeerConnection.onnegotiationneeded can sometimes fire multiple times in a row" was a prerequisite of Perfect Negotiation as well.
	// https://stackoverflow.com/questions/48963787/failed-to-set-local-answer-sdp-called-in-wrong-state-kstable
	// https://bugs.chromium.org/p/chromium/issues/detail?id=740501
	// https://bugs.chromium.org/p/chromium/issues/detail?id=980872
	var isNegotiating = false;
	
	func peerConnection(_ peerConnection: RTCPeerConnection, didChange stateChanged: RTCSignalingState) {
		let state_str = PluginRTCTypes.signalingStates[stateChanged.rawValue] as String?

		NSLog("PluginRTCPeerConnection | onsignalingstatechange [signalingState:%@]", String(describing: state_str))
		
		isNegotiating = (state_str != "stable")
		
		self.eventListener([
			"type": "signalingstatechange",
			"signalingState": state_str!


	/** New track as been added. */
	func peerConnection(_ peerConnection: RTCPeerConnection, didAdd rtpReceiver: RTCRtpReceiver, streams:[RTCMediaStream]) {

		NSLog("PluginRTCPeerConnection | onaddtrack")

		// TODO why streams.count is 0 and should it trigger addtrack
		// TODO why NSLog streamId cause crash need weak ?
		let streamId : String = streams.count > 0 ? streams[0].streamId : "";

		let track = PluginMediaStreamTrack(
		   rtcMediaStreamTrack: rtpReceiver.track!,
		   streamId: streamId
		)

		self.eventListener([
		   "type": "addtrack",
		   "track": track.getJSON()
