0

In https://github.com/holochain/holochat-rust, how are the files ui/holoclient.js and ui/holoclient.map obtained ?

Also, is there any official documentation about that that I missed and is this still the way to get a UI to talk to the holochain container ?

Nicolas Marshall
  • 4,186
  • 9
  • 36
  • 54

1 Answers1

1

ui/holoclient.js is a tiny library that makes it much easier to talk to a running Holochain app instance. The current way of connecting your GUI to an instance is a JSON-RPC-like process via a local WebSocket connection. It's intended as a nice wrapper to make zome function calls feel like local, in-browser function calls. Documentation is currently very light, but it shouldn't take much to figure out how it's supposed to work using the example. In a nutshell:

const url =  'ws://localhost:3000/'
window.holoclient.connect(url).then(({call, close}) => {
  document.getElementById('form').addEventListener('submit', e => {
    e.preventDefault()
    // First, get a list of locally running Holochain instances...
    call('info/instances')().then(info => {
      // Now that we have instance info, we can make zome calls into any of them
      // by referring to them by DNA hash (and agent ID) as specified in our
      // container config.
      // Search for the instance we're looking for, given known DNA and agent
      // hashes.
      const matchingInstances = Object.entries(info)
        .find(([id, value]) => value.dna === 'blog_dna_hash' && value.agent === 'my_agent_hash')
      const instance = getInstance(info, 'the_dna_hash', 'the_agent_hash')
      const content = document.querySelector('#message').value
      // Make another zome call now
      call(instance, 'blog', 'main', 'create_post')({
        content: content
      })
    })
  })
})

It's written in TypeScript, which would mean that ui/holoclient.map is a 'source map', a file which maps line numbers in the compiled JavaScript file to line numbers in the original TypeScript source. Both Chrome and Firefox look for and use those source maps when you're debugging your JS.

Paul d'Aoust
  • 3,019
  • 1
  • 25
  • 36