Skip to content

Commit

Permalink
Merge branch 'master' into update-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mekya authored Dec 2, 2023
2 parents ac5a02c + cb4e6bf commit b2c8dfd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 91 deletions.
18 changes: 0 additions & 18 deletions WebRTC-Sample-App/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,6 @@ WebRTC Live Streaming</string>
<constraint firstAttribute="width" constant="90" id="tMd-w9-0ro"/>
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zuA-ym-oro">
<rect key="frame" x="140" y="592" width="90" height="35"/>
<color key="backgroundColor" red="0.86666666670000003" green="0.13725490200000001" blue="0.12941176469999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="64" id="Lq3-hn-By8" userLabel="width = 90"/>
<constraint firstAttribute="height" constant="35" id="tVl-pt-owp"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue-Bold" family="Helvetica Neue" pointSize="18"/>
<state key="normal" title="Publish">
<color key="titleColor" red="0.96862745100000003" green="0.96862745100000003" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="joinButtonTapped:" destination="E4n-9I-LrE" eventType="touchUpInside" id="mo0-sJ-qQZ"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="dqn-Tz-Jj5"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
Expand All @@ -222,14 +207,12 @@ WebRTC Live Streaming</string>
<constraint firstAttribute="centerX" secondItem="zBK-Om-nWf" secondAttribute="trailing" id="E4k-YY-Q71" userLabel="centerX = Remote View1.trailing"/>
<constraint firstItem="dqn-Tz-Jj5" firstAttribute="bottom" secondItem="Zwp-DO-5T7" secondAttribute="bottom" constant="20" id="Fpc-aE-wjW" userLabel="Safe Area.bottom = Local View.bottom"/>
<constraint firstItem="LXN-aK-Wm3" firstAttribute="top" secondItem="qPy-8E-T6N" secondAttribute="top" id="I4Q-cM-hh1"/>
<constraint firstItem="zuA-ym-oro" firstAttribute="bottom" secondItem="Zwp-DO-5T7" secondAttribute="bottom" id="PAI-ea-SqS"/>
<constraint firstItem="LXN-aK-Wm3" firstAttribute="leading" secondItem="qPy-8E-T6N" secondAttribute="trailing" id="Q0S-IU-LsM"/>
<constraint firstItem="qPy-8E-T6N" firstAttribute="centerX" secondItem="zBK-Om-nWf" secondAttribute="centerX" id="QRh-rT-aK6"/>
<constraint firstItem="zBK-Om-nWf" firstAttribute="leading" secondItem="CM5-Lj-3ty" secondAttribute="leadingMargin" id="S5L-m5-Yrb"/>
<constraint firstAttribute="centerY" secondItem="PKz-rN-me0" secondAttribute="bottom" id="Um9-Ar-5G8"/>
<constraint firstItem="qPy-8E-T6N" firstAttribute="top" secondItem="zBK-Om-nWf" secondAttribute="bottom" id="gap-oY-sdl"/>
<constraint firstItem="zBK-Om-nWf" firstAttribute="trailing" secondItem="qPy-8E-T6N" secondAttribute="trailing" id="jgL-N3-IEF"/>
<constraint firstItem="zuA-ym-oro" firstAttribute="centerX" secondItem="CM5-Lj-3ty" secondAttribute="centerX" id="kYm-10-JHD"/>
<constraint firstItem="PKz-rN-me0" firstAttribute="leading" secondItem="zBK-Om-nWf" secondAttribute="trailing" constant="11.5" id="kqQ-65-DXL" userLabel="Remote View1.leading = Remote View0.trailing"/>
<constraint firstItem="dqn-Tz-Jj5" firstAttribute="trailing" secondItem="PKz-rN-me0" secondAttribute="trailing" constant="8" id="m4p-r2-kiA" userLabel="Safe Area.trailing = Remote View2.trailing"/>
<constraint firstItem="qPy-8E-T6N" firstAttribute="bottom" secondItem="Zwp-DO-5T7" secondAttribute="bottom" id="m71-fp-qJf"/>
Expand All @@ -241,7 +224,6 @@ WebRTC Live Streaming</string>
</view>
<navigationItem key="navigationItem" id="l7b-W5-MXv"/>
<connections>
<outlet property="joinButton" destination="zuA-ym-oro" id="a5B-gq-wgo"/>
<outlet property="localView" destination="Zwp-DO-5T7" id="ada-FF-Y7z"/>
<outlet property="remoteView0" destination="zBK-Om-nWf" id="pbU-sW-7CT"/>
<outlet property="remoteView1" destination="PKz-rN-me0" id="Uz2-bp-z9s"/>
Expand Down
27 changes: 3 additions & 24 deletions WebRTC-Sample-App/ConferenceViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ open class ConferenceViewController: UIViewController , AVCaptureVideoDataOutput
@IBOutlet var remoteView2: UIView!
@IBOutlet var remoteView3: UIView!

