Git Product home page Git Product logo

live's Introduction

This project is to demonstrate how to build a live broadcast app. It include these features:

  • Create a room to broadcast your live stream
  • Join a room to watch the live
  • Send likes, gifts, and comments

image  image

Introduction

How to run

1. Nginx RTMP server

You need to can set up your own rtmp server, the guidance can be found here:

2. WebSocket server

Just go to the live-server folder, run npm install, then start the server by node app.js

3. iOS client

Go to the live-ios folder, run pod install(must use cocoapods 0.39.0)

In Config.swift, update the server url:

struct Config {
    static var rtmpPushUrl = "rtmp://139.196.179.230/mytv/"
    static var rtmpPlayUrl = "rtmp://139.196.179.230/mytv/"
    static var serverUrl = "http://139.196.179.230:3000"
}

The app can also run on a simulator, but to broadcast, you need to run it on a real device.

Tutorial

1. Live streaming

The basic live streaming flow is:

broadcaster -> rtmp -> media server -> cdn -> rtmp or hls -> audience

For the simplest case, we don't need a cdn server, then the flow will be:

broadcaster -> rtmp -> media server -> rtmp or hls -> audience

That is, the boadcaster push the live stream using the RTMP protocal to a media server, the audience pull the stream from the server using RTMP or HLS protocal.

Some explaination for RTMP and HLS:

  • RTMP: RTMP is used to stream audio, video or data and is originally a proprietary protocol introduced by Macromedia (owned by Adobe). The protocol is TCP-based and offers therefore persistent connections. In short, RTMP encapsulates MP3/AAC audio and MP4/FLV video multimedia streams.

  • HLS: HTTP Live Streaming is known as HLS. As the name implies, it is the media streaming communications protocol based on HTTP; developed by Apple as part of their QuickTime, Safari, OS X, and iOS products. How does it work? It breaks the overall stream into a sequence of small HTTP-based files (.ts: Transport Stream). These transport stream files are indexed in the file .m3u8. It is required to download first the .m3u8 playlist to play a live stream.

For the media server, there are serveral choices:

  • Adobe media server
  • Red5
  • Nginx RTMP module
  • crtmpserver

After setting up the server, you can test it using ffmpeg(install it by brew install ffmpeg).

  • push stream
ffmpeg -f avfoundation -framerate 30  -i "1:0" -f flv rtmp://server-url

p.s. Lots of live stream cloud already covers the media server and cdn parts. You just need to push/pull the stream from it.

2. iOS RTMP libs

There are serveral open source projects supporting RTMP, this project uses:

You can find the usage of these libs in their project pages.

3. Websocket server

This project uses socket.io to handle the client-server communication, the logic is very simple, on the server side:

var rooms = {}

io.on('connection', function(socket) {

  socket.on('create_room', function(room) {
    var roomKey = room.key
    rooms[roomKey] = room
    socket.roomKey = roomKey
    socket.join(roomKey)
  })

  socket.on('close_room', function(roomKey) {
    delete rooms[roomKey]
  })

  socket.on('disconnect', function() {
    if (socket.roomKey) {
      delete rooms[socket.roomKey]
    }
  })

  socket.on('join_room', function(roomKey) {
    socket.join(roomKey)
  })

  socket.on('upvote', function(roomKey) {
    io.to(roomKey).emit('upvote')
  })

  socket.on('gift', function(data) {
    io.to(data.roomKey).emit('gift', data)
  })
  
})

