-
-
Save glongh/7f5304f7704416d18357988de9f9b441 to your computer and use it in GitHub Desktop.
Advanced Channel Groups: Friend Lists, Status Feed and Presence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Initialize with UUID (from successful authentication response with backend) | |
| var p = PUBNUB.init({ | |
| publish_key: "...", | |
| subscribe_key: "...", | |
| uuid: "0c2340c2-8cc1-4898-8868-444ba77d02d2::web" | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Initialize with UUID (from successful authentication response with backend) | |
| var p = PUBNUB.init({ | |
| publish_key: "...", | |
| subscribe_key: "...", | |
| uuid: "user-a" | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Publish a status message | |
| p.publish({ | |
| channel: "ch-user-a-status", | |
| message: { author: "user-a", status: "I am reading about Advanced Channel Groups!", timestamp: Date.now() / 1000 }, | |
| callback: function(m) { | |
| console.log("PUB: ", m); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Add ch-user-a-present to cg-user-a-friends | |
| p.channel_group_add_channel({ | |
| channel_group: "cg-user-a-friends", | |
| channel: "ch-user-a-present", | |
| callback: function(m) { | |
| console.log("CG-Add: ", m); | |
| } | |
| }); | |
| // Add ch-user-a-present to cg-user-a-status-feed | |
| p.channel_group_add_channel({ | |
| channel_group: "cg-user-a-status-feed", | |
| channel: "ch-user-a-present", | |
| callback: function(m) { | |
| console.log("CG-Add: ", m); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ************************************ | |
| // * User A and User B become friends | |
| // ************************************ | |
| // Add User B to User A's groups: Add ch-user-b-present to cg-user-a-friends | |
| p.channel_group_add_channel({ | |
| channel_group: "cg-user-a-friends", | |
| channel: "ch-user-b-present", | |
| callback: function(m) { | |
| console.log("CG-Add: ", m); | |
| } | |
| }); | |
| // Add User B to User A's groups: ch-user-b-status to cg-user-a-status-feed | |
| p.channel_group_add_channel({ | |
| channel_group: "cg-user-a-status-feed", | |
| channel: "ch-user-b-status", | |
| callback: function(m) { | |
| console.log("CG-Add: ", m); | |
| } | |
| }); | |
| // Add User A to User B's groups: Add ch-user-a-present to cg-user-b-friends | |
| p.channel_group_add_channel({ | |
| channel_group: "cg-user-b-friends", | |
| channel: "ch-user-a-present", | |
| callback: function(m) { | |
| console.log("CG-Add: ", m); | |
| } | |
| }); | |
| // Add User B to User A's groups: ch-user-a-status to cg-user-b-status-feed | |
| p.channel_group_add_channel({ | |
| channel_group: "cg-user-b-status-feed", | |
| channel: "ch-user-a-status", | |
| callback: function(m) { | |
| console.log("CG-Add: ", m); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Get the List of Friends | |
| p.channel_group_list_channels({ | |
| channel_group: "cg-user-a-friends", | |
| callback: function(m) { | |
| console.log("FRIENDLIST: ", m); | |
| } | |
| }); | |
| // Which Friends are online right now | |
| p.here_now({ | |
| channel_group: "cg-user-a-friends", | |
| callback: function(m) { | |
| console.log("ONLINE NOW: ", m); | |
| } | |
| }); | |
| // Watch Friends come online / go offline | |
| p.subscribe({ | |
| channel_group: "cg-user-a-friends-pnpres", | |
| message: function(m,a,b,c) { | |
| console.log("FRIEND PRESENCE: ", m,a,b,c); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Get Status Feed Messages | |
| p.subscribe({ | |
| channel_group: "cg-user-a-status-feed", | |
| message: function(m,a,b,c) { | |
| console.log("STATUS: ", m,a,b,c); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment