new WindowManager(type, initialize)
Message utils takes care of messaging between multiple windows. Messages can be transfered direcly or forwarded between windows.
Is responsible for keeping track of all sessions, handles message reception, message forwarding and message sending.
When a window is open it cannot be acessed we need to wait for the ready message.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | Type of this window. |
initialize |
Boolean | Indicates if the manager should be automatically initialized, by default its true. If you want to manually initialize the manager later to avoid loosing message set to false. |
- Source:
Members
(static) generateUUID
Generate a UUID used to indetify the window manager.
.toUpperCase() here flattens concatenated strings to save heap memory space.
http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
- Source:
manager :EventManager
Event manager containing the message handling events for this manager.
Type:
- Source:
onBroadcastMessage
On broadcast message callback, receives data and authentication as parameters.
Called when a broadcast message arrives, onBroadcastMessage(data, authentication).
type {Function}
- Source:
onMessage
Global manager on message callback, receives type, data and authentication as parameters.
This onMessage callback is always called before the individual session callback.
It might be used for globally handling authentication tasks.
type {Function}
- Source:
sessions :Object
Map of known sessions.
Indexed by the UUID of the session.
Type:
- Object
- Source:
type :String
Type of this window manager object.
Type:
- String
- Source:
uuid :String
UUID of this window manager.
Used to identify this window on communication with another windows.
Type:
- String
- Source:
waitingSessions :Array
List of sessions in waiting state.
These still havent reached the READY state.
Type:
- Array
- Source:
Methods
broadcast(data, authentication)
Broadcast a message to all available sessions.
The message will be passed further on by the other windows that receive it.
Parameters:
Name | Type | Description |
---|---|---|
data |
WindowMessage | Data to be broadcasted. |
authentication |
String | Authentication information. |
- Source:
checkOpener() → {WindowSession}
Send an acknowledge message.
Used to send a signal indicating the parent window that it is ready to receive data.
- Source:
Returns:
Session fo the opener window, null if the window was not opened.
- Type
- WindowSession
dispose()
Dispose the window manager.
Should be called when its not used anymore. Destroy all the window events created by the manager.
- Source:
getSession(type) → {WindowSession}
Get a session from the manager from its type.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | Type of the window to get. |
- Source:
Returns:
Session of the type specified, null if none was found.
- Type
- WindowSession
initialize() → {WindowSession}
Initialized the manager message handler, checks for the opener window and sends acknowledge message to waiting sessions.
By default it is automatically called on the constructor. But sometimes it might be usefull to initialize the window later on to avoid loosing messages.
Be carefull to specify all the global callbacks before calling this method.
- Source:
Returns:
If this window was opened by another one it returns the respective session. Returns null otherwise.
- Type
- WindowSession
logSessions()
Log to the console a list of all known sessions.
Useful for debug purposes.
- Source:
lookup(type, onFinish)
Lookup for a window type.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | Type of the window to look for. |
onFinish |
String | Receives the gateway session, found uuid and type as parameters onFinish(session, uuid, type), if null no window of the type was found. |
- Source:
openSession(url, type) → {WindowSession}
Create a new session with a new window from URL and type.
Before opening a new window it searches for a window of the same type in the known sessions.
If a session of the same type already exists it is returned.
Parameters:
Name | Type | Description |
---|---|---|
url |
String | URL of the window. |
type |
String | Type of the window to open (Optional). |
- Source:
Returns:
Session created to open a new window.
- Type
- WindowSession
sessionAvailable(type) → {Boolean}
Check if a session of a type exists and its available for message exchanging.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | Type of the window to check. |
- Source:
Returns:
True if a session of the type requested exists, false otherwise.
- Type
- Boolean
sessionExists(type) → {Boolean}
Check if a session of a type exists.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | Type of the window to check. |
- Source:
Returns:
True if a session of the type requested exists, false otherwise.
- Type
- Boolean
wasOpened() → {Boolean}
Check if this window was opened by another one.
- Source:
Returns:
True if the window was opened by another window, false otherwise.
- Type
- Boolean