Skip to content

Commit

Permalink
Merge pull request #5 from apivideo/feat/new-events
Browse files Browse the repository at this point in the history
Feat/new events
  • Loading branch information
RomainPetit1 authored Nov 9, 2021
2 parents 97f8543 + a7cc423 commit 0b5122e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
27 changes: 17 additions & 10 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
Copyright 2021 Api.video
MIT License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Copyright (c) 2021 api.video

http://www.apache.org/licenses/LICENSE-2.0
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 2 additions & 2 deletions LiveStreamIos.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Pod::Spec.new do |spec|


spec.name = "LiveStreamIos"
spec.version = "0.0.3"
spec.version = "0.0.4"
spec.summary = "a native iOS library from api.video"


Expand All @@ -17,7 +17,7 @@ Pod::Spec.new do |spec|



spec.license = "Apache License, Version 2.0"
spec.license = "MIT License Copyright (c) 2021 api.video"

spec.author = { "Ecosystem Team" => "[email protected]" }
spec.social_media_url = "https://twitter.com/api_video"
Expand Down
29 changes: 14 additions & 15 deletions LiveStreamIos/ApiVideoLiveStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,18 @@ public class ApiVideoLiveStream{

private var ratioConstraint: NSLayoutConstraint?
private var mthkView: MTHKView?

private var livestreamkey: String?
private var rtmpServerUrl: String?

private var rtmpStream: RTMPStream
private var rtmpConnection = RTMPConnection()
private var currentPosition: AVCaptureDevice.Position = .back
private var retryCount: Int = 0
private static let maxRetryCount: Int = 5

public var onStatusChange: ((String) -> ())? = nil {
didSet{
}
}


public var onConnectionSuccess: (() -> ())? = nil
public var onConnectionFailed: ((String) -> ())? = nil
public var onDisconnect: (() -> ())? = nil

public var videoResolution: Resolutions = Resolutions.RESOLUTION_720{
didSet{
updateRatioConstraint()
Expand Down Expand Up @@ -132,7 +129,6 @@ public class ApiVideoLiveStream{
}

rtmpStream = RTMPStream(connection: rtmpConnection)

NotificationCenter.default.addObserver(self, selector: #selector(on(_:)), name: UIDevice.orientationDidChangeNotification, object: nil)
DispatchQueue.main.async {
if let orientation = DeviceUtil.videoOrientation(by: UIApplication.shared.statusBarOrientation) {
Expand All @@ -150,7 +146,6 @@ public class ApiVideoLiveStream{
prepareCamera()
setCaptureSettings()
setAudioSettings()

if (view != nil) {
mthkView = MTHKView(frame: view!.bounds)
mthkView!.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -174,7 +169,6 @@ public class ApiVideoLiveStream{
])
}


}

private func updateRatioConstraint() {
Expand All @@ -195,7 +189,6 @@ public class ApiVideoLiveStream{
}
}


public func startLiveStreamFlux(liveStreamKey: String, rtmpServerUrl: String?) -> Void{
self.livestreamkey = liveStreamKey
self.rtmpServerUrl = rtmpServerUrl
Expand All @@ -208,6 +201,9 @@ public class ApiVideoLiveStream{
}

public func stopLiveStreamFlux() -> Void{
if (self.onDisconnect != nil) {
self.onDisconnect!()
}
rtmpConnection.close()
rtmpConnection.removeEventListener(.rtmpStatus, selector: #selector(rtmpStatusHandler), observer: self)
rtmpConnection.removeEventListener(.ioError, selector: #selector(rtmpErrorHandler), observer: self)
Expand Down Expand Up @@ -244,14 +240,17 @@ public class ApiVideoLiveStream{
guard let data: ASObject = e.data as? ASObject, let code: String = data["code"] as? String else {
return
}
if (self.onStatusChange != nil) {
self.onStatusChange!(code)
}
switch code {
case RTMPConnection.Code.connectSuccess.rawValue:
if (self.onConnectionSuccess != nil) {
self.onConnectionSuccess!()
}
retryCount = 0
rtmpStream.publish(self.livestreamkey!)
case RTMPConnection.Code.connectFailed.rawValue, RTMPConnection.Code.connectClosed.rawValue:
if (self.onConnectionFailed != nil) {
self.onConnectionFailed!(code)
}
guard retryCount <= ApiVideoLiveStream.maxRetryCount else {
return
}
Expand Down

0 comments on commit 0b5122e

Please sign in to comment.