Coder Social home page Coder Social logo

generative-platform-standard's People

Contributors

augustdev avatar sergyperov avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

generative-platform-standard's Issues

Ability to get Project Output's traits/features

Given our latest discussion about custom titles for editions, I assume it would be great to send additional metadata such as output's features, e.g.:

"generativePlatformStandard": {
    "id": "1337",
    "type": "READY",
    "payload": {
        "traits": [
            {
                "name": "title",
                "value": "Random output with RED SKY #33"
            }
            {
                "name": "sunColor",
                "value": "red"
            }
        ]
    }
}

I assume there shouldn't be an API methid to fetch all possible traits, because there is a chance Project is not aware of all outputs. Therefore list of all various is usually cradfted by Platform based on all generated Project's outputs.

Issues in current implemention

Had a chance to look at the current implementation! Here's some important issues I've seen:

  1. Access to contentWindow
    get implementsPreviewCaptureTrigger() {
    return (
    this.iframe?.contentWindow?.$implementsPreviewCaptureTrigger || false
    );
    }

Such code won't work when we deal with different domains (because you can't read window content of another origin in most cases). I've proposed solution to this problem in #1 (point 1).

  1. Dealing with multiple projects
    if (iframeSelector.contentWindow.$implementsDelegatedLoading) {
    const strongRef = this;
    window.addEventListener("message", function (event) {
    if (event.data === "loading-complete") {
    strongRef.onLoadingComplete();
    }
    });

In case there are more then one Project on page, current window will receive multiple events, and this implementation doesn't distinguish from which partiluar iframe we got the event. I proposed a solution to this problem in #1 (point 2)

Rethink who should be responsible for initiating download

Given some Platforms can use sandbox mode on their iframe we should either:

  • request all Platforms to include sandbox="... allow-downloads"
  • change standard to request Projects to send binary file over postMessage, so Platform can initiate download itself

Feature flags and better `postMessage` handling

The Standard looks nice! I think we should keep it simple and target to provide solutions for the most commonly used cases!

Here are some suggestions I would like to discuss:

  1. Sending feature flags. The idea of feature flags is great, but the current implementation of setting window of iframe wouldn't work in case iframe has another origin (which I assume is quite a common case):
// parent won't be able to read it in case it has another origin
window.$implementsDelegatedLoading = true;

Therefore we probably want to use postMessage for this purpose:

function initialiseGenerativePlatformStandard(config) {
  const initMessage = {
    generativePlatformStandard: {
      id: "some-id",
      type: "init",
      config,
    }
  }
  window.parent.postMessage(initMessage, "*");
}

So original platform will listen to this event.

  1. Sending stringified JSON instead of plain text.
    What do you think about communicating in JSON format instead of plain text? My assumption is that this way is more structured and will give the ability to add payload in the future in a better way. Also, it's easier to distinguish messages within this standard (simply check JSON.parse(event.message).generativePlatformStandard, of cause with try-catch to handle cases when a message is not stringified JSON. So my proposal is to use the format:
{
  "generativePlatformStandard": {
    "id": "SOME ID TO HANDLE MULTIPLE PROJECTS ON SAME PAGE",
    "type": "SOME_TYPE",
    // anything else needed, depending on type
  }
}

You can notice I've added "id" field as well. There should be a way to manage multiple projects in the same window. I assume we can't access the actual URL that emitted this event (we can get only the origin), as well as accessing contentWindow wouldn't work in the case of another origin. So feels like providing an "id" should be the cleanest solution.

  1. Checking the origin of the message. Both Platform and Project can receive post messages, probably we should mention that it's possible to check the origin in order to process only requests from specific ones. For Project, I don't expect it to be an issue. But for Platform, I believe there could be poteniatial exploit when some embded iframe (maybe an ad) starts sending lots of such requests. Again, it's quite a corner case, but mentioning this in Docs should be great.

  2. Error events. For cases when Project failed to render an output, we should ask to send some event "type": "error", so Platform can show error message.

Ability to speed up render

There are some projects that takes quite long to finish "drawing" process, for example:

I do understand that sometimes it's just due to performance issues. Although would be nice to give ability for Platform to send a signal to Project indicating that we want to speed up render (if possible) to see the final version ASAP.

Actual use case: "Speed up" button on Artwork/Edition page to see final output (in case Project supports such speed up)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.