This standard is versioned using Semantic Versioning. The version number is
defined in package.json
file.
The main communication channel between Platform and Project is window.postMessage
method.
In the context of this standard, we call these messages "signals".
Platform can send signal to Project and Project can send signal to Platform.
Signal is a valid JSON object that required to have a type
field which value should be
the following string:
gps:[f|b]:[message-type]
Where:
gps:
is a type namespace (meaning "Generative Platform Standard")f:
orb:
is a direction of the signalf:
(forward) indicates a signal from Platform to Projectb:
(backward) indicates a signal from Project to Platform
Additional fields are optional and depend on the signal type.
This signal should be sent from Platform to Project to initialize the communication channel.
After the message is received by Project it should send a gps:b:init
message back to Platform.
Version of the standard should be specified in the v
field. It is allowed to omit minor and patch numbers if
they are zero (e.g. "1"
instead of "1.0.0""
).
{
"type": "gps:f:init",
"v": "1"
}
This signal should be sent from Project to Platform in response to gps:f:init
message.
As a payload, it should contain additional field "implementsSignals"
which should ab an array
of all possible signals (both forward and backward) that are supported by this project.
{
"type": "gps:b:init",
"implementsSignals": [
{
"type": "gps:f:download",
"key": "download-small",
"text": "512 x 515"
},
{
"type": "gps:f:download",
"key": "download-medium",
"text": "1024 x 1024"
},
{
"type": "gps:b:load-compl",
},
{
"type": "gps:b:capt-prev",
}
]
}
This signal should be sent from Project to Platform when the project is ready to be rendered. As a result, Platform should hide the loading indicator and show the project.
{
"type": "gps:b:load-compl"
}
This signal should be sent from Project to Platform when the project is ready to be captured. It is especially important for projects that have some kind of animation. Platform can use this signal in order to make a screenshot of a Project.
{
"type": "gps:b:capt-prev"
}
This signal should be sent from Platform to Project when the user clicks on the download button.
Therefore, Project should generate a data url with the image and send it back to Platform via gps:b:download
signal.
Two additional properties that can exists are key
and text
. key
is a unique identifier of the
download option and text
is a text that should be displayed to the user. It is helpful when
Project supports multiple download options (e.g. different sizes of the image).
{
"type": "gps:f:download",
"key": "download-medium",
"text": "1024 x 1024"
}
Project should reply on gps:f:download
signal with this signal. It should contain a data url
with the image that should be downloaded. Projects are supposed to be used with sandbox
attribute,
so it is not possible to download the image directly from the Project. Two required properties
are dataUrl
and ext
. dataUrl
is a data url with the image and ext
is a file extension of the image.
{
"type": "gps:b:download",
"dataUrl": "...",
"ext": "png"
}