Giter Site home page Giter Site logo

harshitchhipa / angularjs-chat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stephenlb/angularjs-chat

1.0 3.0 0.0 14.6 MB

AngularJS Chat - Enable chat messaging experiences in your iOS, Android and Web apps.

Home Page: http://angularjs.chat

License: MIT License

angularjs-chat's Introduction

AngularJS Chat

AngularJS Chat

Enable messaging experiences for Web, iOS and Android apps. Coming Soon AngularJS and the best frameworks Ionic, PubNub, PhoneGap

AngularJS Chat Website

NPM Install

npm install angular-chat

Bower Install

bower install angular-chat

Include the files

Include the angular chat files in your template.

<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/rltm/web/rltm.js"></script>
<script src="bower_components/angular-chat/angular-chat.js"></script>

Include the Angular module

var chat = angular.module('BasicChat', ['chat']);

Configure

In order to use angularjs-chat, you must configure a connection to a realtime service. This library includes rltm.js as a dependency which lets you switch between realtime service providers like Socket.io and PubNub easily. We recommend setting up with PubNub to get started quickly and scale to infinity.

angular.module('chat').constant('config', {
    rltm: {
        service: "pubnub",
        config: {
            "publishKey": "demo",
            "subscribeKey": "demo"
        }
    }
});

Example Controller

The chat module exposes an object called Messages which includes a send and receive method.

chat.controller( 'chat', [ 'Messages', '$scope', function( Messages, $scope ) {
    // Message Inbox
    $scope.messages = [];
    // Receive Messages
    Messages.receive(function(message) {
        $scope.messages.push(message);
    });
    // Send Messages
    $scope.send = function() {
        Messages.send({ 
            data: $scope.textbox 
        });
    };
}]);

In this controller we keep a list of messages in $scope.messages and push a new message every time the Messages.receive() callback is called.

To send a message over the Internet, we use the Messages.send() method and attach it to ```$scope.send()```` so we can call bind it to the DOM.

Create your view

We use the $scope.send() method and $scope.messages variable in our view.

<div ng-app="BasicChat">
    <div ng-controller="chat">
        <div ng-repeat="message in messages">
            <strong>{{message.user.name}}:</strong>
            <span>{{message.data}}</span>
        </div>
        <form ng-submit="send()">
            <input ng-model="textbox">
        </form>
    </div>
</div>

Set User ID

Set some identification for this user.

Messages.user({ id: MY_USER_ID, name : sillyname() });

Send to User

Send a message to another user.

Messages.send({ to: target_user_id, data : message_body });

If you want random user id's that are transient... you can publish the LIST of users to the "global" channel and receive each user who has come online.

Basic Example

Check out /examples/basic/index.html for an example of a chatroom that every visitor can chat in.

Support Desk (many to one) Example

Check out /examples/support-chat/index.html and /examples/support-chat/admin.html for an example of a embedded support type chatroom. The page index.html can only chat with the user on admin.html. The page admin.html creates a new instance of a chatroom for every new user on index.html.

AngularJS Chat Resources

angularjs-chat's People

Contributors

ianjennings avatar stephenlb avatar

Stargazers

 avatar

Watchers

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