Git Product home page Git Product logo

Comments (1)

bgins avatar bgins commented on August 23, 2024

The message protocol has changed to send Webnative state on connect and disconnect messages. In addition, data messages have been have been broken into filesystem and session messages.

Messages

Messages are sent from Webnative to the extension as window post messages. When the extension initially connects, it configures Webnative with an extension ID which is used to tag all messages sent to the extension. The tag lets the extension filter window post messages to only receive messages intended for it.

State

Each message includes some information about the state of Webnative:

type State = {
  app: {
    namespace: AppInfo | string
    capabilities?: Permissions
  }
  fileSystem: {
    dataRootCID: string | null
  }
  user: {
    username: string | null
    accountDID: string | null
    agentDID: string
  }
  odd: {
    version: string
  }
}

Updated on April 21st, 2023.

Connect message

The extension calls a connect function that is added to the global object (e.g. window) by Webnative. When the connect function is called, Webnative sends a connect message to the extension:

globalThis.postMessage({
  id: extensionId,
  type: "connect",
  timestamp: 1678487975,
  state
})

Disconnect message

The extension calls a disconnect function when it does not need messages to be sent from Webnative:

globalThis.postMessage({
  id: extensionId,
  type: "disconnect",
  timestamp: 1678487975,
  state
})

Session messages

Webnative sends session create and destroy messages to the extension. Each message contains a detail field that includes the username and indicates the message type:

globalThis.postMessage({
  id: extensionId,
  type: "session",
  timestamp: 1678487975,
  state,
  detail: {
    type: "create",
    username
  }
})
globalThis.postMessage({
  id: extensionId,
  type: "session",
  timestamp: 1678487975,
  state,
  detail: {
    type: "destroy",
    username
  }
})

File system messages

Webnative sends filesystem local-change and publish messages to the extension. Each message contains a detail field that includes the root CID, path on local-change, and indicates the message type:

globalThis.postMessage({
  id: extensionId,
  type: "filesystem",
  timestamp: 1678487975,
  state,
  detail: {
    type: "local-change",
    root: "<root-cid>",
    path
  }
})
globalThis.postMessage({
  id: extensionId,
  type: "filesystem",
  timestamp: 1678487975,
  state,
  detail: {
    type: "publish",
    root: "<root-cid>"
  }
})

from odd-devtools.

Related Issues (20)

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.