@IBOutlet weak var joinButton: UIButton!
var remoteViews:[RTCVideoRenderer] = []

//keeps which remoteView renders which track according to the index
Expand All @@ -37,24 +36,7 @@ open class ConferenceViewController: UIViewController , AVCaptureVideoDataOutput

var conferenceClient: AntMediaClient?;
var playing = false

@IBAction func joinButtonTapped(_ sender: Any) {
AntMediaClient.printf("button tapped");
publishStream = !publishStream;
var title:String;

//TODO: don't use flag(publishStream), use more trusted info @mekya
if (publishStream) {
self.conferenceClient?.publish(streamId: publisherStreamId)
title = "Stop";
}
else {
self.conferenceClient?.stop(streamId:publisherStreamId);
title = "Publish"
}
joinButton.setTitle(title, for: .normal);
}


func initRenderer(view: UIView)
{
#if arch(arm64)
Expand Down Expand Up @@ -135,16 +117,13 @@ extension ConferenceViewController: AntMediaClientDelegate

AntMediaClient.printf("stream id to publish \(streamId)")
self.publisherStreamId = streamId;
//opens the camera
self.conferenceClient?.initPeerConnection(streamId: streamId, mode: AntMediaClientMode.publish)


//if you can mute and close the camera, you can do that here
//self.conferenceClient?.setAudioTrack(enableTrack: false)
//self.conferenceClient?.setVideoTrack(enableTrack: false)


//if you want to publish immediately, uncomment the line below and just call the method below
//self.conferenceClient?.publish(streamId: self.publisherStreamId)
self.conferenceClient?.publish(streamId: self.publisherStreamId)
}

}
Expand Down

This file was deleted.

39 changes: 12 additions & 27 deletions WebRTCiOSSDK/api/AntMediaClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,9 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {

private var videoEnable: Bool = true
private var audioEnable: Bool = true

private var multiPeer: Bool = false


private var enableDataChannel: Bool = true

private var multiPeerStreamId: String?


//Screen capture of the app's screen.
private var useExternalCameraSource: Bool = false

Expand All @@ -118,11 +114,6 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
private var externalVideoCapture: Bool = false;

private var cameraSourceFPS: Int = 30;

/*
This peer mode is used in multi peer streaming
*/
private var multiPeerMode: String = "play"

var pingTimer: Timer?

Expand All @@ -138,14 +129,12 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
var video:Bool?
var audio:Bool?
var mode:String?
var multiPeer:Bool?
var mainTrack:String?
var trackList:[String]
}

public override init() {
self.multiPeerStreamId = nil
}
}

public func setOptions(url: String, streamId: String, token: String = "", mode: AntMediaClientMode = .join, enableDataChannel: Bool = false, useExternalCameraSource: Bool = false) {
self.wsUrl = url
Expand Down Expand Up @@ -187,11 +176,6 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
self.webRTCClientMap[self.getPublisherStreamId()]?.setMaxVideoBps(maxVideoBps: videoBitratePerSecond)
}

public func setMultiPeerMode(enable: Bool, mode: String) {
self.multiPeer = enable
self.multiPeerMode = mode;
}

public func setVideoEnable( enable: Bool) {
self.videoEnable = enable
}
Expand Down Expand Up @@ -222,7 +206,7 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
AntMediaClient.printf("Disable track id is not set \(String(describing: self.disableTrackId))");
}

let handShakeMesage = HandshakeMessage(command: mode.getName(), streamId: streamId, token: token, video: self.videoEnable, audio:self.audioEnable, multiPeer: self.multiPeer && self.multiPeerStreamId != nil ? true : false, mainTrack: self.mainTrackId, trackList: trackList)
let handShakeMesage = HandshakeMessage(command: mode.getName(), streamId: streamId, token: token, video: self.videoEnable, audio:self.audioEnable, mainTrack: self.mainTrackId, trackList: trackList)

