Dev.Opera - Follow the standards, break the rulesDev.Opera - Follow the standards, break the rules

Login

Lost password?



Class opera.io.webserver

Object
   |
   +--opera.io.webserver

class opera.io.webserver


Web server implementation

The WebServer offers access to information about the proxy, device and currently running service. It also maintains incoming connections.

Services running on the Web server are accessed through a URL on the form: http://device.host.proxy/service/path, e.g. http://work.john.operaunite.com/wiki/addEntry


Defined in unite.js


Field Summary
Object connections
The current connections made to this Web server.
String currentServiceName
The name of the service currently accessing the webserver object, for example 'File Sharing'.
String currentServicePath
The path of the service currently accessing the webserver object, for example '/fileSharing/'.
String deviceName
The name of the device the Web server is running on, for example 'work'.
String hostName
The hostname of the Webserver, for example 'work.john.operaunite.com'.
string originURL
The URL the currently running service was downloaded from.
String port
The port this Web server is listening to, for example 8840.
String proxyName
The name of the proxy the Web server is connected to, for example 'operaunite.com'.
String publicIP
The public facing IP address of this Web server, as seen by the proxy.
int publicPort
The public facing port of this Web server, as seen by the proxy.
Object services
Services running on this Web server.
String userName
The My Opera user name of the user owning the Web server, for example 'john'.
Constructor Summary
opera.io.webserver ()
This class has no constructor.
Method Summary
void addEventListener( <String> pathFragment, <Function> handler, <boolean> useCapture )
Add an event listener for incoming requests.
String getContentType( <String> file )
Get the MIME content type mapped to a particular file name.
void removeEventListener( <String> pathFragment, <Function> handler, <boolean> useCapture )
Remove an event listener from the server.
void shareFile( <File> file, <String> path )
Shares a File
void sharePath( <String> path, <File> file )
Share the given file on the given URL path.
void unshareFile( <File> file )
Unshares a previously shared file
void unsharePath( <String> path )
Unshare a File previously shared on the given URL path
Field Detail

connections

Object connections
The current connections made to this Web server. Readonly.

Array-like object containing WebServerConnection objects representing the current connections to this Web server.

Connections remain in this collection even if they are closed. They are removed when there are no longer any references to the connection elsewhere in the system.


currentServiceName

String currentServiceName
The name of the service currently accessing the webserver object, for example 'File Sharing'. Readonly.

The name of the service, for example as defined in the widgetname element in the config.xml of a Opera Unite application.


currentServicePath

String currentServicePath
The path of the service currently accessing the webserver object, for example '/fileSharing/'. Readonly.

The path of the service, for example as defined in the servicePath element in the config.xml of an Opera Unite application. In contrast to the serviceName, this name can only contain characters that are valid in an IRI.

The path includes a leading and trailing slash.

This way a service called "My Cool File Sharing (tm) (c)" can be identified as simply "share" in it's URL, i.e. http://work.john.operaunite.com/share.

In the example above this property would contain '/share/'.

Note that anything after the first path component is handled by the service.


deviceName

String deviceName
The name of the device the Web server is running on, for example 'work'. Readonly. You may run a Web server on different devices, like two different computers in your home network and your mobile phone, e.g. work as in http://work.john.operaunite.com.

hostName

String hostName
The hostname of the Webserver, for example 'work.john.operaunite.com'. Readonly.

You may run Web servers on different devices. The hostname contains the device name, username and proxy address, for example work.john.operaunite.com as in http://work.john.operaunite.com/wiki.

Note that this will always be a host name which contains the proxy name.

This property will not contain the 'admin.' subdomain, if it is used.


originURL

string originURL
The URL the currently running service was downloaded from. Readonly.

This property can be used to make a download link to the service and can also function as part of an auto update scheme.


port

String port
The port this Web server is listening to, for example 8840. Readonly. You may run multiple Web servers from the same computer by assigning different port numbers and device names to each instance of Opera running the Web server in opera:config. Valid ports are in the range 0-65536

proxyName

String proxyName
The name of the proxy the Web server is connected to, for example 'operaunite.com'. Readonly. The proxy name is the last part of the full host name, e.g. operaunite.com as in http://work.john.operaunite.com/wiki

publicIP

String publicIP
The public facing IP address of this Web server, as seen by the proxy. If the Web server does not accept direct connections, this property is null.

publicPort

int publicPort
The public facing port of this Web server, as seen by the proxy. If the Web server does not accept direct connections, this property is null.

services

Object services
Services running on this Web server. Readonly. Array-like object containing WebServerServiceDescriptor objects that describe the services currently running on this device. You can use this property to discover and communicate with other services, and potentially share data with them.

userName

String userName
The My Opera user name of the user owning the Web server, for example 'john'. Readonly. For authentication purposes, a My Opera user name is required for connecting to the proxy and publishing services.

