Created
September 5, 2014 01:46
-
-
Save aoberoi/47a0a4f3dc1bc82d629f to your computer and use it in GitHub Desktop.
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
(function() { | |
var OpenTokCall, counter, displayTime, runClock, startClock, stopClock, | |
__bind = function(fn, me) { | |
return function() { | |
return fn.apply(me, arguments); | |
}; | |
}; | |
runClock = void 0; | |
counter = 0; | |
startClock = function() { | |
runClock = window.setInterval(displayTime, 1000); | |
}; | |
stopClock = function() { | |
window.clearInterval(runClock); | |
counter = 0; | |
}; | |
displayTime = function() { | |
$('#call-modal .timer').html("TIME: " + (moment().hour(0).minute(0).second(counter++).format("mm:ss"))); | |
}; | |
OpenTokCall = (function() { | |
function OpenTokCall() { | |
this.startCall = __bind(this.startCall, this); | |
this.pubContainer = document.createElement("div"); | |
this.pubContainer.className = 'attorney-stream'; | |
this.publisher; | |
this.sessionId = $('#current-attorney').data('open-tok-session-id'); | |
this.apiKey = $('#current-attorney').data('open-tok-api-key'); | |
this.token = $('#current-attorney').data('open-tok-token'); | |
OT.on({ | |
exception: function(e) { | |
if (typeof e.target.connect !== "undefined") { | |
return e.target.connect(this.apiKey, this.token); | |
} | |
} | |
}); | |
OT.setLogLevel(OT.ERROR); | |
this.session = OT.initSession(this.sessionId); | |
this.session.on({ | |
sessionConnected: (function(_this) { | |
return function(event) { | |
}; | |
})(this), | |
streamCreated: (function(_this) { | |
return function(event) { | |
var stream; | |
stream = event.stream; | |
if (stream.connection.data != null) { | |
return _this.getCall(JSON.parse(stream.connection.data).call.search_token, function(data) { | |
return _this.getUser(data, function(userData, callData) { | |
return _this.loadIncomingCallBox(userData, callData, stream); | |
}); | |
}); | |
} | |
}; | |
})(this), | |
streamDestroyed: (function(_this) { | |
return function(event) { | |
$('.user-stream').remove(); | |
$('.attorney-stream').remove(); | |
return _this.showNoCall($('#call-modal').modal('hide')); | |
}; | |
})(this), | |
sessionDisconnected: (function(_this) { | |
return function(event) { | |
}; | |
})(this), | |
connectionDestroyed: (function(_this) { | |
return function(event) { | |
}; | |
})(this) | |
}); | |
this.session.connect(this.apiKey, this.token); | |
} | |
OpenTokCall.prototype.loadIncomingCallBox = function(userData, callData, stream) { | |
$('#call-incoming-box h2.user-name').text("" + userData.first_name + " " + userData.last_name); | |
$('#call-incoming-box p.call-message').text(callData.message); | |
$('#call-incoming-box .call-back-image').attr('src', userData.profile_image.url); | |
$('#call-incoming-box .call-inner-image').attr('src', userData.profile_image.url); | |
$('#call-incoming-box #call-status .pass-call').on('click', (function(_this) { | |
return function() { | |
return _this.session.forceDisconnect(stream.connection, function() { | |
return _this.updateCallStatus(callData.id, 'rejected'); | |
}); | |
}; | |
})(this)); | |
$('#call-incoming-box #call-status .accept-call').on('click', (function(_this) { | |
return function() { | |
$('#attorney-call-video').append(_this.pubContainer); | |
_this.publisher = OT.initPublisher(_this.apiKey, 'attorney-call-video').on({ | |
streamDestroyed: function(event) { | |
stopClock(); | |
location.reload(); | |
return event.preventDefault(); | |
}, | |
streamCreated: function(event) { | |
}, | |
sessionDisconnected: function(event) { | |
}, | |
connectionDestroyed: function(event) { | |
} | |
}); | |
return _this.session.publish(_this.publisher, function() { | |
return _this.startCall(stream, userData, callData); | |
}); | |
}; | |
})(this)); | |
$('#no-call-box').hide(); | |
return $('#call-incoming-box').show(); | |
}; | |
OpenTokCall.prototype.startCall = function(stream, userData, callData) { | |
var height, subContainer, width; | |
$('#call-modal h2.user-name').text("" + userData.first_name + " " + userData.last_name); | |
$('#call-modal p.call-message').text(callData.message); | |
$('#call-modal .end-call').on("click", (function(_this) { | |
return function() { | |
return _this.session.forceDisconnect(stream.connection, function() { | |
return _this.updateCallStatus(callData.id, 'rejected'); | |
}); | |
}; | |
})(this)); | |
height = $('#user-call-video').height(); | |
width = $('#user-call-video').width(); | |
subContainer = document.createElement("div"); | |
subContainer.className = 'user-stream'; | |
subContainer.id = "stream-" + stream.streamId; | |
$('#user-call-video').append(subContainer); | |
this.subscriber = this.session.subscribe(stream, subContainer, { | |
height: height, | |
width: width | |
}, (function(_this) { | |
return function() { | |
startClock(); | |
return _this.updateCallStatus(callData.id, 'success'); | |
}; | |
})(this)); | |
return this.subscriber.on({ | |
destroyed: (function(_this) { | |
return function(event) { | |
return _this.session.unpublish(_this.publisher); | |
}; | |
})(this) | |
}); | |
}; | |
OpenTokCall.prototype.getCall = function(search_token, callback) { | |
return $.ajax('/attorneys/calls/find_by', { | |
type: 'GET', | |
dataType: 'json', | |
data: { | |
search_token: search_token | |
}, | |
success: (function(_this) { | |
return function(data) { | |
return callback(data); | |
}; | |
})(this) | |
}); | |
}; | |
OpenTokCall.prototype.getUser = function(data, callback) { | |
return $.ajax("/attorneys/users/" + data.user_id, { | |
type: 'GET', | |
dataType: 'json', | |
success: function(userData) { | |
return callback(userData, data); | |
} | |
}); | |
}; | |
OpenTokCall.prototype.updateCallStatus = function(call_id, status) { | |
return $.ajax("/attorneys/calls/" + call_id, { | |
type: 'PUT', | |
dataType: 'json', | |
data: { | |
call: { | |
status: status | |
} | |
} | |
}); | |
}; | |
OpenTokCall.prototype.showNoCall = function(callback) { | |
$('#call-incoming-box').hide(); | |
$('#no-call-box').show(); | |
return callback; | |
}; | |
return OpenTokCall; | |
})(); | |
jQuery(function() { | |
if ($('#current-attorney').length) { | |
return new OpenTokCall; | |
} | |
}); | |
}).call(this); | |
(function() { | |
var AttorneyStatusUpdate; | |
jQuery(function() { | |
new AttorneyStatusUpdate; | |
return $('#filter-question-us-state').on('change', function(event) { | |
return this.form.submit(); | |
}); | |
}); | |
AttorneyStatusUpdate = (function() { | |
function AttorneyStatusUpdate() { | |
$(document).on('click', '#attorney-status', this.updateAttorneyStatus); | |
} | |
AttorneyStatusUpdate.prototype.updateAttorneyStatus = function(event) { | |
var end_point, status_link; | |
status_link = $(".status-change"); | |
end_point = status_link.attr("href"); | |
$.get("" + end_point + ".json", function(data) { | |
return status_link.text(data.attorney_status); | |
}); | |
return event.preventDefault(); | |
}; | |
return AttorneyStatusUpdate; | |
})(); | |
}).call(this); | |
(function() { | |
}).call(this); | |
(function() { | |
}).call(this); | |
(function() { | |
var userCall; | |
userCall = function(sessionId, token) { | |
var apiKey, other_streams, publisher, session; | |
apiKey = $('#selected-user').data('open-tok-api-key'); | |
console.log("Session id: " + sessionId); | |
console.log("API Key: " + apiKey); | |
publisher = void 0; | |
other_streams = void 0; | |
session = OT.initSession(sessionId); | |
session.on({ | |
sessionConnected: function(event) { | |
var pubOptions; | |
pubOptions = { | |
publishAudio: false, | |
publishVideo: true | |
}; | |
publisher = OT.initPublisher(apiKey, "publisher", pubOptions); | |
session.publish(publisher); | |
other_streams = event.streams; | |
}, | |
streamCreated: function(event) { | |
var i, stream, subContainer; | |
i = 0; | |
while (i < event.streams.length) { | |
stream = event.streams[i]; | |
subContainer = document.createElement("div"); | |
subContainer.id = "stream-" + stream.streamId; | |
document.getElementById("subscribers").appendChild(subContainer); | |
session.subscribe(stream, subContainer); | |
i++; | |
} | |
} | |
}); | |
return session.connect(apiKey, token); | |
}; | |
jQuery(function() { | |
return $('#select_attorney_call_form').on('change', function(event) { | |
var selected; | |
selected = $(event.target); | |
console.log("/attorneys/attorneys/" + (selected.val()) + "/call.json"); | |
return $.ajax("/attorneys/attorneys/" + (selected.val()) + "/calls", { | |
type: 'POST', | |
dataType: 'json', | |
data: { | |
call: { | |
user_id: $('#selected-user').data('user-id'), | |
attorney_id: selected.val() | |
} | |
}, | |
success: function(data, textStatus, jqXHR) { | |
return userCall(data.open_tok_session_id, data.user_token); | |
} | |
}); | |
}); | |
}); | |
}).call(this); | |
(function() { | |
jQuery(function() { | |
return $('#call_id').on('change', function() { | |
return $('#call_form').submit(); | |
}); | |
}); | |
}).call(this); | |
/* | |
Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. | |
For licensing, see LICENSE.html or http://ckeditor.com/license | |
*/ | |
CKEDITOR.editorConfig = function(config) | |
{ | |
// Define changes to default configuration here. For example: | |
config.toolbar = [ | |
{name: 'document',groups: ['mode', 'document', 'doctools'],items: ['Source', '-', 'Templates']}, | |
{name: 'clipboard',groups: ['clipboard', 'undo'],items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo']}, | |
{name: 'editing',groups: ['find', 'selection', 'spellchecker'],items: ['Find', 'Replace', '-', 'SelectAll', '-', 'Scayt']}, | |
'/', | |
{name: 'basicstyles',groups: ['basicstyles', 'cleanup'],items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']}, | |
{name: 'paragraph',groups: ['list', 'indent', 'blocks', 'align', 'bidi'],items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl']}, | |
'/', | |
{name: 'links',items: ['Link', 'Unlink', 'Anchor']}, | |
{name: 'insert',items: ['Image', 'Table', 'HorizontalRule', 'PageBreak']}, | |
'/', | |
{name: 'styles',items: ['Styles', 'Format', 'Font', 'FontSize']}, | |
{name: 'colors',items: ['TextColor', 'BGColor']}, | |
{name: 'tools',items: ['Maximize', 'ShowBlocks']} | |
]; | |
/* Filebrowser routes */ | |
// The location of an external file browser, that should be launched when "Browse Server" button is pressed. | |
config.filebrowserBrowseUrl = "/ckeditor/attachment_files"; | |
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Flash dialog. | |
config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files"; | |
// The location of a script that handles file uploads in the Flash dialog. | |
config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files"; | |
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Link tab of Image dialog. | |
config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures"; | |
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Image dialog. | |
config.filebrowserImageBrowseUrl = "/ckeditor/pictures"; | |
// The location of a script that handles file uploads in the Image dialog. | |
config.filebrowserImageUploadUrl = "/ckeditor/pictures"; | |
// The location of a script that handles file uploads. | |
config.filebrowserUploadUrl = "/ckeditor/attachment_files"; | |
// Rails CSRF token | |
config.filebrowserParams = function() { | |
var csrf_token, csrf_param, meta, | |
metas = document.getElementsByTagName('meta'), | |
params = new Object(); | |
for (var i = 0; i < metas.length; i++) { | |
meta = metas[i]; | |
switch (meta.name) { | |
case "csrf-token": | |
csrf_token = meta.content; | |
break; | |
case "csrf-param": | |
csrf_param = meta.content; | |
break; | |
default: | |
continue; | |
} | |
} | |
if (csrf_param !== undefined && csrf_token !== undefined) { | |
params[csrf_param] = csrf_token; | |
} | |
return params; | |
}; | |
config.addQueryString = function(url, params) { | |
var queryString = []; | |
if (!params) { | |
return url; | |
} else { | |
for (var i in params) | |
queryString.push(i + "=" + encodeURIComponent(params[i])); | |
} | |
return url + ((url.indexOf("?") != -1) ? "&" : "?") + queryString.join("&"); | |
}; | |
// Integrate Rails CSRF token into file upload dialogs (link, image, attachment and flash) | |
CKEDITOR.on('dialogDefinition', function(ev) { | |
// Take the dialog name and its definition from the event data. | |
var dialogName = ev.data.name; | |
var dialogDefinition = ev.data.definition; | |
var content, upload; | |
if (CKEDITOR.tools.indexOf(['link', 'image', 'attachment', 'flash'], dialogName) > -1) { | |
content = (dialogDefinition.getContents('Upload') || dialogDefinition.getContents('upload')); | |
upload = (content == null ? null : content.get('upload')); | |
if (upload && upload.filebrowser && upload.filebrowser['params'] === undefined) { | |
upload.filebrowser['params'] = config.filebrowserParams(); | |
upload.action = config.addQueryString(upload.action, upload.filebrowser['params']); | |
} | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment