Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Added roomanchors plugin. #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions roomanchors/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (C) 2014 Mojo Lingo LLC

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 changes: 17 additions & 0 deletions roomanchors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Room Anchors

A plugin for Candy Chat to create and listen to anchors in the URL for rooms.

## Usage
Include the JavaScript file:
```HTML
<script type="text/javascript" src="candyshop/roomanchors/roomanchors.js"></script>
```

To enable this plugin, add its `init` method after you `init` Candy:
```JavaScript
CandyShop.RoomAnchors.init();
Candy.connect();
```

To use this plugin, simply add the name of a room to the end of the URL, like `mydomain.com/chat#room-name` and it will join that room if it exists or create it if it doesn't. When you change rooms, the name of the room you switch to will autopopulate into the address bar as well.
86 changes: 86 additions & 0 deletions roomanchors/roomanchors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/** File: roomanchors.js
* Handling for joining rooms when included as part of the chat URL
*
* Authors:
* - Ben Klang <bklang@mojolingo.com>
*
* Copyright:
* - (c) 2014 Mojo Lingo LLC. All rights reserved.
*/

var CandyShop = (function(self) { return self; }(CandyShop || {}));

CandyShop.RoomAnchors = (function(self, Candy, $) {
/** Object: about
* About RoomAnchors plugin
*
* Contains:
* (String) name - Candy Plugin RoomAnchors
* (Float) version - andy Plugin Available Rooms version
*/
self.about = {
name: 'Candy Plugin RoomAnchors',
version: '0.1.0'
};

/** Object: _options
* Options for this plugin's operation
*
* Options:
* (String) conferenceDomain - Domain suffix to be applied to the room name in the anchor
*/
var _options = {
conferenceDomain: null
};

/** Function: init
*/
self.init = function(options){
// apply the supplied options to the defaults specified
$.extend(true, _options, options);

if (_options.conferenceDomain === '' || _options.conferenceDomain === null) {
throw('You must configure the conference domain.');
}

// Ensure we have a leading "@"
if (_options.conferenceDomain.indexOf('@') === -1) {
_options.conferenceDomain = "@" + _options.conferenceDomain;
}

$(Candy).on('candy:view.connection.status-5', self.refresh);
$(Candy).on('candy:view.connection.status-8', self.refresh);

$(Candy).on('candy:view.room.after-show', function(ev, data) {
if (
data.roomJid === CandyShop.StaticLobby.getLobbyFakeJid() ||
data.roomJid.indexOf(_options.conferenceDomain) === -1 || // Is not a MUC JID
Strophe.getResourceFromJid(data.roomJid) // Is a MUC-based 1-on-1
) {
return false;
}
window.location.hash = '#' + data.roomJid.split('@')[0];
});
};

self.refresh = function() {
if (window.location.hash !== '') {
// Join, just in case we aren't already
Candy.Core.Action.Jabber.Room.Join(self.roomAnchorJid());
// Show, just in case we were already in the room
try {
Candy.View.Pane.Room.show(self.roomAnchorJid());
} catch(ex) {
// This may happen if we attempt to show right after a join, but the join hasn't
// yet finished (a race condition). Ignore it, since the act of joining
// will focus the room.
}
}
};

self.roomAnchorJid = function() {
return window.location.hash.substring(1) + _options.conferenceDomain;
};

return self;
}(CandyShop.RoomAnchors || {}, Candy, jQuery));