public static IMediaStream Create(MediaStreamConstraints constraints) { var mediaStreamTracks = new List <IMediaStreamTrack>(); bool isAudio = (constraints.Audio.Value.HasValue && constraints.Audio.Value == true) || constraints.Audio.Object != null; bool isVideo = (constraints.Video.Value.HasValue && constraints.Video.Value == true) || constraints.Video.Object != null; if (isAudio) { var defaultAudioDevice = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Audio); mediaStreamTracks.Add(MediaStreamTrack.Create(MediaStreamTrackKind.Audio, defaultAudioDevice.UniqueID)); } if (isVideo) { var devices = Webrtc.RTCCameraVideoCapturer.CaptureDevices; //// TODO: CURENTLY HARD CODED TO BACK. SELECT THE CAMERA BASED ON constraints var defaultVideoDevice = devices.FirstOrDefault(d => d.Position == AVCaptureDevicePosition.Front /*.Back*/); //var defaultVideoDevice = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Video); mediaStreamTracks.Add(MediaStreamTrack.Create(MediaStreamTrackKind.Video, defaultVideoDevice.UniqueID)); } var nativeMediaStream = WebRTCme.WebRtc.NativePeerConnectionFactory.MediaStreamWithStreamId($"{WebRTCme.WebRtc.Id}"); var self = new MediaStream(nativeMediaStream); foreach (var track in mediaStreamTracks) { self.AddTrack(track); } return(self); }
public static IMediaStream Create(MediaStreamConstraints constraints) { var activity = Xamarin.Essentials.Platform.CurrentActivity; var context = activity.ApplicationContext; var mediaStreamTracks = new List <IMediaStreamTrack>(); bool isAudio = (constraints.Audio.Value.HasValue && constraints.Audio.Value == true) || constraints.Audio.Object != null; bool isVideo = (constraints.Video.Value.HasValue && constraints.Video.Value == true) || constraints.Video.Object != null; if (isAudio) { // TODO: HOW TO GET DEFAULT AUDIO INPUT??? var audioManager = (AudioManager)activity.GetSystemService(global::Android.Content.Context.AudioService); ////var id = audioManager.Microphones[0].Id; // alzubitariq modification: https://github.com/melihercan/WebRTCme/issues/1 int id = 0; if (Build.VERSION.SdkInt >= BuildVersionCodes.P) { id = audioManager.Microphones[0].Id; } else { AudioDeviceInfo[] deviceInfo = audioManager.GetDevices(GetDevicesTargets.Inputs); id = deviceInfo[0].Id; } mediaStreamTracks.Add(MediaStreamTrack.Create(MediaStreamTrackKind.Audio, $"{id}")); } if (isVideo) { // TODO: HOW TO GET DEFAULT VIDEO INPUT??? var cameraManager = (CameraManager)activity.GetSystemService( global::Android.Content.Context.CameraService); //var list = cameraManager.GetCameraIdList(); var id = cameraManager.GetCameraIdList()[/*0*/ 1]; //// TODO: CURENTLY HARD CODED TO FRONT. SELECT THE CAMERA BASED ON constraints mediaStreamTracks.Add(MediaStreamTrack.Create(MediaStreamTrackKind.Video, $"{id}")); } var nativeMediaStream = WebRTCme.WebRtc.NativePeerConnectionFactory .CreateLocalMediaStream($"{WebRTCme.WebRtc.Id}"); var self = new MediaStream(nativeMediaStream); foreach (var track in mediaStreamTracks) { self.AddTrack(track); } return(self); }
public async Task <IMediaStream> GetCameraMediaStreamAsync(CameraType cameraType = CameraType.Default, MediaStreamConstraints mediaStreamConstraints = null) { var mediaStream = await _mediaDevices.GetUserMedia(mediaStreamConstraints ?? new MediaStreamConstraints { Audio = new MediaStreamContraintsUnion { Value = true }, Video = new MediaStreamContraintsUnion { Value = true } }); return(mediaStream); }
public async Task <IMediaStream> GetDisplayMediaStreamAync(MediaStreamConstraints mediaStreamConstraints = null) { var mediaStream = await _mediaDevices.GetDisplayMedia(mediaStreamConstraints ?? new MediaStreamConstraints { Video = new MediaStreamContraintsUnion { Object = new MediaTrackConstraints { Cursor = CursorOptions.Never, DisplaySurface = DisplaySurfaceOptions.Monitor } } }); return(mediaStream); }
public async Task <IMediaStream> GetUserMedia(MediaStreamConstraints constraints) => await Task.FromResult(MediaStream.Create(JsRuntime, await JsRuntime.CallJsMethodAsync <JsObjectRef>(NativeObject, "getUserMedia", constraints)));
private void Button_Click(object sender, RoutedEventArgs e) { RTCIceGatherOptions options = new RTCIceGatherOptions(); RTCIceServer server = new RTCIceServer(); server.UserName = "******"; server.Credential = "12345"; server.Urls = new List <String>(); server.Urls.Add("stun:stun.vline.com"); options.IceServers = new List <RTCIceServer>(); options.IceServers.Add(server); _iceGatherer = new RTCIceGatherer(options); _iceGatherer.OnStateChange += this.RTCIceGatherer_onICEGathererStateChanged; _iceGatherer.OnLocalCandidate += this.RTCIceGatherer_onICEGathererLocalCandidate; _iceGatherer.OnLocalCandidateComplete += this.RTCIceGatherer_onICEGathererCandidateComplete; _iceGatherer.OnLocalCandidateGone += this.RTCIceGatherer_onICEGathererLocalCandidateGone; _iceGatherer.OnError += this.RTCIceGatherer_onICEGathererError; _iceGatherer2 = new RTCIceGatherer(options); _iceGatherer2.OnStateChange += this.RTCIceGatherer_onICEGathererStateChanged2; _iceGatherer2.OnLocalCandidate += this.RTCIceGatherer_onICEGathererLocalCandidate2; _iceGatherer2.OnLocalCandidateComplete += this.RTCIceGatherer_onICEGathererCandidateComplete2; _iceGatherer2.OnLocalCandidateGone += this.RTCIceGatherer_onICEGathererLocalCandidateGone2; _iceGatherer2.OnError += this.RTCIceGatherer_onICEGathererError; _iceTransport = new RTCIceTransport(_iceGatherer); _iceTransport.OnStateChange += RTCIceTransport_onICETransportStateChanged; _iceTransport.OnCandidatePairAvailable += RTCIceTransport_onICETransportCandidatePairAvailable; _iceTransport.OnCandidatePairGone += RTCIceTransport_onICETransportCandidatePairGone; _iceTransport.OnCandidatePairChange += RTCIceTransport_onICETransportCandidatePairChanged; _iceTransport2 = new RTCIceTransport(_iceGatherer); _iceTransport2.OnStateChange += RTCIceTransport_onICETransportStateChanged2; _iceTransport2.OnCandidatePairAvailable += RTCIceTransport_onICETransportCandidatePairAvailable2; _iceTransport2.OnCandidatePairGone += RTCIceTransport_onICETransportCandidatePairGone2; _iceTransport2.OnCandidatePairChange += RTCIceTransport_onICETransportCandidatePairChanged2; RTCCertificate.GenerateCertificate().AsTask <RTCCertificate>().ContinueWith((cert) => { String str = cert.Result.Expires.ToString(); List <RTCCertificate> certs = new List <RTCCertificate>(); certs.Add(cert.Result); _dtlsTransport = new RTCDtlsTransport(_iceTransport, certs); MediaStreamConstraints constraints = new MediaStreamConstraints(); constraints.Audio = new MediaTrackConstraints(); constraints.Video = new MediaTrackConstraints(); MediaDevices.GetUserMedia(constraints).AsTask().ContinueWith <IList <MediaStreamTrack> >((temp) => { if (temp.Result != null && temp.Result.Count() > 0) { List <MediaStreamTrack> ret = new List <MediaStreamTrack>(temp.Result); List <RTCRtpSender> senders = new List <RTCRtpSender>(); foreach (MediaStreamTrack track in temp.Result) { RTCRtpSender rtpSender = new RTCRtpSender(track, _dtlsTransport); senders.Add(rtpSender); } return(ret); } return(null); }); }); RTCCertificate.GenerateCertificate().AsTask <RTCCertificate>().ContinueWith((cert) => { var certs = new List <RTCCertificate>(); certs.Add(cert.Result); _dtlsTransport2 = new RTCDtlsTransport(_iceTransport2, certs); }); MediaDevices.EnumerateDevices().AsTask().ContinueWith <MediaDeviceInfo>((temp) => { foreach (MediaDeviceInfo info in temp.Result) { if (info.DeviceId != null) { System.Diagnostics.Debug.WriteLine("DeviceID: {0}", info.DeviceId); } } return(null); }); }
public Task <IMediaStream> GetUserMedia(MediaStreamConstraints constraints) => Task.FromResult(MediaStream.Create(constraints));
public Task <IMediaStream> GetDisplayMedia(MediaStreamConstraints constraints) { throw new NotImplementedException(); }
public static MediaStreamConstraints MakeConstraints( bool shouldDoThis, MediaStreamConstraints existingConstraints, MediaDeviceKind kind, MediaDevice device ) { if (!shouldDoThis) { return(existingConstraints); } if (null == device) { return(existingConstraints); } if (null == existingConstraints) { existingConstraints = new MediaStreamConstraints(); } IMediaTrackConstraints trackConstraints = null; switch (kind) { case MediaDeviceKind.AudioInput: trackConstraints = existingConstraints.Audio; break; case MediaDeviceKind.AudioOutput: trackConstraints = existingConstraints.Audio; break; case MediaDeviceKind.VideoInput: trackConstraints = existingConstraints.Video; break; } if (null == trackConstraints) { trackConstraints = new MediaTrackConstraints(); } var newAdvancedList = new List <MediaTrackConstraintSet>(); if (null == trackConstraints.Advanced) { trackConstraints.Advanced = newAdvancedList; } var constraintSet = new MediaTrackConstraintSet { DeviceId = new ConstrainString { Parameters = new ConstrainStringParameters { Exact = new StringOrStringList { Value = device.Id } }, Value = new StringOrStringList { Value = device.Id } } }; newAdvancedList.Add(constraintSet); trackConstraints.Advanced = newAdvancedList; switch (kind) { case MediaDeviceKind.AudioInput: existingConstraints.Audio = trackConstraints; break; case MediaDeviceKind.AudioOutput: existingConstraints.Audio = trackConstraints; break; case MediaDeviceKind.VideoInput: existingConstraints.Video = trackConstraints; break; } return(existingConstraints); }