Skip to content

pubnub/chat-examples-javascript

Repository files navigation

PubNub JavaScript Chat

Build Status

This repository contains sample code from the Chat Resource Center.

Repository structure

Directory Description
examples Sample applications which show how to implement chat functionality using the PubNub SDK.
examples > react Source files for the Animal Forest Chat application. The complete tutorial can be found here.
snippets Verified and tested code snippets used in documentation.
Snippets from chat-resource-center/ are used in the Chat Resource Center.

Animal Forest Chat Application

Requirements

  • Node.js
  • Gulp - required to install project dependencies.

Prerequisites

Sign Up for a PubNub Account

If you don't already have an account, you can create one for free here.

  1. Sign in to your PubNub Admin Dashboard, click Create New App, and give your app a name.

  2. Select your new app, then click its keyset. Copy the Publish and Subscribe keys. You'll need these keys to include in this project.

  3. Scroll down on the Key Options page and enable the Presence and Storage & Playback add-on features.

  4. Click Save Changes, and you're done!

Using your PubNub keys

Add your PubNub keys to the keys file in the config folder:

cd examples/react/
vi src/config/keys.js

The file should look like the following:

module.exports = {
    publishKey: 'YOUR_PUBLISH_KEY',
    subscribeKey: 'YOUR_SUBSCRIBE_KEY'
  };

Building the project

  1. Navigate to the react project directory:
cd examples/react/
npm install
  1. Run the app in development mode:
$ npm start

Open http://localhost:3000 to view it in the browser.

Further Information

For more information about this project, or how to create your own chat app using PubNub, please check out the React tutorial in the Chat Resource Center.