2016-12-15 52 views
2

我使用節點模塊例如「LWIP」在如何反應的組成部分?這是用於電子應用的。調用節點模塊從反應成分

更新與代碼的問題:

  1. 這是從我試圖調用另一個.js文件的反應成分。

button.js

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import resize from '../../node-code/process'; 

class Button extends React.Component{ 

    mess(){ 
     console.log('working'); 
     resize(); 
    } 

    render(){ 
     return <button id="imgButton" onClick={this.mess.bind(this)}>Upload Image</button> 
    } 
} 

export default Button 
  • 這是其他JavaScript文件,其中我試圖調整圖像大小。
  • process.js

    var lwip = require('lwip'); 
    
    export default function(){ 
        var lwip = require('lwip'); 
        lwip.open('../../public/img/portrait.jpg', function(err, image){ 
    
    
        image.batch() 
         .scale(0.75)   // scale to 75% 
         .rotate(45, 'white') // rotate 45degs clockwise (white fill) 
         .crop(200, 200)  // crop a 200X200 square from center 
         .blur(5)    // Gaussian blur with SD=5 
         .writeFile('../../public/img/output.jpg', function(err){ 
    
         }); 
    
        }); 
    } 
    
    +0

    歡迎使用堆棧!這個問題需要一些工作。你遇到任何錯誤? – azium

    +0

    沒有錯誤,但我需要知道調用節點模塊中的方法的過程。我正在寫一個電子應用程序,我需要處理一個圖像,所以我安裝了lwip節點模塊,如何在反應組件中使用這些方法?有沒有可以指導我完成的教程? – Vasista

    +0

    like ...'var lwip = require('lwip'); lwip.method()'? – azium

    回答

    1

    節點模塊需要從主電子線程,而不是渲染線程上運行作出反應運行。

    您可以在渲染器進程中運行NPM模塊,就好像您在瀏覽器中一樣,但這些模塊無法使用Node.js庫,因爲瀏覽器中顯然沒有節點。

    要你需要使用IPC(進程間通信),使用事件在線程之間發送數據的系統的主(節點)和渲染器(瀏覽器)線程之間進行通信。

    Here's the IPC documentation for Electron.

    如果需要線程之間不斷的溝通,你可以使用electron-ipc-socket庫。