Skip to content

Commit

Permalink
Initial iOS support. Added dependency on CN1JSON.cn1lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
shannah committed Aug 13, 2020
1 parent 78ee97c commit 1271753
Show file tree
Hide file tree
Showing 33 changed files with 14,983 additions and 10 deletions.
1 change: 1 addition & 0 deletions IosRtcPlugin
Submodule IosRtcPlugin added at 1a078e
6 changes: 6 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ Currently (July 27, 2020) it works on:
. Android
. Simulator (https://www.codenameone.com/blog/big-changes-jcef.html[requires CEF to be installed])
. Javascript (Desktop and Android Chrome)
. iOS (experimental. Some demos not working yet.)

== Dependencies

. CN1JSON.cn1lib

== Installation

. Copy https://github.com/shannah/CN1WebRTC/blob/master/bin/webrtc.cn1lib[webrtc.cn1lib] into your project's "lib" directory.
. Copy https://github.com/shannah/CN1WebRTC/blob/master/lib/CN1JSON.cn1lib[CN1JSON.cn1lib] into your project's "lib" directory.
. Refresh Cn1libs

== Demo
Expand Down
8 changes: 4 additions & 4 deletions Versions.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
#Fri Jul 24 08:09:37 PDT 2020
#Thu Aug 13 08:20:06 PDT 2020
CodeNameOneBuildClientJar=105
CodenameOne_SRCzip=137
CodenameOneJar=137
JavaSEJar=137
CodenameOne_SRCzip=140
CodenameOneJar=140
JavaSEJar=140
CLDC11Jar=108
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
vendor="${codename1.vendor}"
subtitle="${codename1.secondaryTitle}"

targetType="iphone"
targetType="debug_iphone_steve"
certificate="${codename1.ios.debug.certificate}"
certPassword="${codename1.ios.debug.certificatePassword}"
provisioningProfile="${codename1.ios.debug.provision}"
Expand Down
Binary file added lib/CN1JSON.cn1lib
Binary file not shown.
1 change: 1 addition & 0 deletions lib/CN1JSON.ver
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=4
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.codename1.webrtc.compat.cordova;

public class CordovaNativeImpl implements com.codename1.webrtc.compat.cordova.CordovaNative{
public boolean execute(String param, String param1, String param2) {
return false;
}

public void pluginInitialize(com.codename1.ui.PeerComponent param) {
}

public void dispose() {
}

public boolean isSupported() {
return false;
}

}
7 changes: 6 additions & 1 deletion webrtc/codenameone_library_appended.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
#is an appended type property.
#
#Wed Jan 09 17:59:31 IST 2013
codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.RECORD_AUDIO" android\:required\="true" /> <uses-permission android\:name\="android.permission.MODIFY_AUDIO_SETTINGS" android\:required\="true" /> <uses-permission android\:name\="android.permission.CAMERA" android\:required\="true" /> <uses-feature android\:name\="android.hardware.audio.low_latency" android\:required\="true" /> <uses-feature android\:name\="android.hardware.audio.pro" android\:required\="true" />\\ <uses-feature android\:name\="android.hardware.microphone" android\:required\="true"/> <uses-feature android\:name\="android.hardware.camera" android\:required\="true" /> <uses-feature android\:name\="android.hardware.camera.autofocus" android\:required\="true"/> <uses-feature android\:name\="android.hardware.camera.front" android\:required\="true" />
codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.RECORD_AUDIO" android\:required\="true" /> <uses-permission android\:name\="android.permission.MODIFY_AUDIO_SETTINGS" android\:required\="true" /> <uses-permission android\:name\="android.permission.CAMERA" android\:required\="true" /> <uses-feature android\:name\="android.hardware.audio.low_latency" android\:required\="true" /> <uses-feature android\:name\="android.hardware.audio.pro" android\:required\="true" />\\ <uses-feature android\:name\="android.hardware.microphone" android\:required\="true"/> <uses-feature android\:name\="android.hardware.camera" android\:required\="true" /> <uses-feature android\:name\="android.hardware.camera.autofocus" android\:required\="true"/> <uses-feature android\:name\="android.hardware.camera.front" android\:required\="true" />
#codename1.arg.ios.pods=,Cordova ~> 6.1
codename1.arg.ios.pods=,Cordova ~> 6.1
codename1.arg.ios.pods.platform=,11.0
codename1.arg.ios.pods.build.CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES=YES
codename1.arg.ios.pods.build.CLANG_ENABLE_MODULES=YES
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.codename1.webrtc.compat.cordova;

public class CordovaNativeImpl {
public boolean execute(String param, String param1, String param2) {
return false;
}

public void pluginInitialize(android.view.View param) {
}

public void dispose() {
}

public boolean isSupported() {
return false;
}

}
Binary file added webrtc/native/ios/IosRtcPlugin.framework.zip
Binary file not shown.
29 changes: 29 additions & 0 deletions webrtc/native/ios/IosrtcPluginCommandDelegateImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

#import <UIKit/UIKit.h>
#import <Cordova/CDVCommandDelegate.h>

@class CDVViewController;

@interface IosrtcPluginCommandDelegateImpl : NSObject <CDVCommandDelegate>{

}

@end
129 changes: 129 additions & 0 deletions webrtc/native/ios/IosrtcPluginCommandDelegateImpl.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/

#import "CDVCommandDelegateImpl.h"
#import "CDVCommandQueue.h"
#import "CDVPluginResult.h"
#import "CDVViewController.h"
#import "com_codename1_webrtc_compat_cordova_CordovaCallbackManager.h"

@implementation IosrtcPluginCommandDelegateImpl : NSObject

//@synthesize urlTransformer;


- (NSString*)pathForResource:(NSString*)resourcepath
{
return nil;
}

- (void)flushCommandQueueWithDelayedJs
{
//_delayResponses = YES;
//[_commandQueue executePending];
//_delayResponses = NO;
}

- (void)evalJsHelper2:(NSString*)js
{

}

- (void)evalJsHelper:(NSString*)js
{

}

- (BOOL)isValidCallbackId:(NSString*)callbackId
{

return YES;
}

- (void)sendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId
{
CDV_EXEC_LOG(@"Exec(%@): Sending result. Status=%@", callbackId, result.status);
// This occurs when there is are no win/fail callbacks for the call.
if ([@"INVALID" isEqualToString:callbackId]) {
return;
}
// This occurs when the callback id is malformed.
if (![self isValidCallbackId:callbackId]) {
NSLog(@"Invalid callback id received by sendPluginResult");
return;
}
int status = [result.status intValue];
BOOL keepCallback = [result.keepCallback boolValue];
NSString* argumentsAsJSON = [result argumentsAsJSON];
BOOL debug = NO;
BOOL isSuccess = [result.status intValue] == 0 || [result.status intValue] == 1;
#ifdef DEBUG
debug = YES;
#endif

//NSString* js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeCallback('%@',%d,%@,%d, %d)", callbackId, status, argumentsAsJSON, keepCallback, debug];

//[self evalJsHelper:js];
//NSLog(@"Result %@", argumentsAsJSON);
//public static void sendResult(String callbackId, boolean isSuccess, int status, String args, boolean keepCallback){
com_codename1_webrtc_compat_cordova_CordovaCallbackManager_sendResult___java_lang_String_boolean_int_java_lang_String_boolean(
CN1_THREAD_GET_STATE_PASS_ARG
fromNSString(CN1_THREAD_GET_STATE_PASS_ARG callbackId),
isSuccess,
[result.status intValue],
fromNSString(CN1_THREAD_GET_STATE_PASS_ARG argumentsAsJSON),
keepCallback
);

}

- (void)evalJs:(NSString*)js
{
//[self evalJs:js scheduledOnRunLoop:YES];
}

- (void)evalJs:(NSString*)js scheduledOnRunLoop:(BOOL)scheduledOnRunLoop
{

}

- (id)getCommandInstance:(NSString*)pluginName
{
//return [_viewController getCommandInstance:pluginName];
return nil;
}

- (void)runInBackground:(void (^)())block
{
//dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
}

- (NSString*)userAgent
{
//return [_viewController userAgent];
return nil;
}

- (NSDictionary*)settings
{
//return _viewController.settings;
return nil;
}

@end
Binary file added webrtc/native/ios/WebRTC.framework.zip
Binary file not shown.
3 changes: 3 additions & 0 deletions webrtc/native/ios/com_codename1_webrtc_WebRTCNativeImpl.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#import "com_codename1_webrtc_WebRTCNativeImpl.h"


@implementation com_codename1_webrtc_WebRTCNativeImpl

-(void)requestPermissions:(NSString*)param param1:(BOOL)param1 param2:(BOOL)param2{

}

-(BOOL)isSupported{
return NO;
}


@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import <Foundation/Foundation.h>

@class iosrtcPlugin;

@interface com_codename1_webrtc_compat_cordova_CordovaNativeImpl : NSObject {

iosrtcPlugin* _iosrtcPlugin;
}
-(void)pluginInitialize:(UIView*)param;
-(void)dispose;
-(BOOL)execute:(NSString*) callbackId param1:(NSString*)action param2:(NSString*)data;
-(BOOL)isSupported;
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#import <Foundation/Foundation.h>
#import "com_codename1_webrtc_compat_cordova_CordovaNativeImpl.h"
#import "IosrtcPluginCommandDelegateImpl.h"
#import <objc/message.h>
#import <WebKit/WebKit.h>
@import IosRtcPlugin;



@implementation com_codename1_webrtc_compat_cordova_CordovaNativeImpl



-(iosrtcPlugin*)getIosrtcPlugin {

return _iosrtcPlugin;
}


-(void)pluginInitialize:(UIView*)param {
WKWebView* webView = (WKWebView*)param;
if (_iosrtcPlugin == nil) {
_iosrtcPlugin = [[iosrtcPlugin alloc] init];
//[_iosrtcPlugin setValue:webView forKey:@"webView"];
[_iosrtcPlugin setWebView:webView];
_iosrtcPlugin.commandDelegate = [[IosrtcPluginCommandDelegateImpl alloc] init];
[_iosrtcPlugin pluginInitialize];
}
}
-(void)dispose {
if (_iosrtcPlugin != nil) {
[_iosrtcPlugin setWebView:nil];
_iosrtcPlugin.commandDelegate = nil;
[_iosrtcPlugin dispose];
_iosrtcPlugin = nil;

}
}
-(BOOL)execute:(NSString*) callbackId param1:(NSString*)param1 param2:(NSString*)param2{
//-(BOOL)execute:(NSString*)param param1:(NSString*)param1{
if (![NSThread isMainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self execute:callbackId param1:param1 param2:param2];

});
return YES;
}
NSData* data = [param2 dataUsingEncoding:NSUTF8StringEncoding];
NSError *e;
NSArray *array = nil;
if (param2 == nil || [param2 length] == 0) {
array = [NSArray array];
} else {
array = [NSJSONSerialization JSONObjectWithData:data options:nil error:&e];
}
CDVInvokedUrlCommand* command = [[CDVInvokedUrlCommand alloc] initWithArguments:array callbackId:callbackId className:@"iosrtcPlugin" methodName:param1];
return [self execute:command];
}

