Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bcready never fires #42

Open
BenjaminHorn opened this issue Jul 11, 2015 · 3 comments
Open

bcready never fires #42

BenjaminHorn opened this issue Jul 11, 2015 · 3 comments

Comments

@BenjaminHorn
Copy link

I made a new phonegap project, and added your plugin.

phonegap add https://github.com/bcsphere/bluetooth.git 

In index.html I added

<script src="bc.js"></script>

Do I need other files?

My index.js looks like this:

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
   onBCReady: function() {
        console.log('bcready');
    },    
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
        document.addEventListener('bcready', app.onBCReady, false);
    }
};

I can see the result of console.log('Received Event: ' + id); but never 'bcready'.

Phonegap 5.1.1-0.29.0
Android 4.3

@lizhijumacc
Copy link

try this :

    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
        document.addEventListener('bcready', this.onBCready, false);
    }

may be the 'bcready' event has been fired before the 'receivedEvent' be called.

I'll try it later.

@BenjaminHorn
Copy link
Author

@lizhijumacc thanks for your reply! Unfortunately I can still see only

[phonegap] [console.log] Received Event: deviceready

After some remote debug it turned out, BC or window.BC is null.

Looks like

<script src="bc.js"></script>

does not load BC namespace.

@BenjaminHorn
Copy link
Author

Is any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants