Skip to content

Commit

Permalink
Merge pull request #1 from Telerik-Verified-Plugins/tnikolov/livesync…
Browse files Browse the repository at this point in the history
…-integration

Integrate LocalWebServer with LiveSync plugin.
  • Loading branch information
TomaNikolov authored Nov 14, 2016
2 parents 7a9b09f + afc7932 commit 0b0bcfb
Show file tree
Hide file tree
Showing 909 changed files with 29 additions and 31,447 deletions.
Binary file added LocalWebServer.zip
Binary file not shown.
55 changes: 13 additions & 42 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,62 +29,33 @@
<dependency id="cordova-plugin-file" url="https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git" version=">=1.3.4" />

<engines>
<engine name="cordova-ios" version=">=4.1.0" />
<engine name="cordova-ios" version=">=4.0.1" />
</engines>

<!-- ios -->
<platform name="ios">

<config-file target="config.xml" parent="/*">
<feature name="CordovaLocalWebServer">
<param name="ios-package" value="CDVLocalWebServer"/>
<param name="onload" value="true"/>
</feature>
<feature name="CordovaLocalWebServer">
<param name="ios-package" value="CDVLocalWebServer"/>
<param name="onload" value="true"/>
</feature>
<preference name="CordovaLocalWebServerStartOnSimulator" value="true" />
<access origin="http://localhost" />
<access origin="http://localhost" />
<allow-navigation href="http://localhost:*/*" />
</config-file>


<header-file src="src/ios/CDVLocalWebServer.h" />
<source-file src="src/ios/CDVLocalWebServer.m" />

<header-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServer.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServerConnection.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServerFunctions.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServerHTTPStatusCodes.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServerPrivate.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServerRequest.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServerResponse.h" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServer.m" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServerConnection.m" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServerFunctions.m" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServerRequest.m" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Core/GCDWebServerResponse.m" />

<header-file src="src/ios/GCDWebServer/GCDWebServer/Requests/GCDWebServerDataRequest.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Requests/GCDWebServerFileRequest.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Requests/GCDWebServerMultiPartFormRequest.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Requests/GCDWebServerURLEncodedFormRequest.h" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Requests/GCDWebServerDataRequest.m" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Requests/GCDWebServerFileRequest.m" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Requests/GCDWebServerMultiPartFormRequest.m" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Requests/GCDWebServerURLEncodedFormRequest.m" />
<header-file src="src/ios/CDVLocalWebServer.h" />
<source-file src="src/ios/CDVLocalWebServer.m" />

<header-file src="src/ios/GCDWebServer/GCDWebServer/Responses/GCDWebServerDataResponse.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Responses/GCDWebServerErrorResponse.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Responses/GCDWebServerFileResponse.h" />
<header-file src="src/ios/GCDWebServer/GCDWebServer/Responses/GCDWebServerStreamedResponse.h" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Responses/GCDWebServerDataResponse.m" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Responses/GCDWebServerErrorResponse.m" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Responses/GCDWebServerFileResponse.m" />
<source-file src="src/ios/GCDWebServer/GCDWebServer/Responses/GCDWebServerStreamedResponse.m" />

<framework src="AssetsLibrary.framework" />
<framework src="MobileCoreServices.framework" />
<framework src="CFNetwork.framework" />
<framework src="AssetsLibrary.framework" />
<framework src="MobileCoreServices.framework" />
<framework src="CFNetwork.framework" />
<framework src="libz.dylib" />

<dependency id="cordova-plugin-webserver" />

<info>
Your content tag in config.xml now points to a http://localhost:0 location (randomized port), e.g. &lt;content src="http://localhost:0" /&gt;
WARNING: For localStorage and IndexedDB persistence, you must choose a non-randomized port (between 1 and 49152, to avoid the ephemeral port range 49152 to 65535 on iOS).
Expand Down
2 changes: 1 addition & 1 deletion src/ios/CDVLocalWebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

#import <Cordova/CDVPlugin.h>
#import "GCDWebServer.h"
#import <GCDWebServer/GCDWebServer.h>

