arj03 / ssb-browser-core

ssb-server in a browser
Other
50 stars 8 forks source link

Basic usage example #1

Closed revolunet closed 1 year ago

revolunet commented 4 years ago

Hi, i'm trying to use ssb-browser-core and bundle with webpack; i had to disable fs and net bundling for the browser for it to load

What are the first steps to setup the connexion ?

I'm trying this :

import SSB from "ssb-browser-core/core";
SSB.init();

But i get :

Capture d’écran 2020-05-04 à 15 41 48
revolunet commented 4 years ago

Ok i had to specify a "data" directory :

SSB.init("./data");

now i get :

Uncaught Error: ssb-tunnel is configured, but a portal is missing
    at Object.server (index.js:83)
    at Object.server (compose.js:96)
    at index.js:45
    at Array.map (<anonymous>)
    at Object.server (index.js:44)
    at setupMultiserver (core.js:167)
    at run (setImmediate.js:40)
    at runIfPresent (setImmediate.js:69)
    at onGlobalMessage (setImmediate.js:109)
arj03 commented 4 years ago

Looks like you are loading ssb-browser-core directly instead of using the bundle?

There are some patches that needs to be applied if running directly from source: https://github.com/arj03/ssb-browser-core#building

revolunet commented 4 years ago

With import SSB from "ssb-browser-core/dist/bundle-core";

i get TypeError: s.existsSync is not a function

arj03 commented 4 years ago

Yeah SSB browser core is not a ES module.

See https://github.com/arj03/ssb-browser-core#api.

Dist is created using browserify and has polyfills for all the fs stuff.

Happy to ideas on how to improve the README for your use case :)

revolunet commented 4 years ago

even with const SSB = require("ssb-browser-core/dist/bundle-core"); i get the same error

arj03 commented 4 years ago

You hit that error if you run the browserify code from node instead of in the browser. It's a bit unfortunate with the patches. I should create branches for all of them and use that, so that you can just include the project directly as you did in the second post. To be honest it took quite a while to fix everything to work in the browser and it takes time for things to be applied upstream.

revolunet commented 4 years ago

sorry i dont understand what's going on :/ i require the "bundle-core" with webpack and this error appear in the browser.

when inspecting this bundle-core i can see the patchs are already applied, for example :

crypto_auth:function(){},crypto_auth_verify:function(){},crypto_box_easy:function(){},crypto_box_keypair:function(){},crypto_box_open_easy:function(){}
arj03 commented 1 year ago

Closing this one, this is a webpack example in repo and the old patches are long since merged.