2017-03-20 16:38:14 -04:00
import { Injectable } from '@angular/core' ;
import { Cordova , Plugin } from '@ionic-native/core' ;
2016-09-21 15:04:46 -05:00
import { Observable } from 'rxjs/Observable' ;
2016-07-17 19:53:58 +02:00
2016-12-06 09:15:03 -05:00
export interface HttpdOptions {
/**
* The public root directory for your web server. This path is relative to your app's www directory.
* Default is current directory.
*/
www_root? : string ;
/**
* The port number to use.
* Default is 8888
*/
port? : number ;
/**
* Setting this option to false will allow remote access to your web server (over any IP).
* Default is false.
*/
localhost_only? : boolean ;
}
2016-07-17 19:53:58 +02:00
2016-06-11 00:33:02 -04:00
/**
* @name Httpd
* @description
* Embedded httpd for Cordova apps. Light weight HTTP server.
2016-06-11 02:34:08 -04:00
* @usage
2016-08-11 07:55:26 -04:00
* ```typescript
2017-03-20 16:38:14 -04:00
* import { Httpd, HttpdOptions } from '@ionic-native/httpd';
*
* constructor(private httpd: Httpd) { }
*
* ...
*
2016-08-11 07:55:26 -04:00
*
* let options: HttpdOptions = {
* www_root: 'httpd_root', // relative path to app's www directory
* port: 80,
* localhost_only: false
* };
*
2017-03-20 16:38:14 -04:00
* this.httpd.startServer(options).subscribe((data) => {
2016-08-11 07:55:26 -04:00
* console.log('Server is live');
* });
*
* ```
2016-12-06 09:15:03 -05:00
* @interfaces
* HttpdOptions
2016-06-11 00:33:02 -04:00
*/
@Plugin ( {
2016-10-27 12:48:50 -05:00
pluginName : 'Httpd' ,
2016-07-17 19:53:58 +02:00
plugin : 'https://github.com/floatinghotpot/cordova-httpd.git' ,
pluginRef : 'cordova.plugins.CorHttpd' ,
repo : 'https://github.com/floatinghotpot/cordova-httpd' ,
platforms : [ 'iOS' , 'Android' ]
2016-06-11 00:33:02 -04:00
} )
2017-03-20 16:38:14 -04:00
@Injectable ( )
2016-06-11 00:33:02 -04:00
export class Httpd {
2016-07-17 19:53:58 +02:00
/**
* Starts a web server.
* @param options {HttpdOptions}
2016-12-04 12:46:41 -05:00
* @returns {Observable<string>} Returns an Observable. Subscribe to receive the URL for your web server (if succeeded). Unsubscribe to stop the server.
2016-07-17 19:53:58 +02:00
*/
@Cordova ( {
observable : true ,
clearFunction : 'stopServer'
} )
2017-03-20 16:38:14 -04:00
startServer ( options? : HttpdOptions ) : Observable < string > { return ; }
2016-07-17 19:53:58 +02:00
/**
* Gets the URL of the running server
* @returns {Promise<string>} Returns a promise that resolves with the URL of the web server.
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
getUrl ( ) : Promise < string > { return ; }
2016-06-11 00:33:02 -04:00
2016-07-17 19:53:58 +02:00
/**
* Get the local path of the running webserver
* @returns {Promise<string>} Returns a promise that resolves with the local path of the web server.
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
getLocalPath ( ) : Promise < string > { return ; }
2016-06-11 00:33:02 -04:00
}