Skip to content

Commit

Permalink
Merge branch 'master' into dev/3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Dec 17, 2020
2 parents da3222a + 12e2561 commit 561b3fd
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions RtcSurfaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@ import UIKit
import AgoraRtcKit

class RtcSurfaceView: UIView {
private lazy var canvas: AgoraRtcVideoCanvas = {
var canvas = AgoraRtcVideoCanvas()
canvas.view = self
return canvas
}()
private var surface: UIView
private var canvas: AgoraRtcVideoCanvas
private weak var channel: AgoraRtcChannel?

func destroy() {

override init(frame: CGRect) {
surface = UIView(frame: frame)
canvas = AgoraRtcVideoCanvas()
canvas.view = surface
super.init(frame: frame)
addSubview(surface)
addObserver(self, forKeyPath: "frame", options: .new, context: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

deinit {
canvas.view = nil
removeObserver(self, forKeyPath: "frame", context: nil)
}

func setData(_ engine: AgoraRtcEngineKit, _ channel: AgoraRtcChannel?, _ uid: Int) {
Expand All @@ -45,6 +56,10 @@ class RtcSurfaceView: UIView {
}

private func setupVideoCanvas(_ engine: AgoraRtcEngineKit) {
subviews.forEach { $0.removeFromSuperview() }
surface = UIView(frame: self.frame)
addSubview(surface)
canvas.view = surface
if canvas.uid == 0 {
engine.setupLocalVideo(canvas)
} else {
Expand Down Expand Up @@ -73,4 +88,10 @@ class RtcSurfaceView: UIView {
}
}
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "frame" {
surface.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height)
}
}
}

0 comments on commit 561b3fd

Please sign in to comment.