Skip to content

Commit 088d959

Browse files
committed
Initial commit :)
0 parents  commit 088d959

File tree

13 files changed

+691
-0
lines changed

13 files changed

+691
-0
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: macOS-latest
12+
env:
13+
WORKSPACE: HLSCachingReverseProxyServer.xcworkspace
14+
SCHEME: HLSCachingReverseProxyServer-Package
15+
SDK: iphonesimulator13.1
16+
DESTINATION: platform=iOS Simulator,name=iPhone 11 Pro,OS=13.1
17+
18+
steps:
19+
- uses: actions/checkout@v1
20+
21+
- name: Generate Xcode Project
22+
run: make project
23+
24+
- name: Build and Test
25+
run: |
26+
set -o pipefail && xcodebuild clean build test \
27+
-workspace "$WORKSPACE" \
28+
-scheme "$SCHEME" \
29+
-sdk "$SDK" \
30+
-destination "$DESTINATION" \
31+
-configuration Debug \
32+
-enableCodeCoverage YES \
33+
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty -c
34+
35+
- name: Upload Code Coverage
36+
run: |
37+
bash <(curl -s https://codecov.io/bash) \
38+
-X xcodeplist \
39+
-J HLSCachingReverseProxyServer \
40+
-t "$CODECOV_TOKEN"
41+
env:
42+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
/*.xcworkspace
6+
**/xcuserdata
7+
**/xcshareddata
8+
Pods/
9+
Carthage/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Pod::Spec.new do |s|
2+
s.name = "HLSCachingReverseProxyServer"
3+
s.version = "0.1.0"
4+
s.summary = "A simple local reverse proxy server for HLS segment cache"
5+
s.homepage = "https://github.com/StyleShare/HLSCachingReverseProxyServer"
6+
s.license = { :type => "MIT", :file => "LICENSE" }
7+
s.author = { "Suyeol Jeon" => "[email protected]" }
8+
s.source = { :git => "https://github.com/StyleShare/HLSCachingReverseProxyServer.git",
9+
:tag => s.version.to_s }
10+
s.source_files = "Sources/**/*.{swift,h,m}"
11+
s.frameworks = "Foundation"
12+
s.swift_version = "5.1"
13+
14+
s.dependency "GCDWebServer", "~> 3.5"
15+
s.dependency "PINCache", ">= 3.0.1-beta.3"
16+
17+
s.ios.deployment_target = "8.0"
18+
s.osx.deployment_target = "10.11"
19+
s.tvos.deployment_target = "9.0"
20+
end

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Suyeol Jeon (xoul.kr)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
project: clean
2+
swift package generate-xcodeproj --enable-code-coverage
3+
ruby -e "require 'xcodeproj'; Xcodeproj::Project.open('HLSCachingReverseProxyServer.xcodeproj').save" || true
4+
pod install
5+
6+
clean:
7+
rm -rf Pods

Package.resolved

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// swift-tools-version:5.1
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "HLSCachingReverseProxyServer",
7+
platforms: [
8+
.macOS(.v10_11), .iOS(.v8), .tvOS(.v9)
9+
],
10+
products: [
11+
.library(name: "HLSCachingReverseProxyServer", targets: ["HLSCachingReverseProxyServer"]),
12+
],
13+
dependencies: [
14+
.package(url: "https://github.com/Quick/Nimble.git", .revision("50c3f82c3d23af1d6e710226015b3e94b5265f71")),
15+
.package(url: "https://github.com/devxoul/SafeCollection.git", .upToNextMajor(from: "3.1.0")),
16+
],
17+
targets: [
18+
.target(name: "HLSCachingReverseProxyServer"),
19+
.testTarget(name: "HLSCachingReverseProxyServerTests", dependencies: ["HLSCachingReverseProxyServer", "Nimble", "SafeCollection"]),
20+
]
21+
)

Podfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use_frameworks!
2+
inhibit_all_warnings!
3+
4+
target 'HLSCachingReverseProxyServer' do
5+
platform :ios, '8.0'
6+
7+
pod 'GCDWebServer', '~> 3.5'
8+
pod 'PINCache', '>= 3.0.1-beta.3'
9+
10+
target 'HLSCachingReverseProxyServerTests' do
11+
end
12+
end

