Skip to content

Commit

Permalink
Merge pull request #8 from peder541/master
Browse files Browse the repository at this point in the history
Updates for PhoneGap 3.x
  • Loading branch information
jefflinwood committed Aug 17, 2014
2 parents 8634c80 + 75c4e22 commit 9dc7271
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
2 changes: 2 additions & 0 deletions plugin.xml
Expand Up @@ -15,6 +15,8 @@
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.phonegap.plugins.twilioclient.IncomingConnectionActivity" android:theme="@android:style/Theme.NoDisplay"/>
Expand Down
11 changes: 5 additions & 6 deletions src/android/com/phonegap/plugins/twilioclient/TCPlugin.java
Expand Up @@ -4,10 +4,10 @@
import java.util.Iterator;
import java.util.Map;

import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
import org.apache.cordova.api.PluginResult.Status;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.apache.cordova.PluginResult.Status;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -67,10 +67,9 @@ public void onReceive(Context context, Intent intent) {
mConnection = intent.getParcelableExtra(Device.EXTRA_CONNECTION);
mConnection.setConnectionListener(plugin);
Log.d(TAG, "incoming intent received with connection: "+ mConnection.getState().name());
JSONObject connection = new JSONObject();
String constate = mConnection.getState().name();
if(constate.equals("PENDING")) {
TCPlugin.this.javascriptCallback("onincoming", connection, mInitCallbackContext);
TCPlugin.this.javascriptCallback("onincoming", mInitCallbackContext);
}
}
};
Expand Down
18 changes: 9 additions & 9 deletions src/ios/TCPlugin.h
Expand Up @@ -18,23 +18,23 @@
-(void)device:(TCDevice*)device didReceiveIncomingConnection:(TCConnection*)connection;
-(void)device:(TCDevice *)device didReceivePresenceUpdate:(TCPresenceEvent *)presenceEvent;
-(void)deviceDidStartListeningForIncomingConnections:(TCDevice*)device;
-(void)deviceStatus:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options;
-(void)deviceStatus:(CDVInvokedUrlCommand*)command;

# pragma mark connection delegate methods
-(void)connection:(TCConnection*)connection didFailWithError:(NSError*)error;
-(void)connectionDidStartConnecting:(TCConnection*)connection;
-(void)connectionDidConnect:(TCConnection*)connection;
-(void)connectionDidDisconnect:(TCConnection*)connection;
-(void)connectionStatus:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options;
-(void)connectionStatus:(CDVInvokedUrlCommand*)command;

