Skip to content


Subversion checkout URL

You can clone with
Download ZIP
The node.js muzzley client library
JavaScript HTML
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This document describes how to use the muzzley client library.


To use the library you first need to add it to your project:

npm install muzzley-client


The following code snippet shows how to quickly get started with the muzzley client library:

var muzzley = require('muzzley-client');

muzzley.connectApp('yourAppToken', function(err, activity) {
  if (err) return console.log("err: " + err);

  activity.on('participantJoin', function(participant) {

    participant.changeWidget('gamepad', function(err) {
      if (err) return console.log("err: " + err );
      console.log('Activity: changeWidget was successful');

      participant.on('quit', function() {

      participant.on('action', function(action) {
        // Action object represents the participant's interaction




API Documentation

var muzzley = require('muzzley-client');

Creates a new muzzley instance.


The muzzley instance is an EventEmitter and you can listen to the following events:

error This event is emitted every time an error occurs during the activity.

muzzley.on('error', function(err) {

Some error messages are also sent via xhr to our servers, if you don't want this behavior you can simple turn it off

muzzley.sendErrors = false;



This method connects your app with the muzzley platform and creates an activity.

The simple way to use it, is just passing your application token which you can get from

var token = 'yourAppToken';
muzzley.connectApp(token, callback);

It is also possible to pass an options object with the token and the activityId that should be used for the new activity. For the muzzley platform to accept the provided activityId, it must be a valid static activity id of the current application (defined by the application token). The static activity ids are generated in the web site when viewing an application's details.

var options = {
  activityId: 'weee'

muzz.connectApp(options, callback);

The callback function will receive an err and an activity object.

function callback(err, activity) {



The activity object is returned in the callback of the muzzley.connectApp function and will have the activity's properties:

  activityId: '940232',
  qrCodeUrl: ''

The activity object is also an EventEmitter. You can listen to the following events:

function callback(err, activity) {
  activity.on('participantJoin', join);

  activity.on('participantQuit', quit);

participantJoin This event is emitted every time a user joins the activity.

participantQuit This event is emitted when a user quits the activity.

Each of these event functions will receive a participant object.

function join(participant) {


function quit(participant) {



The participant object will have the activity participant's properties:

  id: 1,
  name: 'Participant Name',
  photoUrl: ''

The participant is also an EventEmitter that emits the following events:

action This event is emitted every time a participant interacts and receives an action object that represents the participant's interaction.

participant.on('action', function (action) {
  // Action object represents the participants interaction

sharingInvitation This event is emitted every time a participant starts a share from assetsPicker widget and you need to accept it or reject (if you ignore it will do a timeout).

participant.on('sharingInvitation', function (invite, cbAccept) {
  // invite object contains the invitation properties

  var reason = 'the reason why you accept or reject'

  // you need allways to call the callback with true or false and a reason
  // true accepts the invitation
  // false rejects

  cbAccept(true, reason);

sharingFile This event is emitted every time a participant is actualy sending a file (if you don't accept the sharingInvitation you will never get this event)

participant.on('sharingFile', function (file) {
  // "file" object contains all information about the file 

sharingCancel This event is emitted when a share process is canceled

participant.on('sharingCancel', function (share) {
  // share object represents the share that was canceled

sharingEnd This event is emitted every time a share process ends

participant.on('sharingEnd', function (share) {
  // share object represents the shareInvitation that ended

sendMediaStream This event is emitted every time a participant starts a stream from widget cameraStream

participant.on('sendMediaStream', function (stream) {
  // stream object contains all information about the stream

quit This event is emitted when the participant quits the activity.

participant.on('quit', function () {



The changeWidget method instructs the participant's device (smartphone) to transform itself into the given widget identifier. After a successful transformation - or if some error occurs - the callback argument is called.

participant.changeWidget('widget identifier', callback);

The possible widgets are referenced in the muzzley documentation at


This method allows you to connect to a muzzley activity as a participant.

var userToken = 'guest'; 
var activityId = '14e0f3';
muzz.connectUser(userToken, activityId, callback);

The callback function will recive an err and a user object;

function callback(err, user) {


The user object will have the participant's properties:

  id: 1,
  name: 'muzzley dev',
  photoUrl: ''

The user is also an event-emitter, and you can listen for changeWidget events:

user('changeWidget', function (widget) {


the changeWidget event recives a widget string with the name of the widget wich this participant should transform

After you recive this event you can start sending widget data for that you call user.sendWidgetData

    "w": "gamepad",
    "c": "b",
    "v": 1,
    "e": 2


Coming soon.

Something went wrong with that request. Please try again.