On the client side, it uses the socket.io swift client(https://github.com/socketio/socket.io-client-swift), the logic is also simple:

create, join, or close a room:

socket.on("connect") { data, ack in
    self.socket.emit("create_room", self.room)
}

socket.on("connect") { data, ack in
    self.socket.emit("join_room", self.room.key)
}

socket.disconnect()

publish likes and comments events:

socket.emit("upvote", room.key)
socket.emit("comment", [
    "roomKey": room.key,
    "text": text
])

listen likes and comments events:

socket.on("upvote") { data, ack in
    self.emitterView.emitImage(R.image.heart()!)
}
        
socket.on("comment") { data, ack in
    let comment = Comment(dict: data[0] as! [String: AnyObject])
    self.comments.append(comment)
    self.tableView.reloadData()
}

live's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

live's Issues

IJK player needs update

Hi,

I had two issues when I used this:

  1. A stream video to B. A restarts streams. B can only see video no sound.
  2. No ARMV6 (Iphone 5, 5s) support.

I solved both problems by getting the IJK player from original github and recompiling it.

Where do I get Config urls?

struct Config {

static var rtmpPushUrl = "rtmp://106.187.100.229/live/"
static var rtmpPlayUrl = "rtmp://106.187.100.229/live/"
static var serverUrl = "http://192.168.100.70:3000"

}

Where do I get the 3 urls?

Explain Please! Where would I find these?

After creating the server, it says to find my rtmpPushURL

static var rtmpPushUrl = ???
static var rtmpPlayUrl = ???
static var serverUrl = ???

Where would I find these? (I'm on mac)

videocore pod - AudioMixer.cpp videocore/mixers/Apple/AudioMixer.h file not found

It seems latest version of cocoapods maybe causing problems with videocore.

  • fixed

Save this file Gemfile in the live-ios folder.

Gemfile

source 'https://rubygems.org'
gem 'cocoapods', '= 0.39.0'

then run > bundle install

// WARNING
// no bundler ?
https://discuss.circleci.com/t/choosing-the-right-version-of-cocoapods-in-your-project/2997
// please read up about rvm + cocoapods before continuing.
// running this on a production system would cause problems.
// (basically you are hot swapping ruby versions / this will result in missing gems that will need to be re-installed
// rvm not found?
// curl -L https://get.rvm.io | bash -s -- --version latest
// open new terminal
// sudo rvm install 2.2.2
// sudo gem install activesupport -v '5.0.0'
/ / bundle install

compile + fixed.

screen shot 2016-07-31 at 11 30 30 am

Version 7.3.1 (7D1014)
pods 1.0.1

screen shot 2016-07-31 at 11 11 38 am

➜ live-ios git:(master) ✗ cat Podfile.lock
PODS:

  • boost (1.51.0):
    • boost/graph-includes (= 1.51.0)
    • boost/math-includes (= 1.51.0)
    • boost/numeric-includes (= 1.51.0)
    • boost/pointer_cast-includes (= 1.51.0)
    • boost/preprocessor-includes (= 1.51.0)
    • boost/shared_ptr-includes (= 1.51.0)
    • boost/string_algorithms-includes (= 1.51.0)
  • boost/graph-includes (1.51.0)
  • boost/math-includes (1.51.0)
  • boost/numeric-includes (1.51.0)
  • boost/pointer_cast-includes (1.51.0)
  • boost/preprocessor-includes (1.51.0)
  • boost/shared_ptr-includes (1.51.0)
  • boost/string_algorithms-includes (1.51.0)
  • glm (0.9.7.1)
  • IHKeyboardAvoiding (2.6)
  • R.swift (2.4.0):
    • R.swift.Library (~> 2.2.0)
  • R.swift.Library (2.2.0)
  • Socket.IO-Client-Swift (6.1.4)
  • SVProgressHUD (2.0.3)
  • TextAttributes (0.3.1)
  • UriParser-cpp (0.1.3)
  • VideoCore/Swift (0.3.2):
    • boost (~> 1.51.0)
    • glm (~> 0.9.7.1)
    • UriParser-cpp (~> 0.1.3)

DEPENDENCIES:

  • glm (from https://github.com/maxcampolo/glm.git)
  • IHKeyboardAvoiding
  • R.swift
  • Socket.IO-Client-Swift
  • SVProgressHUD
  • TextAttributes
  • VideoCore/Swift (from https://github.com/maxcampolo/VideoCore.git, branch update_headers)

EXTERNAL SOURCES:
glm:
:git: https://github.com/maxcampolo/glm.git
VideoCore:
:branch: update_headers
:git: https://github.com/maxcampolo/VideoCore.git

CHECKOUT OPTIONS:
glm:
:commit: 2cfe1129de430e4b23e811c5e0800989283af224
:git: https://github.com/maxcampolo/glm.git
VideoCore:
:commit: 44d54cc477fc1aee3c9b498363d1b2937e97d69b
:git: https://github.com/maxcampolo/VideoCore.git

SPEC CHECKSUMS:
boost: 6c5c8d8daef26ac83c1e1c00ad14de62b80161d7
glm: e83c95e7a6359bdaeb23e6089ac826dd62c5c09f
IHKeyboardAvoiding: d2541ee56dad83e160cd9aed0468c52247af6f49
R.swift: 0ef9c42dc6c94ac44a3c78a7639c73f855a8e159
R.swift.Library: 31a487b65381f37a7d203a6f1f935b43c9be35b0
Socket.IO-Client-Swift: 79dfbbe170d7816c84e2d3cc2baa3d227549e067
SVProgressHUD: b0830714205bea1317ea1a2ebc71e5633af334d4
TextAttributes: b43233c6356a72f1c1e483d5bda694535432a4be
UriParser-cpp: cbbe00080ee432ec4833dca863a7fc83adc9b01a
VideoCore: 5d8ea99d900089ee016bb87485912b0286e07650

PODFILE CHECKSUM: 5d3bb34d70e08934417075aa86abaa934e62d4b7

COCOAPODS: 1.0.1

Bitcode bundle error while Archiving

The project builds just fine, however when I try to archive it, I receive the following:

ld: bitcode bundle could not be generated because '../pili-librtmp.framework/pili-librtmp(amf.o)' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture armv7

I have a physical device connected (NOT a Simulator). I've set the enable_bitcode flags = NO at both the project and pod level. Nothing.

Supported Languages

Hello again.
I was trying to make channels in chinese and greek characters but it doesnt work and it crashes in this line in the file
AudienceViewController

override func viewDidLoad() {
        super.viewDidLoad()

        player = IJKFFMoviePlayerController(contentURL: NSURL(string: Config.rtmpPlayUrl + room.key), withOptions: IJKFFOptions.optionsByDefault())

        player.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]  //in this line!!
        player.view.frame = previewView.bounds
        previewView.addSubview(player.view)

        player.prepareToPlay()

        socket.on("connect") {[weak self] data, ack in
            self?.joinRoom()
        }

    }

Any idea how to make it support different characters?

local RTMP and nginx server not accessible

i had setup rtmp and nginx server locally and is working testing with obs app and ffpeg command able to publish video stream from mac(where nginx is installed).
but from iphone or other system on lan on entering my system ip address it doesn't work.

Not able to make an ipa file

Hi, It is running successfully in simulator and device when connected to system.

But I am unable to make ipa file at the time of build. It is showing me 4 error. Please check screenshot.

Please help me to resolve the issue.
screen shot 2017-06-28 at 4 33 32 pm

Archive clang error at IJKMediaFramework

ld: bitcode bundle could not be generated because '.../Live/live-ios/IJKMediaFramework.framework/IJKMediaFramework(IJKMediaPlayback.o)' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I succeeded to run Live, but failed to archive it.
Do you have any suggestion that I should do?

error when creating archive

Error face when create archive
xcode version : 8.3

OBJC_CLASS$IJKFFOptions”,referenced from:
Objc-class-ref in streaming_play.o

“_IJKMPMoviePlayerLoadStateDidChangeNotification”,referenced from:
TFC8stratafy14streaming_play14viewAillAppearfSbR in streaming_play.o

OBJC_CLASS$IJKFFMoviePlayerController”,referenced from:
Objc-class-ref in streaming_play.o
Symbol(s) not found for architecture armv7

Update to Swift 4?

Has anyone tried to update this project so that it works with Swift 4/iOS 11?

App seems to be crashing when I try to create a room (start broadcasting) on a test phone

Everything seems to work on simulator, I am able to start a broadcast room and find the room and start chatting and sending gifts in the room.
However, when I load it to a test phone (iphone7), as soon as I click on the + to start a broadcast room, the app crashes.

It seems that this is not successful in BroadcasterViewController:
let videoConfiguration = LFLiveVideoConfiguration.defaultConfiguration(for: .medium3)
I get a error "Protocol not available"
Am I missing a step somewhere? Thank you so much!

Missing videocore pods?

Please help.. I ran the pod install and everything installed perfectly all dependencies. Opened the project and went to run on my device and I am getting errors.. ran multiple pod installs with success, but not sure why I am missing these files. I went to videoCore directly and copied the mixers folder in.. still no dice..
screen shot 2016-09-01 at 1 26 22 pm

Can't run on physical device

I'm trying to run this project on a 1st gen iPad mini with iOS 9.3.3. The build fails with these errors:

image

I'm able to run it fine on the simulator though.

nginx.conf file

Could you please share your nginx.conf file? Because we are the noobies here and don't know anything about Nginx :(
Just to mention that your app with your server runs perfect and i'm trying to make it on my own!

second launch crashed.

i have changed
123
in Config.swift
and i run node app.js success and terminal display listening on port 3000...
for the first time it works well.but second time it crashed like below:
123

Can't display video when join room

I used server localhost
struct Config {

static var rtmpPushUrl = "rtmp://192.168.0.104:3000/live/"
static var rtmpPlayUrl = "rtmp://192.168.0.104:3000/live/"
static var serverUrl = "http://192.168.0.104:3000"

}

I created room in Device A. And then join room from Device B. But device B do not show video, It's only chat , send gift..

Please, Can i help you how show it.
Thank you

Swift 3 - 6 errors

Followed all instructions, but I am getting these errors on iOS 10 Swift 3
screen shot 2017-05-31 at 9 34 39 am

Delay

Hi, guys. It's really cool theme. I've created something like this using a little other stack devices and technologies. And I have a couple questions to you, which is a delay in your app? And what appear when the speed of connection becomes low - losing frames or video is frozen?
Thank you in advance

Latency issue

Hi,
Thanks for sharing the great code. I try it with DigitalOcean server and choose the Singapore Data Center as it's closest to me.

There's a problem with delay in the live video(Latency).

Do you have any suggestion on hosting or configuration to do to reduce it to the minimum?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.