A simple multi-party text chat plugin written in Javascript. This project is built upon the Signaling Library of the OpenTok API.
Install using Bower:
bower install opentok-chattr
or clone this repo.
The OpenTok for WebRTC JS API is required. The jquery.event.ue and jquery-udraggable libraries are required for a draggable interface.
- Clone this repo.
- Get your API Key, Session ID, and Token from your TokBox Dashboard. For help on this step, visit the Quickstart page in the OpenTok Docs.
- In
demo.html, eplaceAPI KEY,SESSION ID, andTOKENwith your corresponding credentials. - Serve
demo.htmlon a web-server using e.g.npm install http-server -g;http-serverorpython -m SimpleHTTPServer 8000
See demo.html for a complete example.
Include all required scripts:
<script src="//static.opentok.com/webrtc/v2.2/js/opentok.min.js" type="text/javascript" charset="utf-8"></script>
<script src="bower_components/jquery/dist/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="bower_components/jquery.event.ue/jquery.event.ue.js" type="text/javascript" charset="utf-8"></script>
<script src="bower_components/jquery.udraggable/jquery.udraggable.js" type="text/javascript" charset="utf-8"></script>
<script src="OpenTokChattr.js" type="text/javascript" charset="utf-8"></script>Include the OpenTokChattr.css file:
<link rel="stylesheet" type="text/css" href="OpenTokChattr.css" />Create an OpenTok session and connect to the session.
var apiKey = "API KEY";
var sessionId = "SESSION ID";
var token = "TOKEN";
var otSession = OT.initSession(apiKey,sessionId);
otSession.connect(token);Now, initialize an OpenTokChattr by calling:
var chattr = new OpenTokChattr("#container", "Room Id", otSession, options);The first argument is the jQuery selector string for the container element of the OpenTokChattr window.
The second argument is the name of the room, which will appear at the top of the OpenTokChattr window.
The third argument is the OpenTok Session object that was previously initialized.
The final (and optional) argument is an object of any additional options. Include any of the following in the options argument:
var options = {
"draggable": true, //Allows the chat window to be dragged
"closeable": function(){ //Shows a close icon and performs this function when it is clicked
$("#chattr").hide();
}
}