Skip to content

Commit

Permalink
Add API section
Browse files Browse the repository at this point in the history
  • Loading branch information
fastner committed Aug 4, 2017
1 parent 0a9b9d9 commit 853c28d
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,88 @@ channel2

`response()` is a shortcut of send with preset namespace of source message.

# API

````
function interframe(targetWindow, [origin = "*"])
returns
{
addListener,
removeListener,
send,
hasHandshake
}
````

This factory function returns a channel.



````
function addListener(callback)
returns
callback
````

Add callback for new messages. callback is a function with the signature
`(message) => {}`



````
function removeListener(callback)
````

Disconnect specific callback from message events.



````
function send(namespace, [data])
returns
Promise<message>
````

Send message to opposite side. `namespace` is a string that defines the type
of the message. `data` is an optional argument that must be serializable by
`JSON.stringify`.

The returned message consists of
````
{
id,
data,
namespace,
response,
}
````

- id is the id of the message
- data is the optional data object (given in send())
- namespace is the namespace (given in send())

The promise only resolves if the `response()`function of the message inside addListener callback is used.

````
function hasHandshake([callback])
returns
boolean
````

Returns if handshake is successfull. An optional callback is called as
soon as there is a handshake.


## Copyright

<img src="https://raw.githubusercontent.com/sebastian-software/s15e-javascript/master/assets/sebastiansoftware.png" alt="Sebastian Software GmbH Logo" width="250" height="200"/>

Copyright 2016-2017<br/>[Sebastian Software GmbH](http://www.sebastian-software.de)
Copyright 2016-2017<br/>[Sebastian Software GmbH](http://www.sebastian-software.de)

0 comments on commit 853c28d

Please sign in to comment.