Podfile.lock

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
PODS:
2+
- GCDWebServer (3.5.3):
3+
- GCDWebServer/Core (= 3.5.3)
4+
- GCDWebServer/Core (3.5.3)
5+
- PINCache (3.0.1-beta.8):
6+
- PINCache/Arc-exception-safe (= 3.0.1-beta.8)
7+
- PINCache/Core (= 3.0.1-beta.8)
8+
- PINCache/Arc-exception-safe (3.0.1-beta.8):
9+
- PINCache/Core
10+
- PINCache/Core (3.0.1-beta.8):
11+
- PINOperation (~> 1.1.1)
12+
- PINOperation (1.1.2)
13+
14+
DEPENDENCIES:
15+
- GCDWebServer (~> 3.5)
16+
- PINCache (>= 3.0.1-beta.3)
17+
18+
SPEC REPOS:
19+
trunk:
20+
- GCDWebServer
21+
- PINCache
22+
- PINOperation
23+
24+
SPEC CHECKSUMS:
25+
GCDWebServer: c0ab22c73e1b84f358d1e2f74bf6afd1c60829f2
26+
PINCache: 534fd41d358d828dfdf227a0d327f3673a65e20b
27+
PINOperation: 24b774353ca248fcf87d67b2d61eef42087c125a
28+
29+
PODFILE CHECKSUM: eccdba0298d185d28e91ef914560e6ab6cbd4b13
30+
31+
COCOAPODS: 1.8.3

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# HLSCachingReverseProxyServer
2+
3+
![Swift](https://img.shields.io/badge/Swift-5.1-orange.svg)
4+
[![CocoaPods](http://img.shields.io/cocoapods/v/HLSCachingReverseProxyServer.svg)](https://cocoapods.org/pods/HLSCachingReverseProxyServer)
5+
[![Build Status](https://github.com/StyleShare/HLSCachingReverseProxyServer/workflows/CI/badge.svg)](https://github.com/StyleShare/HLSCachingReverseProxyServer/actions)
6+
[![CodeCov](https://img.shields.io/codecov/c/github/StyleShare/HLSCachingReverseProxyServer.svg)](https://codecov.io/gh/StyleShare/HLSCachingReverseProxyServer)
7+
8+
A simple local reverse proxy server for HLS segment cache.
9+
10+
## Concept
11+
12+
1. **User** sets a reverse proxy url instead of original url.
13+
```diff
14+
- https://example.com/vod.m3u8
15+
+ http://127.0.0.1:8080/vod.m3u8?__hls_origin_url=https://example.com/vod.m3u8
16+
```
17+
2. **AVAsset** requests a playlist(`.m3u8`) to the local reverse proxy server.
18+
3. **Reverse proxy server** fetches the original playlist and replaces all URIs to point the local reverse proxy server.
19+
```diff
20+
#EXTM3U
21+
#EXTINF:12.000,
22+
- vod_00001.ts
23+
+ http://127.0.0.1:8080/vod.m3u8?__hls_origin_url=https://example.com/vod_00001.ts
24+
#EXTINF:12.000,
25+
- vod_00002.ts
26+
+ http://127.0.0.1:8080/vod.m3u8?__hls_origin_url=https://example.com/vod_00002.ts
27+
#EXTINF:12.000,
28+
- vod_00003.ts
29+
+ http://127.0.0.1:8080/vod.m3u8?__hls_origin_url=https://example.com/vod_00003.ts
30+
```
31+
4. **AVAsset** requests segments(`.ts`) to the local server.
32+
5. **Reverse proxy server** fetches the original segment and caches. Next time the server will return the cached data for the same segment.
33+
34+
## Usage
35+
36+
```swift
37+
let server = HLSCachingReverseProxyServer()
38+
server.start(port: 8080)
39+
40+
let playlistURL = URL(string: "http://devstreaming.apple.com/videos/wwdc/2016/102w0bsn0ge83qfv7za/102/0640/0640.m3u8")!
41+
let url = server.reverseProxyURL(from: playlistURL)!
42+
let playerItem = AVPlayerItem(url: url)
43+
self.player.replaceCurrentItem(with: playerItem)
44+
```
45+
46+
## Dependencies
47+
48+
* [GCDWebServer](https://github.com/swisspol/GCDWebServer)
49+
* [PINCache](https://github.com/pinterest/PINCache)
50+
51+
## Installation
52+
53+
**Podfile**
54+
55+
```ruby
56+
pod 'HLSCachingReverseProxyServer'
57+
```
58+
59+
## Development
60+
61+
```console
62+
$ make project
63+
$ open HLSCachingReverseProxyServer.xcworkspace
64+
```
65+
66+
## License
67+
68+
HLSCachingReverseProxyServer is under MIT license. See the [LICENSE](LICENSE) for more info.

0 commit comments

Comments
 (0)