- (BOOL)execute:(CDVInvokedUrlCommand*)command
{
BOOL retVal = YES;
double started = [[NSDate date] timeIntervalSince1970] * 1000.0;
CDVPlugin* obj = [self getIosrtcPlugin];
NSString* methodName = [NSString stringWithFormat:@"%@:", command.methodName];
SEL normalSelector = NSSelectorFromString(methodName);
if ([obj respondsToSelector:normalSelector]) {
((void (*)(id, SEL, id))objc_msgSend)(obj, normalSelector, command);
} else {
// There's no method to call, so throw an error.
NSLog(@"ERROR: Method '%@' not defined in Plugin '%@'", methodName, command.className);
retVal = NO;
}
double elapsed = [[NSDate date] timeIntervalSince1970] * 1000.0 - started;
if (elapsed > 10) {
NSLog(@"THREAD WARNING: ['%@'] took '%f' ms. Plugin should use a background thread.", command.className, elapsed);
}
return retVal;
}
-(BOOL)isSupported{
return YES;
}

-(void)dealloc {
if (_iosrtcPlugin != nil) {
[_iosrtcPlugin dispose];
_iosrtcPlugin = nil;
}
[super dealloc];
}
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.codename1.webrtc.compat.cordova;

public class CordovaNativeImpl {
public boolean execute(String param, String param1, String param2) {
return false;
}

public void pluginInitialize(Object param) {
}

public void dispose() {
}

public boolean isSupported() {
return false;
}

}
Loading

0 comments on commit 1271753

Please sign in to comment.