Git Product home page Git Product logo

partner-example-app's Introduction

StreamMe Partner Example App

js-happiness-style

An example app for Stream.me Partners. This repo is an electron app integrates with the StreamMe partner api to create users and setup/view streams.

Usage

$ git clone [email protected]:StreamMeDev/partner-example-app.git
$ cd partner-example-app

To get started you will need StreamMe Partner credentials, these should have been provided to you from your contact at StreamMe. Open up config.js and add the clientSlug, clientId and clientSecret to the approprite fields in config.js. Now you can start the app:

$ npm install && npm start

This will open up an app that you can use to test out the integration. Now that you see what it can look like, lets dig into the actual integrations.

Partner API Integration

This application is structured as a React Flux app where the endpoint integrations can be found in the src/actions directory. Lets take a look at the one to create a user, here is the important part:

request({
  method: 'POST',
  url: 'https://partners.stream.me/api/v1/' + <CLIENT_SLUG> + '/users',
  json: {
    username: <UNIQUE_USERNAME>,
    email: <OPTIONAL_USER_EMAIL>
  },
  auth: {
    user: <CLIENT_ID>,
    pass: <CLIENT_SECRET>
  }
}, function (err, resp, body) {
  if (err) {
    // handle network errors
    return;
  }

  if (resp.statusCode >= 400) {
    // handle application errors
    // the response body data structure returned
    // when there is an error looks like this:
    // {
    //   "reasons": [{
    //     "message": "Some human readable error"
    //     "code": "some_machine_error_code"
    //   }]
    // }
    return;
  }

  // handle a successful user creation
  // the response body for this is super simple:
  // {
  //   "slug": "slugified-version-of-username-submitted",
  //   "username": "Username as submitted above"
  // }
});

In this example we use the request module from npm to make a basic auth'd request to the partner api. This will create a new user that you can then use to access the other partner api's, like the stream key endpoint. Lets take a look at the request to get a stream key and broadcast url just as another example:

request({
  method: 'GET',
  url: 'https://partners.stream.me/api/v1/' + <CLIENT_SLUG> + '/users/' + <USER_SLUG> + '/broadcast',
  json: true,
  auth: {
    user: <CLIENT_ID>,
    pass: <CLIENT_SECRET>
  }
}, function (err, resp, body) {
  if (err) {
    // handle network errors
    return;
  }

  if (resp.statusCode >= 400) {
    // handle application errors
    // see the data structure from above
    return;
  }

  // handle a successful user creation
  // the response body for this is:
  // {
  //   "broadcastKey": "9b597331-d950-4629-8417-834d8cafcf27",
  //   "originServers": [
  //     {
  //       "region": "US, Central",
  //       "broadcastUrl": "rtmp://ls.stream.me/origin"
  //     },
  //     {
  //       "region": "US, East",
  //       "broadcastUrl": "rtmp://ls.stream.me/origin"
  //     },
  //     {
  //       "region": "US, West",
  //       "broadcastUrl": "rtmp://ls.stream.me/origin"
  //     },
  //     {
  //       "region": "Europe, West",
  //       "broadcastUrl": "rtmp://ls.stream.me/origin"
  //     },
  //     {
  //       "region": "Asia, East",
  //       "broadcastUrl": "rtmp://ls.stream.me/origin"
  //     }
  //   ]
  // }
});

NOTE: This is just an example application. In a real application you would never want to expose your client secret to your users. The reccomended way to do a production integration is to create a server which talks to the StreamMe API's on your behalf.

partner-example-app's People

Contributors

wesleytodd avatar

Stargazers

 avatar

Watchers

 avatar  avatar

partner-example-app's Issues

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.