@myetherwallet/mewconnect-web-client
<!--##### Note This Repository Nees Some Cleaning-->
Last updated a month ago by stevemieskoski .
Original npm · Tarball · package.json
$ cnpm install @myetherwallet/mewconnect-web-client 
SYNC missed versions from official npm registry.

Getting Started

Get the code

The example requires both MEWconnect-web-client (this repo) and MEWconnect-Signal-Server (MEWconnect-hanshake-server)

git clone https://github.com/MyEtherWallet/MEWconnect-web-client.git

Install the dependencies:

npm install

Start the server serving the example initiator and receiver:

npm start
Get the signaling server

Clone the repo:

git clone https://github.com/MyEtherWallet/MEWconnect-hanshake-server.git

Install the dependencies:

npm install

Start the signaling server:

npm start

Usage

Two Peers are needed with one designated as the Initiator and the other as the Receiver.

Require the MEWconnect client

let mewConnect = require('@myetherwallet/mewconnect-web-client').Client;

Initiate the client

let mewConnectClient = mewConnect.init();

MEWconnect Client functions as an event emitter. The connection details are passed along with the 'codeDisplay' event

mewConnectClient.on('codeDisplay', code => {
// do something with the code.
// to work with the MEWconnect Mobile applications display it as a qrcode
}

Now call the initiatorStart method to create the connection details:

mewConnectClient.initiatorStart('https://signal-server-url')

Once a p2p connection is established the client will emit a 'rtcConnected' event

mewConnectClient.on('rtcConnected', () =>{
    alert('congrats you are connected to mew connect!')
})

Once a connection is extablished call the 'sendRtcMessage' method to interact with the app

mewConnectClient.sendRtcMessage('address', {})

The 'sendRtcMessage' method takes two parameters (message type, message data)

To get the response listen for an event matching the sent message type

mewConnectClient.on('address', address => {
    alert('got address: ' + address)
})

Currently the app supports two other message types: 'signMessage', and 'signTx'

exists you can get the address or send a transaction or message to the mobile app for signing.

The data portion of those two message types are:

signMessage

{
    hash: 'hash of the message to be signed',
    text: 'text of the message to be signed'
}

signTx

{
        nonce:"0x00",
        gasPrice:"0x098bca5a00",
        gas:"0x5208",
        to:"0xc3982F1DbAB6DA9d95F579B9A5f9c5CAb13F8cfC",
        value:"0xb1a2bc2ec50000",
        data:"",
        chainId:3

}

If the p2p connection fails to be established the client can attempt to use an intermediate TURN server to facilitate the connection. To signal a failed p2p attempt the client can call the 'useFallback' method on the client

mewConnectClient.useFallback()

Additional events are emitted at various points to signal various stages of the connection

SocketConnectedEvent

  • successfully connected to the signal server

RtcInitiatedEvent

  • Peer identified via the signal server, and a p2p connection will be attempted

UsingFallback

  • One of the peers failed to establish a p2p connection and will attempt to use an intermediate TURN server to facilitate the connection

RtcConnectedEvent

  • p2p connection established

RtcClosedEvent

  • p2p connection closed

RtcDisconnectEvent

  • p2p disconnected

RtcErrorEvent

  • p2p connection error occured
Browser

mew-connect-client can be included for use in the browser via webpack or browerfy

Run Tests

first the import WebSocket from 'promise-ws' line needs to be uncommented in websocketWrapper.js npm run test

Current Tags

  • 2.0.0-beta.22                                ...           latest (a month ago)

44 Versions

  • 2.0.0-beta.22                                ...           a month ago
  • 2.0.0-beta.21                                ...           a month ago
  • 2.0.0-beta.20                                ...           a month ago
  • 2.0.0-beta.19                                ...           a month ago
  • 2.0.0-beta.18                                ...           a month ago
  • 2.0.0-beta.17                                ...           2 months ago
  • 2.0.0-beta.16                                ...           2 months ago
  • 2.0.0-beta.15                                ...           2 months ago
  • 2.0.0-beta.14                                ...           2 months ago
  • 2.0.0-beta.13                                ...           2 months ago
  • 2.0.0-beta.12                                ...           3 months ago
  • 2.0.0-beta.11                                ...           3 months ago
  • 2.0.0-beta.10                                ...           3 months ago
  • 2.0.0-beta.9                                ...           3 months ago
  • 2.0.0-beta.8                                ...           3 months ago
  • 2.0.0-beta.7                                ...           3 months ago
  • 2.0.0-beta.6                                ...           3 months ago
  • 2.0.0-beta.5                                ...           3 months ago
  • 2.0.0-beta.4                                ...           3 months ago
  • 2.0.0-beta.3                                ...           3 months ago
  • 2.0.0-beta.2                                ...           3 months ago
  • 2.0.0-beta.1                                ...           4 months ago
  • 1.0.14                                ...           9 months ago
  • 1.0.13                                ...           9 months ago
  • 1.0.12                                ...           9 months ago
  • 1.0.11                                ...           9 months ago
  • 1.0.10                                ...           9 months ago
  • 1.0.9                                ...           a year ago
  • 1.0.8                                ...           a year ago
  • 1.0.7                                ...           a year ago
  • 1.0.6                                ...           a year ago
  • 1.0.5                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 1.0.2-beta.3                                ...           a year ago
  • 1.0.2-beta.2                                ...           a year ago
  • 1.0.2-beta.1                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.0.1-alpha.3                                ...           a year ago
  • 0.0.1-alpha.2                                ...           a year ago
  • 0.0.1-alpha.1                                ...           a year ago
  • 0.0.1-alpha.0                                ...           a year ago
Downloads
Today 1
This Week 1
This Month 3
Last Day 0
Last Week 2
Last Month 100
Dependencies (17)

Copyright 2014 - 2016 © taobao.org |