let json = try! JSONEncoder().encode(handShakeMesage)
return String(data: json, encoding: .utf8)!
Expand Down Expand Up @@ -539,7 +523,7 @@ 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, multiPeerActive: self.multiPeer, 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, 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]?.setToken(token)

Expand Down Expand Up @@ -983,11 +967,6 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
let streamId = message[STREAM_ID] as! String
self.onTakeCandidate(message: message, streamId: streamId)
break
case "connectWithNewId":
self.multiPeerStreamId = message["streamId"] as? String
let jsonString = getHandshakeMessage(streamId: self.getStreamId(), mode: AntMediaClientMode.join)
webSocket?.write(string: jsonString)
break
case STREAM_INFORMATION_COMMAND:
AntMediaClient.printf("stream information command")
var streamInformations: [StreamInformation] = [];
Expand Down Expand Up @@ -1084,6 +1063,7 @@ open class AntMediaClient: NSObject, AntMediaClientProtocol {
self.delegate?.clientHasError(AntMediaError.localized(definition))
break
default:
AntMediaClient.printf("Unknown message received -> \(message)");
break
}
}
Expand Down Expand Up @@ -1262,7 +1242,12 @@ extension AntMediaClient: WebRTCClientDelegate {

if let eventType = json?[EVENT_TYPE] {
//event happened
self.delegate?.eventHappened(streamId:json?[STREAM_ID] as! String, eventType:eventType as! String);
if let incomingStreamId = json?[STREAM_ID] {
self.delegate?.eventHappened(streamId:incomingStreamId as! String , eventType:eventType as! String);
}
else {
AntMediaClient.printf("Incoming message does not have streamId:\(json)")
}
}
else {
self.delegate?.dataReceivedFromDataChannel(streamId: streamId, data: data.data, binary: data.isBinary);
Expand Down
2 changes: 1 addition & 1 deletion WebRTCiOSSDK/api/AntMediaClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public extension AntMediaClientDelegate {
}

func eventHappened(streamId: String, eventType: String) {
AntMediaClient.printf("Event\(eventType) happened in stream:\(streamId) ")
AntMediaClient.printf("Event: \(eventType) happened in stream: \(streamId) ")
}

func clientDidDisconnect(_ message: String) {
Expand Down
12 changes: 5 additions & 7 deletions WebRTCiOSSDK/api/webrtc/WebRTCClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class WebRTCClient: NSObject {
If it's true, it does not open the local camera. When it's set to true, it can record the screen in-app or you can give external frames through your application or BroadcastExtension. If you give external frames or through BroadcastExtension, you need to set the externalVideoCapture to true as well
*/
private var useExternalCameraSource: Bool = false;
private var mode: AntMediaClientMode = AntMediaClientMode.join

private var enableDataChannel: Bool = false;

Expand Down Expand Up @@ -86,16 +85,15 @@ class WebRTCClient: NSObject {

public convenience init(remoteVideoView: RTCVideoRenderer?, localVideoView: RTCVideoRenderer?, delegate: WebRTCClientDelegate, mode: AntMediaClientMode, 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, multiPeerActive:false, enableDataChannel:false, streamId: streamId)
mode: mode, 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, multiPeerActive: Bool, enableDataChannel: Bool, streamId: String) {
public convenience init(remoteVideoView: RTCVideoRenderer?, localVideoView: RTCVideoRenderer?, delegate: WebRTCClientDelegate, mode: AntMediaClientMode, 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, multiPeerActive:false, enableDataChannel:false, useExternalCameraSource: false, streamId: streamId)
mode: mode, 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, multiPeerActive: 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, 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) {
self.init(remoteVideoView: remoteVideoView, localVideoView: localVideoView, delegate: delegate, externalAudio: externalAudio)
self.mode = mode
self.cameraPosition = cameraPosition
self.targetWidth = targetWidth
self.targetHeight = targetHeight
Expand All @@ -106,7 +104,7 @@ class WebRTCClient: NSObject {
self.cameraSourceFPS = cameraSourceFPS;
self.streamId = streamId;

if (self.mode != .play && !multiPeerActive) {
if (mode != .play) {
self.addLocalMediaStream()
}
}
Expand Down

0 comments on commit b2c8dfd

Please sign in to comment.