Coder Social home page Coder Social logo

kurento-go's Introduction

Go Kurento communication package

Kurento is a WebRTC Media Server built over Gstreamer. It allows stream management between Web browser and Server.

WebRTC is a project that provides browser and mobiles integration with Reat Time Communication capabilities via simple APIs. -- http://www.webrtc.org/

Without Kurento, you will only be able to connect 2 browsers each other. That enougth for a lot of applications but you will need more when you want to stream from one browser to several clients, stream a video to several readers, and so on. For that need, you probably want to have client-server capabilities.

WebRTC is fully implemented in Kurento Media Server.

Kurento with Go

With Go at server side, you only need to implement browser to application message system (websocket, xhttpRequest...) to pass information to KMS or to clients.

Your application will communicate streams information to KMS via Kurento Go Package and to clients.

See doc at https://godoc.org/github.com/metal3d/kurento-go

Example:

This snippet shows a simple way to have master (sender) and viewer (reciever). Master MUST be created at first. Note that there is no "close" management, this is only to show you how it works.

Launch KMS server, or if you have docker, run this command:

docker start --rm -it -p 8888:8888 kurento/media-server-64:5.1.0-trusty

You will be able to connect to 127.0.0.1:8888 that is the JSONRPC over WebSocket port that opens Kurento.

In you Go application:

import "github.com/metal3d/kurento-go"

// Create master pipeline and master WebRtcEnpoint
// that will be shared to viewers
var pipeline = new(kurento.MediaPipeline)
var master = new(kurento.WebRtcEndpoint)
var server = kurento.NewConnection("ws://127.0.0.1:8888")

...

// Somewhere 
// in a websocket handler:

message := ReadWebSocket()

if message["id"] == "master" {
    pipeline.Create(master, nil)
    answer, _ := master.ProcessOffer(message["sdpOffer"])

    // need to connect one sink, use self connection
    master.Connect(master, "", "", "") // empty options

    // return the answer to sender
    SendtoClient(json.Marshal(map[string]string{
        "id"        : "masterResponse",
        "response"  : "accept",
        "sdpAnswer" : answer,
    }))
}

if message["id"] == "viewer" {
    viewer := new(kurento.WebRtcEndpoint)
    pipeline.Create(viewer, nil)
    answer, _ := viewer.ProcessOffer(message["sdpOffer"])

    //connect master to viewer
    master.Connect(viewer, "", "", "")

    //return answer to viewer
    SendtoClient(json.Marshal(map[string]string{
        "id"        : "viewerResponse",
        "response"  : "accept",
        "sdpAnswer" : answer,
    }))
}

Note that SendToClient() and ReadWebsocket() should be implemented by yourself, you may want to use standard websocket handler, or gorilla websocket.

The browser side:

 var ws = new WebSocket("ws://127.0.0.1:8000/ws"),
        master = null,
        viewer = null;

    ws.onmessage = function(resp) {
        r = JSON.parse(resp.data);
        switch(r.id) {
            case "masterResponse":
                if (r.response == "accepted") {
                    master.processSdpAnswer(r.sdpAnswer);
                }
                break;
            case "viewerResponse" :
                if (r.response == "accepted") {
                    viewer.processSdpAnswer(r.sdpAnswer);
                }
                break;
            default:
                console.error(r);
                break;
        }
    };

To launch master:

function startMaster(){
    var video = $("#mastervideo");
    master = kurentoUtils.WebRtcPeer.startSendOnly(video, function(offer){
            var message = {
                id : "master",
                sdpOffer : offer
            };
            ws.send(JSON.stringify(message));
            console.log("sent offer from master to viewer")
    });
}

And the viewer:

function startViewer(){
    var video = $("#clientvideo");
    viewer =  kurentoUtils.WebRtcPeer.startRecvOnly(video, function(offerSdp) {
        var message = {
            id : 'viewer',
            sdpOffer : offerSdp
        };
        ws.send(JSON.stringify(message));
        console.log("sent offer from viewer to master")
    });
}

You have to create video element and manage call to startMaster() and startViewer().

Remember that the "onclose" process is not implemented on this snippet.

Help !

I need help to continue the package developpement. This package is generated by https://github.com/metal3d/kurento-go-generator

Because Kurento provides elements and JSONRPC IDL in json form, it's common to generate the Go Package and not to code by hand the entire source.

If you want to help, please fork and pull-request on kurento-go-generator repository and not on kurento git repository. I will not accept pull-request on kurento repository because the code is generated.

At this time, kurento package is in alpha stage. There will be a lot of changes, maybe a rewrite of several parts. Please, forgive me if you have to change a lot of things after an update.

Soon, package will be released with version and we will use GoPkg to provide versions.

kurento-go's People

Contributors

metal3d avatar

Watchers

 avatar

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.