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

Sample code to check dimensions - Temp #207

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 26 additions & 11 deletions Basic-Video-Chat/Basic-Video-Chat/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ class ViewController: UIViewController {
return OTSession(apiKey: kApiKey, sessionId: kSessionId, delegate: self)!
}()

lazy var publisher: OTPublisher = {
let settings = OTPublisherSettings()
settings.name = UIDevice.current.name
return OTPublisher(delegate: self, settings: settings)!
}()

var publisher: OTPublisher?
var subscriber: OTSubscriber?
var timer: Timer?

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -63,10 +59,13 @@ class ViewController: UIViewController {
defer {
processError(error)
}
let settings = OTPublisherSettings()
settings.name = UIDevice.current.name
publisher = OTPublisher(delegate: self, settings: settings)!

session.publish(publisher!, error: &error)

session.publish(publisher, error: &error)

if let pubView = publisher.view {
if let pubView = publisher!.view {
pubView.frame = CGRect(x: 0, y: 0, width: kWidgetWidth, height: kWidgetHeight)
view.addSubview(pubView)
}
Expand Down Expand Up @@ -94,7 +93,10 @@ class ViewController: UIViewController {
}

fileprivate func cleanupPublisher() {
publisher.view?.removeFromSuperview()
if let publisher = publisher {
publisher.view?.removeFromSuperview()
}

}

fileprivate func processError(_ error: OTError?) {
Expand Down Expand Up @@ -142,7 +144,20 @@ extension ViewController: OTSessionDelegate {
// MARK: - OTPublisher delegate callbacks
extension ViewController: OTPublisherDelegate {
func publisher(_ publisher: OTPublisherKit, streamCreated stream: OTStream) {
print("Publishing")
self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { _ in
if self.publisher!.videoCapture?.isCaptureStarted() == true ,
AVCaptureDevice.authorizationStatus(for: .video) == .authorized
{
print("Later - video stream w = \(stream.videoDimensions.width)")
}
})

if self.publisher!.videoCapture?.isCaptureStarted() == true ,
AVCaptureDevice.authorizationStatus(for: .video) == .authorized {
print("Initial (valid) - video stream w = \(stream.videoDimensions.width)")
} else {
print("Capturer not yet started or camera permissions not given.")
}
}

func publisher(_ publisher: OTPublisherKit, streamDestroyed stream: OTStream) {
Expand Down