Skip to content

Commit

Permalink
v3.0.0 (#16)
Browse files Browse the repository at this point in the history
* update initPublisher to mimic OpenTok JS SDK
* update publisher docs
* remove extra android sdk library and restructure android plugin filepath
* update version
  • Loading branch information
msach22 authored Nov 22, 2017
1 parent 6631b81 commit b3ad114
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 81 deletions.
27 changes: 23 additions & 4 deletions docs/tb.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,36 @@ TB.addEventListener('exception', function(e){
```

<a name="initPublisher"></a>
### OT.initPublisher apiKey:String, [replaceElementId:String], [properties:Object]):Publisher
### OT.initPublisher [replaceElementId:String], [properties:Object]):Publisher

Initializes and returns a Publisher object. You can use this Publisher object to test the microphone and camera attached to the Publisher, and then pass this Publisher object to Session.publish() to publish a stream to a session.

You can only create one publisher object. Calling TB.initPublisher() more than once will fail silently.
You can only create one publisher object. Calling `OT.initPublisher()` more than once will fail silently.

#### Parameters

* **apikey** (String) — The API key that TokBox provided you when you registered for the OpenTok API.

* **replaceElementId** (String) - Optional. The id attribute of the existing DOM element that the Publisher video replaces. If you do not specify a replaceElementId, the application appends a new DOM element to the HTML body.

* **properties** (Object) — Optional. This is an optional object that contains the following properties (each of which are optional):

* **audioBitrate** (Number) — The desired bitrate for the published audio, in bits per second. The supported range of values is 6,000 - 510,000. (Invalid values are ignored.) Set this value to enable high-quality audio (or to reduce bandwidth usage with lower-quality audio).
The following are recommended settings:

* **8,000 - 12,000 for narrowband (NB) speech**
* **16,000 - 20,000 for wideband (WB) speech**
* **28,000 - 40,000 for full-band (FB) speech**
* **48,000 - 64,000 for full-band (FB) music**

* **The default value is 40,000.**

* **audioFallbackEnabled** (Boolean) — Whether to turn on audio fallback or not.

* **audioSource** (Boolean) — If this property is set to false, the audio subsystem will not be initialized for the publisher, and setting the publishAudio property will have no effect. If your application does not require the use of audio, it is recommended to set this property rather than use the publishAudio property, which only temporarily disables the audio track.

* **cameraName** (String) - The preferred camera position. When setting this property, if the change is possible, the publisher will use the camera with the specified position. Valid Inputs: 'Front' or 'Back'

* **frameRate** (Number) - The desired frame rate, in frames per second, of the video. Valid values are 30, 15, 7, and 1. The published stream will use the closest value supported on the publishing client. The frame rate can differ slightly from the value you set, depending on the device of the client. And the video will only use the desired frame rate if the client configuration supports it.

* **height** (Number) — The desired height, in pixels, of the displayed Publisher video stream (default: 198).

Expand All @@ -57,6 +72,10 @@ You can only create one publisher object. Calling TB.initPublisher() more than o

* **publishVideo** (Boolean) — Whether to publish video.

* **resolution** (String) - The desired resolution of the video. The format of the string is "widthxheight", where the width and height are represented in pixels. Valid values are "1280x720", "640x480", and "320x240". The published video will only use the desired resolution if the client configuration supports it. Some devices and clients do not support each of these resolution settings.

* **videoSource** (Boolean) — If this property is set to false, the video subsystem will not be initialized for the publisher, and setting the publishVideo property will have no effect. If your application does not require the use of video, it is recommended to set this property rather than use the publishVideo property, which only temporarily disables the video track.


#### Returns

Expand All @@ -65,7 +84,7 @@ You can only create one publisher object. Calling TB.initPublisher() more than o

Example Code:
```
var publisher = OT.initPublisher('1127', 'myPublisherDiv', {name:"HelloWorld"} );
var publisher = OT.initPublisher('myPublisherDiv', {name:"HelloWorld", audioSource: false } );
```

<a name="initSession"></a>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Cordova-Plugin-OpenTok",
"version": "2.3.0",
"version": "3.0.0",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-coffee": "^0.10.1",
Expand Down
6 changes: 2 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.tokbox.cordova.opentok"
version="1.0.4">
version="3.0.0">

<name>OpenTokCordovaPlugin</name>
<description>Add live video streaming to your Cordova Application</description>
Expand All @@ -12,7 +12,7 @@
<platform name="android">
<framework src="build-extras.gradle" custom="true" type="gradleReference" />
<asset src="www/opentok.js" target="opentok.js" />
<source-file src="src/android/com/tokbox/cordova/OpenTokAndroidPlugin.java" target-dir="src/com/tokbox/cordova/" />
<source-file src="src/android/OpenTokAndroidPlugin.java" target-dir="src/com/tokbox/cordova/" />

<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.CAMERA" />
Expand All @@ -26,8 +26,6 @@

<!-- copy opentok sdk -->

<source-file src="src/android/libs/opentok-android-sdk-2.12.0.aar" target-dir="libs/" />
<resource-file src="src/android/libs/opentok-android-sdk-2.12.0.aar" target="libs/opentok-android-sdk-2.12.0.aar" />
<config-file target="config.xml" parent="/*">
<feature name="OpenTokPlugin">
<param name="android-package" value="com.tokbox.cordova.OpenTokAndroidPlugin"/>
Expand Down
File renamed without changes.
Binary file removed src/android/libs/opentok-android-sdk-2.12.0.aar
Binary file not shown.
17 changes: 0 additions & 17 deletions src/android/libs/opentok-android.gradle

This file was deleted.

4 changes: 2 additions & 2 deletions src/js/OT.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
window.OT =
checkSystemRequirements: ->
return 1
initPublisher: (one, two, three) ->
return new TBPublisher( one, two, three )
initPublisher: (one, two) ->
return new TBPublisher( one, two )
initSession: (apiKey, sessionId ) ->
if( not sessionId? ) then @showError( "OT.initSession takes 2 parameters, your API Key and Session ID" )
return new TBSession(apiKey, sessionId)
Expand Down
37 changes: 10 additions & 27 deletions src/js/OTPublisher.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# setStyle( style, value ) : publisher - not yet implemented
#
class TBPublisher
constructor: (one, two, three) ->
@sanitizeInputs( one,two, three )
constructor: (one, two) ->
@sanitizeInputs(one, two)
pdebug "creating publisher", {}
position = getPosition(@domId)
name=""
Expand Down Expand Up @@ -113,33 +113,17 @@ class TBPublisher
publishState = "false"
pdebug "setting publishstate", {media: media, publishState: publishState}
Cordova.exec(TBSuccess, TBError, OTPlugin, media, [publishState] )
sanitizeInputs: (one, two, three) ->
if( three? )
# all 3 required properties present: apiKey, domId, properties
# Check if dom exists
@apiKey = one
@domId = two
@properties = three
else if( two? )
# only 2 properties are present, possible inputs: apiKey, domId || apiKey, properties || domId, properties
if( typeof(two) == "object" )
# second input is property, so first input is either apiKey or domId
@properties = two
if document.getElementById(one)
@domId = one
else
@apiKey = one
else
# no property object is passed in
@apiKey = one
@domId = two
sanitizeInputs: (one, two) ->
if( two? )
# all 2 optional properties present: domId, properties
@domId = one
@properties = two
else if( one? )
# only 1 property is present, apiKey || domId || properties
# only 1 property is present domId || properties
if( typeof(one) == "object" )
@properties = one
else if document.getElementById(one)
else
@domId = one
@apiKey = if @apiKey? then @apiKey else ""
@properties = if( @properties and typeof( @properties == "object" )) then @properties else {}
# if domId exists but properties width or height is not specified, set properties
if( @domId and document.getElementById( @domId ) )
Expand All @@ -152,5 +136,4 @@ class TBPublisher
@properties.height = position.height
else
@domId = TBGenerateDomHelper()
@domId = if( @domId and document.getElementById( @domId ) ) then @domId else TBGenerateDomHelper()
@apiKey = @apiKey.toString()
return @
35 changes: 10 additions & 25 deletions www/opentok.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ window.OT = {
checkSystemRequirements: function() {
return 1;
},
initPublisher: function(one, two, three) {
return new TBPublisher(one, two, three);
initPublisher: function(one, two) {
return new TBPublisher(one, two);
},
initSession: function(apiKey, sessionId) {
if (sessionId == null) {
Expand Down Expand Up @@ -275,14 +275,14 @@ var TBPublisher,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

TBPublisher = (function() {
function TBPublisher(one, two, three) {
function TBPublisher(one, two) {
this.removePublisherElement = __bind(this.removePublisherElement, this);
this.streamDestroyed = __bind(this.streamDestroyed, this);
this.streamCreated = __bind(this.streamCreated, this);
this.eventReceived = __bind(this.eventReceived, this);
this.setSession = __bind(this.setSession, this);
var audioBitrate, audioFallbackEnabled, audioSource, cameraName, frameRate, height, name, position, publishAudio, publishVideo, ratios, resolution, videoSource, width, zIndex, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
this.sanitizeInputs(one, two, three);
this.sanitizeInputs(one, two);
pdebug("creating publisher", {});
position = getPosition(this.domId);
name = "";
Expand Down Expand Up @@ -430,32 +430,18 @@ TBPublisher = (function() {
return Cordova.exec(TBSuccess, TBError, OTPlugin, media, [publishState]);
};

TBPublisher.prototype.sanitizeInputs = function(one, two, three) {
TBPublisher.prototype.sanitizeInputs = function(one, two) {
var position;
if ((three != null)) {
this.apiKey = one;
this.domId = two;
this.properties = three;
} else if ((two != null)) {
if (typeof two === "object") {
this.properties = two;
if (document.getElementById(one)) {
this.domId = one;
} else {
this.apiKey = one;
}
} else {
this.apiKey = one;
this.domId = two;
}
if ((two != null)) {
this.domId = one;
this.properties = two;
} else if ((one != null)) {
if (typeof one === "object") {
this.properties = one;
} else if (document.getElementById(one)) {
} else {
this.domId = one;
}
}
this.apiKey = this.apiKey != null ? this.apiKey : "";
this.properties = this.properties && typeof (this.properties === "object") ? this.properties : {};
if (this.domId && document.getElementById(this.domId)) {
if (!this.properties.width || !this.properties.height) {
Expand All @@ -470,8 +456,7 @@ TBPublisher = (function() {
} else {
this.domId = TBGenerateDomHelper();
}
this.domId = this.domId && document.getElementById(this.domId) ? this.domId : TBGenerateDomHelper();
return this.apiKey = this.apiKey.toString();
return this;
};

return TBPublisher;
Expand Down

0 comments on commit b3ad114

Please sign in to comment.