|
| 1 | +# HLSCachingReverseProxyServer |
| 2 | + |
| 3 | + |
| 4 | +[](https://cocoapods.org/pods/HLSCachingReverseProxyServer) |
| 5 | +[](https://github.com/StyleShare/HLSCachingReverseProxyServer/actions) |
| 6 | +[](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