Giter Site home page Giter Site logo

meteor-dapp-whisper-chat-client's Introduction

Whisper Chat Client Ðapp

Development

Start an geth node and and the app using meteor and open http://localhost:3000 in your browser:

$ geth --rpccorsdomain "http://localhost:3000" --rpc --shh --unlock <your account>

Start your app using meteor

$ cd meteor-dapp-wallet/app
$ meteor

Go to http://localhost:3000

Deployment

To create a build version of your app run:

// install meteor-build-client
$ npm install -g meteor-build-client

// bundle dapp
$ cd meteor-dapp-wallet/app
$ meteor-build-client ../build --path ""

This will generate the files in the ../build folder. Double click the index.html to start the app.

To make routing work properly you need to build it using:

$ meteor-build-client ../build

And start a local server which points with its document root into the ../build folder, so that you can open the app using http://localhost:80/

The Whisper chat app

The collections used are:

  • User - contains the users identities (persistet via localStorage)
  • Users - contains collected identities and usernames (persistet via localStorage)
  • Chats - contains the chats (persistet via localStorage)
  • Messages - contains the messages, which belong to chats (persistet via localStorage)
  • Invitations - contains temporarily store inviations

The web3 object is created in client/lib/thirdpartyConfig.js.

The whole whisper protocol integration can be found in the client/whisperConnection.js. Removing it won't break app, just cut the connection to whisper. Some helper functions for whisper can be found at client/lib/helpers/WhisperHelperFunctions.js.

This dapp uses the ethereum:elements package.

Protocol specs

The following specs need to be transfered as stringified JSON in the payload.

You can also send messages to a chatroom by simply providing the correct chatroom topic including the whisper-chat-client topic. The user will then appear as anonymous:

web3.shh.post({
    "topic": ['whisper-chat-client', 'ethereum'],
    "payload": 'Hello world',
    "ttl": 100,
    "priority": 1000
});

Invite to a group chat

// Topics
[
    'whisper-chat-client',
    '0x34556456..' // the user to invite
]

// TO and FROM parameters
to: '0x34556456..' // the user to invite,
from: '0x12344...'


// Payload
{
    type: 'invite',
    chat: 'ethereum', // chat topic
    name: 'My Chatroom',
    from: {
        identity: '0x12344...', // the current user identity, if you set a from in the whisper `shh.post()` it will be used instead
        name: 'Mr. X'
    },
    // the users invited
    data: [{
        identity: '0x345345345..',
        name: 'user x'
    },
    {
        identity: '0x67554345..',
        name: 'user y'
    }]
}

Invite to a private chat

// Topics
[
    'whisper-chat-client',
    '0x34556456..' // the user to invite
]

// TO and FROM parameters
to: '0x34556456..' // the user to invite,
from: '0x12344...' // required

// Payload
{
    type: 'invite',
    privateChat: true,
    from: {
        identity: '0x12344...', // the current user identity, if you set a from in the whisper `shh.post()` it will be used instead
        name: 'Mr. X'
    }
}

Send message

// Topics
[
    'whisper-chat-client',
    'ethereum' // the chats topic or HEX user identity for private chats
]

// TO and FROM parameters
to: '0x34556456..' // only for private chats
from: '0x12344...'

// Payload
{
    type: 'message',
    id: '231rewf23', // the unique id of the message
    chat: 'ethereum', // the parent chats topic. For private chats the identity of the user
    topic: 'my topic', // the topic set for the chat, to filter chats with many participants. Has nothing to do with whisper topics
    timestamp: 145788999,
    from: {
        identity: '0x4324234..', // the current user identity, if you set a from in the whisper `shh.post()` it will be used instead
        name: 'my username'
    },
    message: 'Hello its me!'
}

Edit message

Will only be allowed for messages which are less than 1 hour old.

// Topics
[
    'whisper-chat-client',
    'ethereum' // the chats topic or HEX user identity for private chats
]

// TO and FROM parameters
to: '0x34556456..' // only for private chats
from: '0x12344...'

// Payload
{
    type: 'edit',
    id: '231rewf23', // the unique id of the message
    chat: 'ethereum', // the parent chats topic. For private chats the identity of the user
    timestamp: 145788999,
    from: {
        identity: '0x4324234..', // the current user identity, if you set a from in the whisper `shh.post()` it will be used instead
        name: 'my username'
    },
    topic: 'my new topic', // the changed topic
    message: 'my edited message' // the changed message
}

Notifications

// Topics
[
    'whisper-chat-client',
    'ethereum' // the chats topic or HEX user identity for private chats
]

// TO and FROM parameters
to: '0x34556456..' // only for private chats
from: '0x12344...'

// Payload
{
    type: 'notification',
    message: 'invitation',
    id: '231rewf23', // the unique id of the message
    chat: 'ethereum', // the parent chats topic. For private chats the identity of the user
    timestamp: 145788999,
    from: {
        identity: Whisper.getIdentity().identity,
        name: Whisper.getIdentity().name
    },
    data: 'some data, see below'
}

There are currently three types of notifications implemented:

  • invitation will list all the users the user has invited into the group chat The data property should contain the identities and usernames:

    [{
        identity: '0x345345345..',
        name: 'user x'
    },
    {
        identity: '0x67554345..',
        name: 'user y'
    }]
  • topicChanged will tell the other participants about a change of the users personal (non-whisper) topic The data property should contain the new topic name e.g. my new topic

  • chatNameChanged will tell the other users that the group chat name has changed. The data property should contain the new chat name e.g. Hello kitty fans. All users will then update their group chat name accordingly. (Everybody can change the group chat name)

meteor-dapp-whisper-chat-client's People

Contributors

frozeman avatar alexvansande avatar debris avatar

Watchers

Jeremy Sarda avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.