/cordova-plugin-broadcaster

Cordova Plugin for broadcast message, eg. IPC.

Primary LanguageJavaMIT LicenseMIT

Cordova Plugin Broadcaster

Cordova Plugin for broadcast, using context.registerReceiver instead of LocalBroadcastManager, to support IPC in android. Forked from https://github.com/bsorrentino/cordova-broadcaster

Installation

$ cordova plugin add https://github.com/hankersyan/cordova-plugin-broadcaster.git

Usage:

    // on receiving the RFID event
	function onRfidReceived( e ) {
      	console.log( "rfid received! data=" + JSON.stringify(e)  );
      	document.getElementById('message').innerText += JSON.stringify(e);
    }
    
    // on receiving the BarCode event
	function onBarReceived( e ) {
      	console.log( "bar received! data=" + JSON.stringify(e)  );
      	document.getElementById('message').innerText += JSON.stringify(e);
    }

    // start to receive the broadcast
    function startListenBroadcast() {
		console.log( "register for SYSTEM_RFID_READ + SYSTEM_BAR_READ" );
    	window.broadcaster.addEventListener( "SYSTEM_RFID_READ", onRfidReceived);
    	window.broadcaster.addEventListener( "SYSTEM_BAR_READ", onBarReceived);
    }

    // stop to receive the broadcast
    function stopListenBroadcast() {
		console.log( "unregister for broadcast!" );
    	window.broadcaster.removeEventListener( "SYSTEM_RFID_READ", onRfidReceived);
    	window.broadcaster.removeEventListener( "SYSTEM_BAR_READ", onBarReceived);
    }

    // send a broadcast
    function sendBroadcast() {
		window.broadcaster.fireNativeEvent( "SYSTEM_RFID_READ", { rfid_value:'123456789' }, function() {
			console.log( "event fired!" );
		});
		window.broadcaster.fireNativeEvent( "SYSTEM_BAR_READ", { bar_value:'987654321' }, function() {
			console.log( "event fired!" );
		});
	}