# pragma mark javascript mapper methods
-(void)deviceSetup:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options;
-(void)connect:(NSArray *)arguments withDict:(NSMutableDictionary *)options;
-(void)disconnectAll:(NSArray *)arguments withDict:(NSMutableDictionary *)options;
-(void)acceptConnection:(NSArray *)arguments withDict:(NSMutableDictionary *)options;
-(void)disconnectConnection:(NSArray *)arguments withDict:(NSMutableDictionary *)options;
-(void)rejectConnection:(NSArray *)arguments withDict:(NSMutableDictionary *)options;
-(void)muteConnection:(NSArray *)arguments withDict:(NSMutableDictionary *)options;
-(void)deviceSetup:(CDVInvokedUrlCommand*)command;
-(void)connect:(CDVInvokedUrlCommand*)command;
-(void)disconnectAll:(CDVInvokedUrlCommand*)command;
-(void)acceptConnection:(CDVInvokedUrlCommand*)command;
-(void)disconnectConnection:(CDVInvokedUrlCommand*)command;
-(void)rejectConnection:(CDVInvokedUrlCommand*)command;
-(void)muteConnection:(CDVInvokedUrlCommand*)command;
-(void)sendDigits:(CDVInvokedUrlCommand*)command;
-(void)showNotification:(CDVInvokedUrlCommand*)command;
-(void)cancelNotification:(CDVInvokedUrlCommand*)command;
Expand Down
28 changes: 14 additions & 14 deletions src/ios/TCPlugin.m
Expand Up @@ -80,9 +80,9 @@ -(void)connectionDidDisconnect:(TCConnection*)connection {

# pragma mark javascript device mapper methods

-(void)deviceSetup:(NSMutableArray *)arguments withDict:(NSMutableDictionary*)options {
self.callback = [arguments pop];
self.device = [[TCDevice alloc] initWithCapabilityToken:[arguments pop] delegate:self];
-(void)deviceSetup:(CDVInvokedUrlCommand*)command {
self.callback = command.callbackId;
self.device = [[TCDevice alloc] initWithCapabilityToken:[command.arguments objectAtIndex:0] delegate:self];

// Disable sounds. was getting EXC_BAD_ACCESS
//self.device.incomingSoundEnabled = NO;
Expand All @@ -92,15 +92,15 @@ -(void)deviceSetup:(NSMutableArray *)arguments withDict:(NSMutableDictionary*)op
[self javascriptCallback:@"onready"];
}

-(void)connect:(NSArray *)arguments withDict:(NSMutableDictionary *)options {
[self.device connect:options delegate:self];
-(void)connect:(CDVInvokedUrlCommand*)command {
[self.device connect:[command.arguments objectAtIndex:0] delegate:self];
}

-(void)disconnectAll:(NSArray *)arguments withDict:(NSMutableDictionary *)options {
-(void)disconnectAll:(CDVInvokedUrlCommand*)command {
[self.device disconnectAll];
}

-(void)deviceStatus:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options {
-(void)deviceStatus:(CDVInvokedUrlCommand*)command {
NSString *state;
switch ([self.device state]) {
case TCDeviceStateBusy:
Expand All @@ -120,25 +120,25 @@ -(void)deviceStatus:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)
}

CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:state];
[self performSelectorOnMainThread:@selector(writeJavascript:) withObject:[result toSuccessCallbackString:[arguments pop]] waitUntilDone:NO];
[self performSelectorOnMainThread:@selector(writeJavascript:) withObject:[result toSuccessCallbackString:command.callbackId] waitUntilDone:NO];
}


# pragma mark javascript connection mapper methods

-(void)acceptConnection:(NSArray *)arguments withDict:(NSMutableDictionary *)options {
-(void)acceptConnection:(CDVInvokedUrlCommand*)command {
[self.connection accept];
}

-(void)disconnectConnection:(NSArray *)arguments withDict:(NSMutableDictionary *)options {
-(void)disconnectConnection:(CDVInvokedUrlCommand*)command {
[self.connection disconnect];
}

-(void)rejectConnection:(NSArray *)arguments withDict:(NSMutableDictionary *)options {
-(void)rejectConnection:(CDVInvokedUrlCommand*)command {
[self.connection reject];
}

-(void)muteConnection:(NSArray *)arguments withDict:(NSMutableDictionary *)options {
-(void)muteConnection:(CDVInvokedUrlCommand*)command {
if(self.connection.isMuted) {
self.connection.muted = NO;
} else {
Expand All @@ -150,7 +150,7 @@ -(void)sendDigits:(CDVInvokedUrlCommand*)command {
[self.connection sendDigits:[command.arguments objectAtIndex:0]];
}

-(void)connectionStatus:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options {
-(void)connectionStatus:(CDVInvokedUrlCommand*)command {
NSString *state;
switch ([self.connection state]) {
case TCConnectionStateConnected:
Expand All @@ -173,7 +173,7 @@ -(void)connectionStatus:(NSMutableArray *)arguments withDict:(NSMutableDictionar
}

CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:state];
[self performSelectorOnMainThread:@selector(writeJavascript:) withObject:[result toSuccessCallbackString:[arguments pop]] waitUntilDone:NO];
[self performSelectorOnMainThread:@selector(writeJavascript:) withObject:[result toSuccessCallbackString:command.callbackId] waitUntilDone:NO];
}


Expand Down

0 comments on commit 9dc7271

Please sign in to comment.