Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getLocalVideoTrack and getLocalAudioTrack methods #58

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions WebRTC-Sample-App/VideoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ extension VideoViewController: AntMediaClientDelegate {
func localStreamStarted(streamId: String) {
print("Local stream added")
self.fullVideoView.isHidden = false

var localVideoTrack:RTCVideoTrack? = self.client?.getLocalVideoTrack();

print("local video trackId:\(localVideoTrack?.trackId)");

var localAudioTrack:RTCAudioTrack? = self.client?.getLocalAudioTrack();

print("local audio trackId:\(localAudioTrack?.trackId)");

}


Expand Down
15 changes: 14 additions & 1 deletion WebRTCiOSSDK/api/AntMediaClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,14 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
if (self.webRTCClientMap[id] == nil) {
AntMediaClient.printf("Has wsClient? (start) : \(String(describing: self.webRTCClientMap[id]))")

self.webRTCClientMap[id] = WebRTCClient.init(remoteVideoView: remoteView, localVideoView: localView, delegate: self, mode: mode != .unspecified ? mode : self.mode , cameraPosition: self.cameraPosition, targetWidth: self.targetWidth, targetHeight: self.targetHeight, videoEnabled: self.videoEnable, enableDataChannel: self.enableDataChannel, useExternalCameraSource: self.useExternalCameraSource, externalAudio: self.externalAudioEnabled, externalVideoCapture: self.externalVideoCapture, cameraSourceFPS: self.cameraSourceFPS, streamId:id,
self.webRTCClientMap[id] = WebRTCClient.init(remoteVideoView: remoteView, localVideoView: localView, delegate: self, cameraPosition: self.cameraPosition, targetWidth: self.targetWidth, targetHeight: self.targetHeight, videoEnabled: self.videoEnable, enableDataChannel: self.enableDataChannel, useExternalCameraSource: self.useExternalCameraSource, externalAudio: self.externalAudioEnabled, externalVideoCapture: self.externalVideoCapture, cameraSourceFPS: self.cameraSourceFPS, streamId:id,
degradationPreference: self.degradationPreference);


if (self.mode != .play) {
self.webRTCClientMap[id]?.addLocalMediaStream();
}

self.webRTCClientMap[id]?.setToken(token)

AntMediaClient.rtcAudioSession.add(self);
Expand Down Expand Up @@ -637,6 +642,14 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
self.sendAudioTrackStatusNotification(enabled:enableTrack);
}

open func getLocalAudioTrack() -> RTCAudioTrack? {
self.webRTCClientMap[self.publisherStreamId ?? (self.p2pStreamId ?? "")]?.getLocalAudioTrack();
}

open func getLocalVideoTrack() -> RTCVideoTrack? {
self.webRTCClientMap[self.publisherStreamId ?? (self.p2pStreamId ?? "")]?.getLocalVideoTrack();
}

func sendNotification(eventType:String, streamId: String = "") {
let notification = [
EVENT_TYPE: eventType,
Expand Down
9 changes: 9 additions & 0 deletions WebRTCiOSSDK/api/AntMediaClientProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ public protocol AntMediaClientProtocol {
*/
func enableTrack(trackId:String, enabled:Bool)

/**
Get the local video track which is local camera or external source which is screen
*/
func getLocalVideoTrack() -> RTCVideoTrack?;

/**
Get the local audio track which is the local microphone
*/
func getLocalAudioTrack() -> RTCAudioTrack?;
/**
Call this method to join a conference room
- Parameters
Expand Down
28 changes: 18 additions & 10 deletions WebRTCiOSSDK/api/webrtc/WebRTCClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ class WebRTCClient: NSObject {
self.peerConnection = WebRTCClient.factory.peerConnection(with: configuration, constraints: defaultConstraint, delegate: self)
}

public convenience init(remoteVideoView: RTCVideoRenderer?, localVideoView: RTCVideoRenderer?, delegate: WebRTCClientDelegate, mode: AntMediaClientMode, cameraPosition: AVCaptureDevice.Position, targetWidth: Int, targetHeight: Int, streamId: String) {
public convenience init(remoteVideoView: RTCVideoRenderer?, localVideoView: RTCVideoRenderer?, delegate: WebRTCClientDelegate, cameraPosition: AVCaptureDevice.Position, targetWidth: Int, targetHeight: Int, streamId: String) {
self.init(remoteVideoView: remoteVideoView, localVideoView: localVideoView, delegate: delegate,
mode: mode, cameraPosition: cameraPosition, targetWidth: targetWidth, targetHeight: targetHeight, videoEnabled: true, enableDataChannel:false, streamId: streamId)
cameraPosition: cameraPosition, targetWidth: targetWidth, targetHeight: targetHeight, videoEnabled: true, enableDataChannel:false, streamId: streamId)
}
public convenience init(remoteVideoView: RTCVideoRenderer?, localVideoView: RTCVideoRenderer?, delegate: WebRTCClientDelegate, mode: AntMediaClientMode, cameraPosition: AVCaptureDevice.Position, targetWidth: Int, targetHeight: Int, videoEnabled: Bool, enableDataChannel: Bool, streamId: String) {
public convenience init(remoteVideoView: RTCVideoRenderer?, localVideoView: RTCVideoRenderer?, delegate: WebRTCClientDelegate, cameraPosition: AVCaptureDevice.Position, targetWidth: Int, targetHeight: Int, videoEnabled: Bool, enableDataChannel: Bool, streamId: String) {
self.init(remoteVideoView: remoteVideoView, localVideoView: localVideoView, delegate: delegate,
mode: mode, cameraPosition: cameraPosition, targetWidth: targetWidth, targetHeight: targetHeight, videoEnabled: true, enableDataChannel:false, useExternalCameraSource: false, streamId: streamId)
cameraPosition: cameraPosition, targetWidth: targetWidth, targetHeight: targetHeight, videoEnabled: true, enableDataChannel:false, useExternalCameraSource: false, streamId: streamId)
}

public convenience init(remoteVideoView: RTCVideoRenderer?, localVideoView: RTCVideoRenderer?, delegate: WebRTCClientDelegate, mode: AntMediaClientMode, cameraPosition: AVCaptureDevice.Position, targetWidth: Int, targetHeight: Int, videoEnabled: Bool, enableDataChannel: Bool, useExternalCameraSource: Bool, externalAudio: Bool = false, externalVideoCapture: Bool = false, cameraSourceFPS: Int = 30, streamId: String,
public convenience init(remoteVideoView: RTCVideoRenderer?, localVideoView: RTCVideoRenderer?, delegate: WebRTCClientDelegate, cameraPosition: AVCaptureDevice.Position, targetWidth: Int, targetHeight: Int, videoEnabled: Bool, enableDataChannel: Bool, useExternalCameraSource: Bool, externalAudio: Bool = false, externalVideoCapture: Bool = false, cameraSourceFPS: Int = 30, streamId: String,
degradationPreference: RTCDegradationPreference = RTCDegradationPreference.maintainResolution) {
self.init(remoteVideoView: remoteVideoView, localVideoView: localVideoView, delegate: delegate, externalAudio: externalAudio)
self.cameraPosition = cameraPosition
Expand All @@ -107,12 +107,10 @@ class WebRTCClient: NSObject {
self.cameraSourceFPS = cameraSourceFPS;
self.streamId = streamId;
self.degradationPreference = degradationPreference

if (mode != .play) {
self.addLocalMediaStream()
}
}



public func externalVideoCapture(externalVideoCapture: Bool) {
self.externalVideoCapture = externalVideoCapture;
}
Expand Down Expand Up @@ -412,7 +410,7 @@ class WebRTCClient: NSObject {
}


private func addLocalMediaStream() -> Bool {
public func addLocalMediaStream() -> Bool {


AntMediaClient.printf("Add local media streams")
Expand Down Expand Up @@ -444,6 +442,16 @@ class WebRTCClient: NSObject {
return true
}

public func getLocalVideoTrack() -> RTCVideoTrack {
return self.localVideoTrack;
}

public func getLocalAudioTrack() -> RTCAudioTrack {
return self.localAudioTrack;
}



public func setDegradationPreference(degradationPreference:RTCDegradationPreference) {
self.degradationPreference = degradationPreference
}
Expand Down
Loading