<commit_before>---
title: "Group Joining - Respoke JavaScript Library"
shortTitle: "Group Joining"
date: 2015-04-20
template: article.jade
showInMenu: "true"
menuOrder: 30
meta:
    keywords: "respoke, group, joining"
    description: "Learn how to do group joining using Respoke"
---

###JavaScript Library

# Groups
The <a href="https://docs.respoke.io/js-library/respoke.Group.html" target="_blank">Group</a> object forms the foundation for conversations in Respoke. It gives you the ability to communicate with a large number of people while only requiring you to send a single message. Let's take a look at how to join a group.

#### Assumptions
You have read the [Getting Started Guide](/client/javascript/getting-started.html), created an instance of the Respoke <a href="https://docs.respoke.io/js-library/respoke.Client.html" target="_blank">Client</a>, and <a href="https://docs.respoke.io/js-library/respoke.Client.html#connect" target+"_blank">connected</a> your app to Respoke. 

## Joining Groups
Before joining a group, you must first be connected to Respoke. The best way to ensure this is to add a listener for the `connect` event, and execute the code to join your group after the event is received.    

Once you are connected, you will use the <a href="https://docs.respoke.io/js-library/respoke.Client.html#join" target+"_blank">join</a> method of the <a href="https://docs.respoke.io/js-library/respoke.Client.html" target+"_blank">Client</a> object to join the group as outlined below.
    
    // Join the group after connecting to Respoke
    client.listen("connect", function() {
        client.join({
            id: "the-group-id",
            onSuccess: function(group) {
                // You have successfully joined the group!
            }
        });
    });  

## Group Methods and Events
Below are a few methods and events commonly used with groups. A complete listing of the availabe methods and events for the Group object can be found in the <a href="https://docs.respoke.io/js-library/respoke.Group.html">Groups</a> section of the API reference.

### Return all members of the group:

    group.getMembers({
        onSuccess: function(connections) {
            connections.forEach(
                function(connection) {
                    var endpoint = connection.getEndpoint();
                }
            );
        }
    });

### When members join the group:

    group.listen("join", function(e) {
        var endpoint = e.connection.getEndpoint();
    });

### When members leave the group:

    group.listen("leave", function(e) {
        var endpoint = e.connection.getEndpoint();
    });

## Related Guides
[Group Messaging](/client/javascript/guide/messaging-group.md)<commit_msg>Updates to spacing of content in group-joining guide<commit_after>---
title: "Group Joining - Respoke JavaScript Library"
shortTitle: "Group Joining"
date: 2015-04-20
template: article.jade
showInMenu: "true"
menuOrder: 30
meta:
    keywords: "respoke, group, joining"
    description: "Learn how to do group joining using Respoke"
---

###JavaScript Library

# Groups
The <a href="https://docs.respoke.io/js-library/respoke.Group.html" target="_blank">Group</a> object forms the foundation for conversations in Respoke. It gives you the ability to communicate with a large number of people while only requiring you to send a single message. Let's take a look at how to join a group.

#### Assumptions
You have read the [Getting Started Guide](/client/javascript/getting-started.html), created an instance of the Respoke <a href="https://docs.respoke.io/js-library/respoke.Client.html" target="_blank">Client</a>, and <a href="https://docs.respoke.io/js-library/respoke.Client.html#connect" target+"_blank">connected</a> your app to Respoke. 

## Joining Groups
Before joining a group, you must first be connected to Respoke. The best way to ensure this is to add a listener for the `connect` event, and execute the code to join your group after the event is received.    

Once you are connected, you will use the <a href="https://docs.respoke.io/js-library/respoke.Client.html#join" target+"_blank">join</a> method of the <a href="https://docs.respoke.io/js-library/respoke.Client.html" target+"_blank">Client</a> object to join the group as outlined below.
    
    // Join the group after connecting to Respoke
    client.listen("connect", function() {
        client.join({
            id: "the-group-id",
            onSuccess: function(group) {
                // You have successfully joined the group!
            }
        });
    });  

## Group Methods and Events
Below are a few methods and events commonly used with groups. A complete listing of the availabe methods and events for the Group object can be found in the <a href="https://docs.respoke.io/js-library/respoke.Group.html">Groups</a> section of the API reference.
    
<br/>
### Return all members of the group:

    group.getMembers({
        onSuccess: function(connections) {
            connections.forEach(
                function(connection) {
                    var endpoint = connection.getEndpoint();
                }
            );
        }
    });

### When members join the group:

    group.listen("join", function(e) {
        var endpoint = e.connection.getEndpoint();
    });

### When members leave the group:

    group.listen("leave", function(e) {
        var endpoint = e.connection.getEndpoint();
    });

## Related Guides
[Group Messaging](/client/javascript/guide/messaging-group.md)
{'fraction_non_alphanumeric': 0.11370631902951295, 'fraction_numerical': 0.003621220351258374, 'mean_word_length': 3.2071591774562074, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2357625', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1493, 'n_words': 543}