New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime Support: Ionic Framework #802

Open
theD1360 opened this Issue Mar 20, 2017 · 14 comments

Comments

Projects
None yet
3 participants
@theD1360

theD1360 commented Mar 20, 2017

Can anyone help me out with this? Below is a simplified version of what I have running on an ionic2 project.
I seems that the connection is working but it never seems to trigger the callback but it also never triggers any errors or warnings. Tried using the promises as well but still nothing.

        let node = new IPFS(
                {
                    repo: this.repoPath,
                    EXPERIMENTAL: {
                        pubsub: false
                    },
                  config: { 
                    Addresses: {
                      Swarm: [
                        '/ip4/127.0.0.1/tcp/1337',
                        '/ip4/127.0.0.1/tcp/1337/ws'
                      ]
                    }
                  }
                }
            );

            node.on('start', ()=>{
               node.files.add(file, (err, res) => {
                    console.log('never fires!!!');                
               });
           }); 
@diasdavid

This comment has been minimized.

Show comment
Hide comment
@diasdavid

diasdavid Mar 20, 2017

Member

@theD1360 what is the file var you are passing?

Member

diasdavid commented Mar 20, 2017

@theD1360 what is the file var you are passing?

@diasdavid

This comment has been minimized.

Show comment
Hide comment
@diasdavid

diasdavid Mar 20, 2017

Member

@theD1360, @VictorBjelkholm just brought up that you might be using a older version of js-ipfs, which version are you using?

Member

diasdavid commented Mar 20, 2017

@theD1360, @VictorBjelkholm just brought up that you might be using a older version of js-ipfs, which version are you using?

@theD1360

This comment has been minimized.

Show comment
Hide comment
@theD1360

theD1360 Mar 20, 2017

@diasdavid Should be using master. I added this in my package.json
"ipfs": "git@github.com:ipfs/js-ipfs.git#master",

the ipfs-api package.json shows "version": "12.1.7"

theD1360 commented Mar 20, 2017

@diasdavid Should be using master. I added this in my package.json
"ipfs": "git@github.com:ipfs/js-ipfs.git#master",

the ipfs-api package.json shows "version": "12.1.7"

@theD1360

This comment has been minimized.

Show comment
Hide comment
@theD1360

theD1360 Mar 20, 2017

Here is what is the calling snippet looks like.

              PhotoLibrary.getPhoto(libraryItem).then( (blob) => {
                console.log("Blob Size:", blob.size); // shows the blob has a size
                let reader = new FileReader();

                reader.addEventListener("loadend", function() {

                  // transform array buffer to ArrayBuffer since ArrayBuffer failed to work
                  let buf = new Buffer(reader.result.byteLength);
                  let view = new Uint8Array(reader.result);
                  for (let i = 0; i < buf.length; ++i) {
                    buf[i] = view[i];
                  }

                  // this is my own wrapper which is passing to the code you saw above.
                  ipfs.addFile({
                    path: "/testing/"+libraryItem.id, // '/testing/99D53A1F-FEEF-40E1-8BB3-7DD55A43C8B7/L0/001'
                    content:buf
                  }).then((data) => {
                    // I'm triggering a resolve to trigger this code. pls ignore
                    console.log("filedata", data);

                  }).catch((e) =>{
                    // same here
                    console.log("crap",libraryItem.photoURL,e);

                  });


                });

                reader.readAsArrayBuffer(blob);


              });

theD1360 commented Mar 20, 2017

Here is what is the calling snippet looks like.

              PhotoLibrary.getPhoto(libraryItem).then( (blob) => {
                console.log("Blob Size:", blob.size); // shows the blob has a size
                let reader = new FileReader();

                reader.addEventListener("loadend", function() {

                  // transform array buffer to ArrayBuffer since ArrayBuffer failed to work
                  let buf = new Buffer(reader.result.byteLength);
                  let view = new Uint8Array(reader.result);
                  for (let i = 0; i < buf.length; ++i) {
                    buf[i] = view[i];
                  }

                  // this is my own wrapper which is passing to the code you saw above.
                  ipfs.addFile({
                    path: "/testing/"+libraryItem.id, // '/testing/99D53A1F-FEEF-40E1-8BB3-7DD55A43C8B7/L0/001'
                    content:buf
                  }).then((data) => {
                    // I'm triggering a resolve to trigger this code. pls ignore
                    console.log("filedata", data);

                  }).catch((e) =>{
                    // same here
                    console.log("crap",libraryItem.photoURL,e);

                  });


                });

                reader.readAsArrayBuffer(blob);


              });
@theD1360

This comment has been minimized.

Show comment
Hide comment
@theD1360

theD1360 Mar 21, 2017

@diasdavid Could this be caused by not having any peers connected? I've checked the peer connections and it comes an empty array.

theD1360 commented Mar 21, 2017

@diasdavid Could this be caused by not having any peers connected? I've checked the peer connections and it comes an empty array.

@VictorBjelkholm

This comment has been minimized.

Show comment
Hide comment
@VictorBjelkholm

VictorBjelkholm Mar 21, 2017

Member

@theD1360 could you try listening to the error event as when when you initialize your node? Could be something that is not working when initializing but you're not catching any errors so might just be silent.

Member

VictorBjelkholm commented Mar 21, 2017

@theD1360 could you try listening to the error event as when when you initialize your node? Could be something that is not working when initializing but you're not catching any errors so might just be silent.

@diasdavid

This comment has been minimized.

Show comment
Hide comment
@diasdavid

diasdavid Mar 21, 2017

Member

@theD1360 can you push a full script that reproduces the case? Since you are using your own wrappers, I can't be sure of what is going on inside.

Member

