Skip to content

Commit

Permalink
Merge pull request #179 from saghul/stacked-uiview
Browse files Browse the repository at this point in the history
Fix positioning video elements using z-index (thanks to @1N50MN14 and @saghul)
  • Loading branch information
ibc committed Jun 14, 2016
2 parents 25a6944 + 5b6a180 commit 01d58ce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/videoCSS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ Supported CSS properties are:
* `z-index`: Useful to place a video on top of another video.
* [`object-fit`](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit)
* `-webkit-transform: scaleX(-1)`: Useful for horizontal mirror effect.

**Note**: if the specified z-index is < 0 (that, is, the video elements will be positioned "behind" the web view), you should specify the
`<body>` `background-color` as `transparent` so the video element will be seen through the web view. This makes it possible to position
HTML elements on top of the native video elements.
11 changes: 8 additions & 3 deletions src/PluginMediaStreamRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ class PluginMediaStreamRenderer : NSObject, RTCEAGLVideoViewDelegate {
// It's placed over the elementView.
self.videoView = RTCEAGLVideoView()

self.webView.addSubview(self.elementView)
self.webView.bringSubviewToFront(self.elementView)

self.elementView.userInteractionEnabled = false
self.elementView.hidden = true
self.elementView.backgroundColor = UIColor.blackColor()
self.elementView.addSubview(self.videoView)
self.elementView.layer.masksToBounds = true

self.videoView.userInteractionEnabled = false

// Place the video element view inside the WebView's superview
self.webView.superview?.addSubview(self.elementView)
}


Expand Down Expand Up @@ -188,6 +188,11 @@ class PluginMediaStreamRenderer : NSObject, RTCEAGLVideoViewDelegate {
self.elementView.alpha = CGFloat(opacity)
self.elementView.layer.zPosition = CGFloat(zIndex)

// if the zIndex is 0 (the default) bring the view to the top, last one wins
if zIndex == 0 {
self.webView.superview?.bringSubviewToFront(self.elementView)
}

if !mirrored {
self.elementView.transform = CGAffineTransformIdentity
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/iosrtcPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class iosrtcPlugin : CDVPlugin {
override func pluginInitialize() {
NSLog("iosrtcPlugin#pluginInitialize()")

// Make the web view transparent
self.webView!.opaque = false
self.webView!.backgroundColor = UIColor.clearColor()

pluginMediaStreams = [:]
pluginMediaStreamTracks = [:]
pluginMediaStreamRenderers = [:]
Expand Down

0 comments on commit 01d58ce

Please sign in to comment.