Web Sender App Development

Shawn Bow edited this page Jan 22, 2015 · 10 revisions

Currently Web Sender Apps are available on Firefox OS 2.2. Please download flint_sender_sdk.js and add it to Firefox OS app project.

Device Discovery

var deviceScanner = new FlintDeviceScanner();
// scan new deivces
deviceScanner.on('devicefound', function(device) {
    // get device's name
    var name = device.getName();
    // get Flint Service Url
    var url = device.getUrlBase();
    // get unique device ID
    var uniqueId = device.getUniqueId();
// device lost
deviceScanner.on('devicegone', function(device) {
// start scanning
// stop scanning
// get device list

Use FlintSenderManager

var senderManager = new FlintSenderManager(
    appid, // application ID
    '', // Flint Service url
    true // keep heartbeat with Flint Service
// set Flint Service Url
// get custom additional data from receiver
// or
senderManager.on('customDataavailable', function(customData) {

Establish communication

  • create MessageBus

    var bus = null;
    // create anonymous MessageBus
    bus = senderManager.createMessageBus();
    // create named MessageBus
    bus = senderManager.createMessageBus('namespace');    
  • listen event

    messageBus.on('message', function(message) {
  • send message

    messageBus.send('some message');

Use WebRTC

  • create Peer

    var peer = senderManager.createPeer();
  • connect receiver

    // data connection
    // stream call
    senderManager.callReceiverPeer(stream, options);

Application control

  • get application's state

    var callback = function(result, state, additionaldata) {
        // result:true means success,false means failure
        // state:application's state,could be 'stopped','starting' or 'running'
        // additionaldata:additional data from receiver
    senderManager.getState(callback); // the first way
    senderManager.on('appstate', callback); // the second way
  • launch application

    var appInfo = {
        appUrl: url,
        useIpc: true or false,
        maxInactive: int
    var callback = function(type, result, token) {
        // type:event type, 'app' + the name of api, for example, if you call launch(),the type is 'applaunch'
        // result:true means success,false means failure
        // token:Flint Service response a token to sender to indicate this request
    // launch application:
    senderManager.launch(appInfo, callback); // the first way
    senderManager.launch(appInfo) // the second way
    senderManager.on('applaunch', callback);
    // relaunch application:
    senderManager.relaunch(appInfo, callback); //the first way
    senderManager.relaunch(appInfo) // the second way
    senderManager.on('apprelaunch', callback);
    // join application:
    senderManager.join(appInfo, callback); //the first way
    senderManager.join(appInfo) // the second way
    senderManager.on('appjoin', callback);
  • stop application

    var callback = function(type, result) {
        // type:event type, 'app' + the name of api, for example, if you call stop(),the type is 'appstop'
        // result:true means success,false means failure
    // stop application:
    senderManager.stop(appInfo, callback); //the first way
    senderManager.on('appstop', callback); //the second way
    // disconnect from Flint Service but donot stop application:
    senderManager.disconnect(appInfo, callback); //the first way
    senderManager.on('appdisconnect', callback); //the second way

More sample code, please refer to:

  • Flint
    • [Developer's Guide](Developer Guide for Flint)
      • [Web Sender Apps](Web Sender App Development)
      • [Android Sender Apps](Android Sender App Development)
      • [iOS Sender Apps](iOS Sender App Development)
      • [Receiver Apps](Receiver Apps Development)
      • Chromecast App Porting
    • [API Libraries](API Libraries)
    • [Flint Protocol Docs](Flint Protocol Docs)
  • Matchstick
    • [Flashing Instructions](Flashing Instructions for Matchstick)
    • [Build Your Matchstick](Build Your Matchstick)
    • [Flashing Your Build](Flashing Your Build)
    • [Setup Your Matchstick](Setup Your Matchstick)
    • [Setup USB Mode](Setup USB Mode for Matchstick)
    • [Supported Media](Supported Media for Matchstick)
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.