Skip to content

Instantly share code, notes, and snippets.

@hansemannn
Last active January 29, 2020 22:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hansemannn/5dd6f9b98d479969c638fc2471c288c0 to your computer and use it in GitHub Desktop.
Save hansemannn/5dd6f9b98d479969c638fc2471c288c0 to your computer and use it in GitHub Desktop.
CXCallObserver in Hyperloop and Titanium
var CallDelegate = Hyperloop.defineClass('CallDelegate', 'NSObject', ['CXCallObserverDelegate']);
CallDelegate.addMethod({
selector: 'callObserver:callChanged:',
instance: true,
arguments: [
'CXCallObserver',
'CXCall'
],
callback: function (callObserver, call) {
if (this.callChanged) {
this.callChanged(callObserver, call);
}
}
});
module.exports = CallDelegate; // Export, so it can be instantiated with "new"
var CXCallObserver = require('CallKit/CXCallObserver'); // Require native class from CallKit
var CallDelegate = require('callDelegate'); // Require delegate class from app/lib/ (Alloy) or Resources/ (Classic)
var myDelegate = new CallDelegate(); // Instantiate Delegate
myDelegate.callChanged = function (callObserver, call) {
if (call.hasConnected) {
Ti.API.info('********** voice call connected **********\n');
} else if(call.hasEnded) {
Ti.API.info('********** voice call disconnected **********/n');
}
};
var callObserver = new CXCallObserver(); // Short-form for as alloc().init()
callObserver.setDelegateQueue(myDelegate, null); // Same as "setDelegate:queue:"
// TODO: Simply wrap into a function "initializeCallObserver" and use it somewhere in your app!
@nirmaljpatel
Copy link

Note: for this to work, add Background mode definition in tiapp.xml

<key>UIBackgroundModes</key>
        <array>
          <string>voip</string>
        </array>

@nirmaljpatel
Copy link

Also in my testing I saw that the event fired when call is disconnected has both hasConnected and hasEnded set to 1.
Event for call connected has hasConnected =1 and hasEnded set to 0.

So go see the correct logs; I had to reverse the order of the if clauses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment