Giter Site home page Giter Site logo

chat-kontroller's Introduction

SendBird JavaScript Widget Sample

This is a sample chat widget built using using the SendBird SDK. It can be used to add a functional chat widget to any website.

You can try out a live demo from the link here. Click on the button at the bottom-right corner of the webpage to try out the widget. Choose any 'User ID' and 'Nickname' to log in and participate in chats.

Setup

  1. The body must have a div element whose id is sb_widget.
<body>
  <div id="sb_widget"></div>
</body>
  1. Import the SendBird SDK.
  2. Import the widget.SendBird.js file.
<script src="SendBird.min.js"></script>
<script src="build/widget.SendBird.js"></script>

Customizing the widget

If you refresh your browser window, you need to reconnect to SendBird. To retain connection on browser refresh, you must implement an appropriate event handler.

If you wish to issue an access_token for your user, modify the connect function in src/sendbird.js.

Require that you have Node installed.

  1. Install npm

     npm install
    
  2. Modify files.

     npm run start-dev
    
  3. Start sample.

     npm start
    

Advanced

Connect other APP or Channel

If you want to connect other application, you need to change variable appId in index.html.

...

  <script src="SendBird.min.js"></script>
  <script src="build/widget.SendBird.js"></script>
  <script>
    var appId = '<APP_ID>';
    sbWidget.start(appId);
  </script>

</html>

Start with User connect

If you want to start this sample with user connect, you can using startWithConnect().

...

  <script src="SendBird.min.js"></script>
  <script src="build/widget.SendBird.js"></script>
  <script>
    var appId = '<APP_ID>';
    var userId = '<USER_ID>';
    var nickname = '<NICKNAME>';
    sbWidget.startWithConnect(appId, userId, nickname, function() {
      // do something...
    });
  </script>

</html>

Show Channel

If you want to open chat, you can using showChannel().

...
var channelUrl = '<CHANNEL_URL>';
sbWidget.showChannel(channelUrl);
...

File Structure

    |-- build
        |-- widget.SendBird.js              - SendBird Widget Bundle file
    |-- node_modules
        |-- ...                             - (node packages)
    |-- src
        |-- js
            |-- elements  
                |-- elements.js             - elements root class
                |-- spinner.js              - spinner element
                |-- widget-btn.js           - widget button element
                |-- popup.js                - popup element
                |-- list-board.js           - channel list element
                |-- chat-section.js         - chat element
            |-- consts.js                   - const variables
            |-- utils.js                    - util functions
            |-- sendbird.js                 - sendbird functions
            |-- widget.js                   - widget functions
        |-- scss
            |-- mixins 
                |-- _border-radius.scss     - border radius mixin  
                |-- _box-shadow.scss        - box shadow mixin
                |-- _state.scss             - element state mixin
                |-- _transform.scss         - transform mixin
                |-- _reset.scss             - clean css mixin
            |-- _mixins.scss                - import mixin
            |-- _variables.scss             - css variables
            |-- _animation.scss             - animation
            |-- _icons.scss                 - icon 
            |-- widget.scss                 - main css  
|-- .eslintrc.js                            - lint setting 
|-- webpack.config.js                       - webpack setting 
|-- package.json                            - npm package 
|-- SendBird.min.js                         - SendBird SDK 
|-- index.html                              - sample file
|-- README.md

chat-kontroller's People

Contributors

philemongloblehi avatar

Watchers

James Cloos avatar  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.