Constructor Detail

opera.io.webserver

opera.io.webserver()
This class has no constructor.

Method Detail

addEventListener

void addEventListener( <String> pathFragment, <Function> handler, <boolean> useCapture )
Add an event listener for incoming requests.

Listening for requests is done by registering event listeners on the Web server. The "event name" corresponds to the path fragment of the URL after the service name, e.g. 'add' as in http://work.john.operaunite.com/wiki/add.

Registered event handlers are called with an event of the type WebServerRequestEvent.

Any request names starting with underscore ('_') is reserved and cannot be used.

The exceptions are the following request names, which have special meanings:

_index
Event fired when a user accesses the root of the service (i.e. http://work.john.operaunite.com/wiki). Use this to supply a default start page or similar for your service.
_request
Event fired when a user accesses any URL under the service. Use this to catch all requests to the server in a general fashion. You'll need to use the WebServerRequest.uri to distinguish the actual request URI. Listening for this event will also catch the _index request, but not _close.
_close
Event fired when a connection is closed. In this case the connection property of the event object is null.

Events for specific event listeners and _index events are fired before the _request event is fired. Consider the following code example:

opera.io.webserver.addEventListener('_request', generalhandler, false);
opera.io.webserver.addEventListener('add', addhandler, false);

The handlers for a specific path, including _index is called before _request.

If the user visits the URL http://work.john.operaunite.com/wiki/add, a WebServerRequestEvent is fired, and the addhandler is called, before the generalhandler method is called. This happens regardless of which event listener was registered first.

Parameters:
pathFragment - Path fragment to add a listener for.
handler - Event listener function to add.
useCapture - Whether or not the capture phase should be used.

getContentType

String getContentType( <String> file )
Get the MIME content type mapped to a particular file name. This function looks up the MIME content type associated with the given file name in Opera. It can for example be used to set proper headers when serving special types of files. The file name must contain a period ('.').
Parameters:
file - The file name to get a MIME type for, for example 'index.html'.
Returns:
The MIME content type mapped to the given file name.

removeEventListener

void removeEventListener( <String> pathFragment, <Function> handler, <boolean> useCapture )
Remove an event listener from the server.
Parameters:
pathFragment - Path fragment to remove a listener for.
handler - Event listener function to remove.
useCapture - Whether or not this applies to the capture phase.

shareFile

void shareFile( <File> file, <String> path )
Shares a File

Shares a File from a mountpoint that has been acquired earlier, and makes it available under the path specified in the second argument.

The File can be a regular file, a directory or an archive.

The share is automatically deleted when the application is closed.

Example: If you have resolved a File to a given folder and then specify opera.io.webserver.shareFile(myFile, 'share'), it will be shared as the URL http://device.user.proxy/service/share

Parameters:
file - The File to share
path - The path this file will be shared as on the Web.
Deprecated This function will be removed shortly. Use sharePath() instead.

sharePath

void sharePath( <String> path, <File> file )
Share the given file on the given URL path.

The path must be a valid URL path token, and should be a relative sub path of the service. It should not start with '../' or '/', but you may specify additional path tokens, like 'media/gfx/logo.png'.

The File can be a regular file, a directory or an archive, but it must be referenced by a mount point.

ALREADY_SHARED_ERR will be thrown if something is already shared on the given path The share is automatically deleted when the application is closed.

Note that if you have added a _request event handler, you will need to compare the incoming requests with the paths you have shared to see if the request matches a shared file. If so, you will need to call WebServerResponse.closeAndRedispatch() without changing the uri fo the request to send the request back to the Web server. On the second pass, the Web server will serve the shared file directly.

Example: In order to share a resolved File on the path 'media/gfx', you would do the following:

opera.io.webserver.sharePath('media/gfx', myFile);

The file will now be shared as the URL http://device.user.proxy/service/media/gfx.

Parameters:
path - URL path to share something on.
file - File to share on the given path.
Throws:
- ALREADY_SHARED_ERR if something is already shared on the given path.

unshareFile

void unshareFile( <File> file )
Unshares a previously shared file When a file has been shared using shareFile, it can be unshared again by calling this method with the same File reference used to share the file
Parameters:
file - The file to unshare.
Deprecated This function will be removed shortly. Use unsharePath() instead.

unsharePath

void unsharePath( <String> path )
Unshare a File previously shared on the given URL path

When a file has been shared using sharePath(), it can be unshared again by calling this method with the same path used to share the file.

Example: Assume that a file has been shared on the path 'media/gfx', i.e. on the URL http://device.user.proxy/service/media/gfx/, calling this method as follows will unshare the file:

opera.io.webserver.unsharePath('media/gfx');
Parameters:
path - URL path of the file to unshare.



Documentation generated by JSDoc on Tue Oct 6 11:14:47 2009

Libraries