BridgeIt API

BridgeIt

The BridgeIt JavaScript API

Native Mobile integration for your web app.

BridgeIt provides a variety of device commands that allow access to device features from JavaScript, all while running in the stock browser such as Safari or Chrome. This is made possible by the BridgeIt utility app that runs alongside the browser and is available for each of the supported platforms (currently Android, iOS, and Windows Phone 8).

For example..

bridgeit.camera('myCamera', 'myCallback');

will allow the user to take a photo identified by 'myCamera' and this will be returned via an event to the function named myCallback. For the best compatibility the callback is passed by name since the browser page may be refreshed when the callback returns.

Most device commands accept an options parameter object. Options supported by a variety of commands are: options.postURL (the URL used to upload the result of the command), and extra parameters specific to the command may be added to the options argument.

Settings & Utilities

bridgeit.allowAnonymousCallbacks

Set allowAnonymousCallbacks to true to take advantage of persistent callback functions currently supported on iOS (default false).

Parameters

bridgeit.appStoreURL()

The app store URL to BridgeIt for the appropirate platform.

bridgeit.isAndroid()

Is the current browser Android?

bridgeit.isIOS()

Is the current browser iOS?

bridgeit.isRegistered()

Verify that BridgeIt Cloud Push is registered.

bridgeit.isSupportedPlatform(command)

Check if the current browser is supported by the BridgeIt Native Mobile app.

Currently iOS, Android, and some features on Windows Phone 8 are supported.

Parameters

bridgeit.isWindowsPhone8()

Is the current browser Windows Phone 8?

bridgeit.launchFailed(id)

Application provided callback to detect BridgeIt launch failure. This should be overridden with an implementation that prompts the user to download BridgeIt and potentially fallback with a different browser control such as input file.

Parameters

bridgeit.notSupported(id, command)

Application provided callback to detect non-supported clients. This should be overridden with an implementation that informs the user the user that native mobile functionality is only available on supported platforms or potentially fallback with a different browser control such as input file, which would be available on all browsers.

Parameters

bridgeit.register(id, callback, options)

Register BridgeIt integration and configure Cloud Push.

This call is necessary to obtain the Cloud Push ID of the device so that notifications can be delivered when the user is not currently viewing your application in the browser.

The callback function will be called when Cloud Push registration completes.

Parameters

bridgeit.url2Object(encoded)

Utility method to unpack url-encoded parameters into an object.

Parameters

bridgeit.cloudPushReturnURL(url)

Augment a URL so that callbacks will be invoked upon Cloud Push return. If called with no argument, the current URL is used.

Parameters

bridgeit.overrideAugmentedRealityAlphaLevel

Set the property to true to have Augmented Reality (in experimental status) be used on Android (default false)

BridgeIt

bridgeit.augmentedReality(id, callback, options)

Launch an Augmented Reality view.

The Augmented Reality view displays a set of geo-positioned images on a video overlay. The images are positioned according to the orientation of the device so that they appear in a line-of-sight with their physical geographic position. The user can select an icon and this is relayed back to the application.

The callback function will be called once the augmented reality view exits with the user selection provided in the return value. The command is invoked with a locations parameter containing an array of named locations, each with a comma-separated latitude, longitude, altitude, direction, and icon URL

<script type="text/javascript">
function handleAug(event)  {
    var text = event.value;
    if (event.response)  {
        var len = "Aug".length;
        var responseLoc = "" + JSON.parse(event.response)["_loc"][0];
        var iconNum = responseLoc.substring(len, len + 1);
        document.getElementById("selected")
                .setAttribute("src",
                "icons/icon" + iconNum + ".png");
    }
}
var locations = {};
locations['marker-a'] = "52.0,114.0,,,image-a.png";
locations['marker-b'] = "27.0,130.0,,,image-b.png";
var postURL = 'http://myserver/ar-post';

</script>
<button id="aug" onclick="bridgeit.augmentedReality('_loc','handleAug', {postURL:postURL, locations: locations});">
    Reality View ... </button>

Parameters

BridgeIt

bridgeit.camcorder(id, callback, options)

Launch the native video recorder.

The callback function will be called once the video is captured.