diasdavid commented Mar 21, 2017

@theD1360 can you push a full script that reproduces the case? Since you are using your own wrappers, I can't be sure of what is going on inside.

@diasdavid

This comment has been minimized.

Show comment
Hide comment
@diasdavid

diasdavid Mar 21, 2017

Member

@theD1360 looks like Ionic doesn't offer a native TCP shim module or a WebSockets one (read it here: https://forum.ionicframework.com/t/tcp-sockets-in-ionic-2/67806/3). Seems like we need to create a custom transport, that supports Ionic2 networking.

See how we did TCP for Node.js -- https://github.com/libp2p/js-libp2p-tcp/ -- and how we bundle it in here: https://github.com/ipfs/js-libp2p-ipfs-nodejs/blob/master/src/index.js#L48

Member

diasdavid commented Mar 21, 2017

@theD1360 looks like Ionic doesn't offer a native TCP shim module or a WebSockets one (read it here: https://forum.ionicframework.com/t/tcp-sockets-in-ionic-2/67806/3). Seems like we need to create a custom transport, that supports Ionic2 networking.

See how we did TCP for Node.js -- https://github.com/libp2p/js-libp2p-tcp/ -- and how we bundle it in here: https://github.com/ipfs/js-libp2p-ipfs-nodejs/blob/master/src/index.js#L48

@theD1360

This comment has been minimized.

Show comment
Hide comment
@theD1360

theD1360 Mar 22, 2017

Upon further inspection it looks like WebSockets are available in the window object not sure what else I need to get this working. I also decided to build the app for android and am getting a new error regarding secure origins on init. Is it possible that it's related to this issue? If not is there any way that I can circumvent the secure origins restriction (webrtc or something)?

I'll take some time to look into how to shim the cordova TCP module . Not 100% clear on how to do that at the moment.

theD1360 commented Mar 22, 2017

Upon further inspection it looks like WebSockets are available in the window object not sure what else I need to get this working. I also decided to build the app for android and am getting a new error regarding secure origins on init. Is it possible that it's related to this issue? If not is there any way that I can circumvent the secure origins restriction (webrtc or something)?

I'll take some time to look into how to shim the cordova TCP module . Not 100% clear on how to do that at the moment.

@diasdavid

This comment has been minimized.

Show comment
Hide comment
@diasdavid

diasdavid Mar 23, 2017

Member

Ok, let's go with WebSockets first then :) We just need to make sure it exposes the same interface that one would get from using WebSockets in a browser context, if it does, then it should work like a charm.

getting a new error regarding secure origins on init

Could you tell us more?

Btw, if you can set up some custom simple apps on Ionic2 for us to have a quick sandbox to try things, that would be extremely helpful.

Member

diasdavid commented Mar 23, 2017

Ok, let's go with WebSockets first then :) We just need to make sure it exposes the same interface that one would get from using WebSockets in a browser context, if it does, then it should work like a charm.

getting a new error regarding secure origins on init

Could you tell us more?

Btw, if you can set up some custom simple apps on Ionic2 for us to have a quick sandbox to try things, that would be extremely helpful.

@theD1360

This comment has been minimized.

Show comment
Hide comment
@theD1360

theD1360 Mar 24, 2017

For sure. I'll see what I can figure out as far as the websockets go. In the meantime, feel free to clone my CygnusLoop app repo. Standard ionic 2 install and build nothing fancy.

Login page is fake just enter any values. Check out the Ionic 2 docs for debugging for debugging info.

theD1360 commented Mar 24, 2017

For sure. I'll see what I can figure out as far as the websockets go. In the meantime, feel free to clone my CygnusLoop app repo. Standard ionic 2 install and build nothing fancy.

Login page is fake just enter any values. Check out the Ionic 2 docs for debugging for debugging info.

@diasdavid diasdavid added the backlog label Apr 5, 2017

@theD1360

This comment has been minimized.

Show comment
Hide comment
@theD1360

theD1360 Apr 6, 2017

Current master appears to be initializing without errors on both iOS and Android. As far as the secure origins goes it appears that it was related to ionic live reload. Still having issues with uploading to the the network but it seems to be a different issue. I'll keep this issue open until I verify that the new error is unrelated.

Thanks guys.

theD1360 commented Apr 6, 2017

Current master appears to be initializing without errors on both iOS and Android. As far as the secure origins goes it appears that it was related to ionic live reload. Still having issues with uploading to the the network but it seems to be a different issue. I'll keep this issue open until I verify that the new error is unrelated.

Thanks guys.

@diasdavid diasdavid changed the title from `ipfs.files.add` callbacks and promises do not resolve on Ionic2 platform to [Ionic2] `ipfs.files.add` callbacks and promises do not resolve on Ionic2 platform Jul 7, 2017

@diasdavid

This comment has been minimized.

Show comment
Hide comment
@diasdavid

diasdavid Sep 1, 2017

Member

@theD1360 if you could come up with a simple example of how to run js-ipfs in Ionic, similar to what we have for Node.js, Browser and Electron in the examples folder, then I would be more able to help you. Wanna do it?

Thanks in advance!

Member

diasdavid commented Sep 1, 2017

@theD1360 if you could come up with a simple example of how to run js-ipfs in Ionic, similar to what we have for Node.js, Browser and Electron in the examples folder, then I would be more able to help you. Wanna do it?

Thanks in advance!

@diasdavid diasdavid changed the title from [Ionic2] `ipfs.files.add` callbacks and promises do not resolve on Ionic2 platform to Ionic Framework support Sep 1, 2017

@diasdavid diasdavid changed the title from Ionic Framework support to Runtime Support: Ionic Framework Mar 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment