Comparing version 0.3.1 to 0.4.0
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Minijanus = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
/** Whether to log information about incoming and outgoing Janus signals. **/ | ||
var verbose = false; | ||
/** | ||
@@ -31,2 +28,13 @@ * Represents a handle to a single Janus plugin on a Janus session. Each WebRTC connection to the Janus server will be | ||
/** Registers a callback to be fired upon the reception of any incoming Janus signals for this plugin handle with the | ||
* `janus` attribute equal to `ev`. | ||
**/ | ||
JanusPluginHandle.prototype.on = function(ev, callback) { | ||
return this.session.on(ev, signal => { | ||
if (signal.sender == this.id) { | ||
callback(signal); | ||
} | ||
}); | ||
}; | ||
/** | ||
@@ -67,3 +75,5 @@ * Sends a signal associated with this handle. Signals should be JSON-serializable objects. Returns a promise that will | ||
this.txns = {}; | ||
this.eventHandlers = {}; | ||
this.options = Object.assign({ | ||
verbose: false, | ||
timeoutMs: 10000, | ||
@@ -97,2 +107,13 @@ keepaliveMs: 30000 | ||
/** Registers a callback to be fired upon the reception of any incoming Janus signals for this session with the | ||
* `janus` attribute equal to `ev`. | ||
**/ | ||
JanusSession.prototype.on = function(ev, callback) { | ||
var handlers = this.eventHandlers[ev]; | ||
if (handlers == null) { | ||
handlers = this.eventHandlers[ev] = []; | ||
} | ||
handlers.push(callback); | ||
}; | ||
/** | ||
@@ -107,3 +128,3 @@ * Callback for receiving JSON signalling messages pertinent to this session. If the signals are responses to previously | ||
JanusSession.prototype.receive = function(signal) { | ||
if (module.exports.verbose) { | ||
if (this.options.verbose) { | ||
console.debug("Incoming Janus signal: ", signal); | ||
@@ -114,5 +135,13 @@ } | ||
} | ||
var responseType = signal.janus; | ||
var handlers = this.eventHandlers[responseType]; | ||
if (handlers != null) { | ||
for (var i = 0; i < handlers.length; i++) { | ||
handlers[i](signal); | ||
} | ||
} | ||
if (signal.transaction != null) { | ||
var txn = this.txns[signal.transaction]; | ||
if (txn == null) { | ||
@@ -124,3 +153,3 @@ // this is a response to a transaction that wasn't caused via JanusSession.send, or a plugin replied twice to a | ||
if (signal.janus === "ack" && txn.type == "message") { | ||
if (responseType === "ack" && txn.type == "message") { | ||
// this is an ack of an asynchronously-processed plugin request, we should wait to resolve the promise until the | ||
@@ -151,3 +180,3 @@ // actual response comes in | ||
} | ||
if (module.exports.verbose) { | ||
if (this.options.verbose) { | ||
console.debug("Outgoing Janus signal: ", signal); | ||
@@ -188,4 +217,3 @@ } | ||
JanusPluginHandle, | ||
JanusSession, | ||
verbose | ||
JanusSession | ||
}; | ||
@@ -192,0 +220,0 @@ |
@@ -1,4 +0,1 @@ | ||
/** Whether to log information about incoming and outgoing Janus signals. **/ | ||
var verbose = false; | ||
/** | ||
@@ -30,2 +27,13 @@ * Represents a handle to a single Janus plugin on a Janus session. Each WebRTC connection to the Janus server will be | ||
/** Registers a callback to be fired upon the reception of any incoming Janus signals for this plugin handle with the | ||
* `janus` attribute equal to `ev`. | ||
**/ | ||
JanusPluginHandle.prototype.on = function(ev, callback) { | ||
return this.session.on(ev, signal => { | ||
if (signal.sender == this.id) { | ||
callback(signal); | ||
} | ||
}); | ||
}; | ||
/** | ||
@@ -66,3 +74,5 @@ * Sends a signal associated with this handle. Signals should be JSON-serializable objects. Returns a promise that will | ||
this.txns = {}; | ||
this.eventHandlers = {}; | ||
this.options = Object.assign({ | ||
verbose: false, | ||
timeoutMs: 10000, | ||
@@ -96,2 +106,13 @@ keepaliveMs: 30000 | ||
/** Registers a callback to be fired upon the reception of any incoming Janus signals for this session with the | ||
* `janus` attribute equal to `ev`. | ||
**/ | ||
JanusSession.prototype.on = function(ev, callback) { | ||
var handlers = this.eventHandlers[ev]; | ||
if (handlers == null) { | ||
handlers = this.eventHandlers[ev] = []; | ||
} | ||
handlers.push(callback); | ||
}; | ||
/** | ||
@@ -106,3 +127,3 @@ * Callback for receiving JSON signalling messages pertinent to this session. If the signals are responses to previously | ||
JanusSession.prototype.receive = function(signal) { | ||
if (module.exports.verbose) { | ||
if (this.options.verbose) { | ||
console.debug("Incoming Janus signal: ", signal); | ||
@@ -113,5 +134,13 @@ } | ||
} | ||
var responseType = signal.janus; | ||
var handlers = this.eventHandlers[responseType]; | ||
if (handlers != null) { | ||
for (var i = 0; i < handlers.length; i++) { | ||
handlers[i](signal); | ||
} | ||
} | ||
if (signal.transaction != null) { | ||
var txn = this.txns[signal.transaction]; | ||
if (txn == null) { | ||
@@ -123,3 +152,3 @@ // this is a response to a transaction that wasn't caused via JanusSession.send, or a plugin replied twice to a | ||
if (signal.janus === "ack" && txn.type == "message") { | ||
if (responseType === "ack" && txn.type == "message") { | ||
// this is an ack of an asynchronously-processed plugin request, we should wait to resolve the promise until the | ||
@@ -150,3 +179,3 @@ // actual response comes in | ||
} | ||
if (module.exports.verbose) { | ||
if (this.options.verbose) { | ||
console.debug("Outgoing Janus signal: ", signal); | ||
@@ -187,4 +216,3 @@ } | ||
JanusPluginHandle, | ||
JanusSession, | ||
verbose | ||
JanusSession | ||
}; |
{ | ||
"name": "minijanus", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Really simple and minimal wrapper for talking to the Janus signalling API.", | ||
@@ -20,3 +20,3 @@ "main": "minijanus.js", | ||
"devDependencies": { | ||
"browserify": "^14.5.0", | ||
"browserify": "^15.2.0", | ||
"tape": "^4.8.0" | ||
@@ -23,0 +23,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72529
425