<script type="text/javascript">
function onAfterVideoCapture(event)  {
    if (event.preview)  {
        document.getElementById("videoThumbnail").setAttribute("src", event.preview);
    }
    if (event.response)  {
        var videoURL = event.response;
        var elem = document.getElementById('videos');
        var vid = document.createElement('video');
        vid.setAttribute('src',  videoURL);
        vid.setAttribute('controls', 'controls');
        vid.setAttribute('preload', 'auto');
        vid.setAttribute('type', 'video/mp4');
        vid.setAttribute('webkit-playsinline', 'yes');
        elem.insertBefore(vid,elem.firstChild);
    }
}
var postURL = 'http://myserver/video-upload';

</script>
<a id="camcorderBtn" type="button" class="btn"
    onclick="bridgeit.camcorder('camcorderBtn','onAfterVideoCapture', {postURL: postURL});">
    Record a Video</a>

Parameters

BridgeIt

bridgeit.camera(id, callback, options)

Launch the native camera.

The callback function will be called once the photo is captured.

<script type="text/javascript">
function onAfterPhotoCapture(event)  {
    if (event.preview)  {
        document.getElementById("photoThumbnail").setAttribute("src", event.preview);
    }
    if (event.response)  {
        var imageURL = event.response;
        var elem = document.getElementById('photos');
        var image = document.createElement('img');
        image.setAttribute('src',  imageURL);
        elem.insertBefore(image,elem.firstChild);
    }
}
var postURL = 'http://myserver/photo-upload';

</script>
<a id="cameraBtn" type="button" class="btn"
    onclick="bridgeit.camera('cameraBtn','onAfterPhotoCapture', {postURL: postURL});">
    Take a photo</a>

Parameters

BridgeIt

bridgeit.fetchContact(id, callback, options)

Launch the native contact list app to select a contact.

The callback function will be called once a contact is seleted.

Parameters

BridgeIt

bridgeit.geoTrack(id, callback, options)

Activate location tracking.

Location tracking will run in the background according to the specified strategy and duration, and will POST a geoJSON record to the specified postURL.

Three strategies are currently supported: "continuous" where the location of the device will be uploaded as frequently as it changes (intended for testing only due to high power consumption), "significant" where the location is uploaded when it changes significantly, and "stop" to cease location tracking.

The callback function will be called once location tracking is activated.

Parameters

BridgeIt

bridgeit.microphone(id, callback, options)

Launch the native audio recorder.

The callback function will be called once the audio is captured.

Parameters

BridgeIt

bridgeit.push(groupName, options)

Push a notification to the group.

This will result in an Ajax Push (and associated callback) to any web pages that have added a push listener to the specified group. If Cloud Push options are provided (options.subject and options.detail) a Cloud Push will be dispatched as a home screen notification to any devices unable to recieve the Ajax Push via the web page.

Push notification to the group.

<a id="regBtn" type="button" class="btn"
    onclick="bridgeit.register('_reg', 'handlePushRegistration');">Enable Cloud Push</a>

<a id="pushBtn" type="button" class="btn"
    onclick="delayedPush();">Push in 10 seconds ...</a>
<script type="text/javascript">
function delayedPush()  {
    bridgeit.push( bridgeit.getId(),
        {subject:'BridgeIt Cloud Push',
        detail:'You have been notified.', delay:10000} );
}

function handlePushRegistration(event)  {
    if (bridgeit.isRegistered())  {
        document.getElementById('regBtn').style.display = 'none';
    }
}

function handlePush()  {
    ...
}
//api key for push service available from bridgeit.mobi
var apikey = 'xxx';
var pushHub = 'http://api.bridgeit.mobi/push/';
bridgeit.usePushService(pushHub, apikey);
bridgeit.addPushListener(bridgeit.getId(), 'handlePush');

</script>

Parameters

BridgeIt

bridgeit.scan(id, callback, options)

Launch the device scanner. Scan QR codes or bar codes (iOS 7).

The callback function will be called once the scan is captured.

Parameters

BridgeIt

bridgeit.sms(number, message)

The sms function will send an SMS message to a number on supported platforms. On iOS devices, a native SMS call is made through the BridgeIt utility app. On other platforms an SMS URL protocol is used in a DOM anchor element, which the browser may use to launch the device SMS functionality, if available.

Parameters

BridgeIt

bridgeit.speech(id, callback, options)

Text-to-speech.

Parameters

BridgeIt

bridgeit.beacons(id, callback, options)

Detect nearby iBeacons.

The callback function will be called when an iBeacon is detected. The return value will be set to the range, major, and minor values if available.

This is currently a pre-alpha feature and is being developed initially on iOS.

Parameters