@interface CDVLocalWebServer : CDVPlugin

Expand Down
21 changes: 15 additions & 6 deletions src/ios/CDVLocalWebServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Licensed to the Apache Software Foundation (ASF) under one
*/

#import "CDVLocalWebServer.h"
#import "GCDWebServerPrivate.h"
#import <GCDWebServer/GCDWebServerPrivate.h>
#import <Cordova/CDVViewController.h>
#import <Cordova/NSDictionary+CordovaPreferences.h>
#import <AssetsLibrary/AssetsLibrary.h>
Expand All @@ -38,6 +38,8 @@ - (GCDWebServerResponse*)_responseWithContentsOfDirectory:(NSString*)path;

@implementation CDVLocalWebServer

NSString *const ServerCreatedNotificationName = @"WKWebView.WebServer.Created";

- (void) pluginInitialize {

BOOL useLocalWebServer = NO;
Expand Down Expand Up @@ -72,7 +74,7 @@ - (void) pluginInitialize {
}
}
#endif

if (port == 0) {
// CB-9096 - actually test for an available port, and set it explicitly
port = [self _availablePort];
Expand All @@ -81,6 +83,7 @@ - (void) pluginInitialize {
NSString* authToken = [NSString stringWithFormat:@"cdvToken=%@", [[NSProcessInfo processInfo] globallyUniqueString]];

self.server = [[GCDWebServer alloc] init];
self.server.delegate = (id<GCDWebServerDelegate>)self;
[GCDWebServer setLogLevel:kGCDWebServerLoggingLevel_Error];

if (useLocalWebServer) {
Expand All @@ -89,7 +92,7 @@ - (void) pluginInitialize {
// add after server is started to get the true port
[self addFileSystemHandlers:authToken];
[self addErrorSystemHandler:authToken];

// handlers must be added before server starts
[self.server startWithPort:port bonjourName:nil];

Expand All @@ -102,7 +105,7 @@ - (void) pluginInitialize {
NSLog(@"%@", error);

[self addErrorSystemHandler:authToken];

// handlers must be added before server starts
[self.server startWithPort:port bonjourName:nil];

Expand Down Expand Up @@ -132,7 +135,7 @@ - (NSUInteger) _availablePort
return ntohs(sockaddr->sin_port);
}
}

return 0;
}

Expand Down Expand Up @@ -170,7 +173,7 @@ - (void) addFileSystemHandlers:(NSString*)authToken
if ([self.commandDelegate respondsToSelector:sel]) {
NSURL* (^urlTransformer)(NSURL*) = ^NSURL* (NSURL* urlToTransform) {
NSURL* localServerURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:%lu", (unsigned long)weakSelf.server.port]];

NSURL* transformedUrl = urlToTransform;

NSString* localhostUrlString = [NSString stringWithFormat:@"http://localhost:%lu", (unsigned long)[localServerURL.port unsignedIntegerValue]];
Expand Down Expand Up @@ -364,5 +367,11 @@ - (void) addErrorSystemHandler:(NSString*)authToken
[self addFileSystemHandler:processRequestBlock basePath:basePath authToken:authToken cacheAge:0];
}

#pragma mark GCDWebServerDelegate

- (void)webServerDidStart:(GCDWebServer*)server {
[NSNotificationCenter.defaultCenter postNotificationName:ServerCreatedNotificationName
object:@[self.viewController, self.server]];
}

@end
6 changes: 0 additions & 6 deletions src/ios/GCDWebServer/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions src/ios/GCDWebServer/.travis.yml

This file was deleted.

52 changes: 0 additions & 52 deletions src/ios/GCDWebServer/Frameworks/GCDWebServers.h

This file was deleted.

22 changes: 0 additions & 22 deletions src/ios/GCDWebServer/Frameworks/Info.plist

This file was deleted.

24 changes: 0 additions & 24 deletions src/ios/GCDWebServer/Frameworks/Tests.m

This file was deleted.

Loading

0 comments on commit 0b0bcfb

Please sign in to comment.