internetarchive / bookreader

The Internet Archive BookReader
https://openlibrary.org/dev/docs/bookreader
GNU Affero General Public License v3.0
998 stars 419 forks source link

Add support for overriding ajax calls with custom transport methods #127

Open jbuckner opened 5 years ago

jbuckner commented 5 years ago

Context

The Internet Archive's Distributed Web project (https://dweb.me) uses different protocols than just http / https, including WebTorrent and ipfs. This means we need a method other than using a standard Ajax requests for it to work in the Dweb version.

Proposal & Constraints

When we initialize BookReader, we pass in an options object with configuration options. We could potentially add a configuration option to let the consumer define a function that will be used in place of the ajax requests. NOTE This is just an idea and will need to be prototyped for feasibility.

Success Metrics

If Mitra is able to integrate the BookReader into the IA Decentralized Website, this is successful.

Stakeholders

@mitra42

mitra42 commented 5 years ago

Is this the same as the issue with the DwebImage tag, or is that getting its own ticket ?

jbuckner commented 5 years ago

@mitra42 The image tag override is covered in #126

imskr commented 5 years ago

Do you mean adding something like this:

// Request with custom header
$.ajax({
    url: 'foo/bar',
    headers: { 'x-my-custom-header': 'some value' }
});
mitra42 commented 5 years ago

Not as simple .... Its more of a section like ...

if (!opts.ajaxintercept) { 
  fetch(url, opts, cb)
} else { 
  opts.ajax.intercept(url, opts, cb)
}

So calling out to a provided function . (I'd hope we weren't still using jquery ajax calls inside bookreader, but a similar process could be used with $.ajax)