110 lines
3.9 KiB
Plaintext
110 lines
3.9 KiB
Plaintext
= render :partial => "jamServer"
|
|
|
|
:javascript
|
|
$(function() {
|
|
JK = JK || {};
|
|
|
|
JK.root_url = "#{root_url}"
|
|
|
|
<% if Rails.env == "development" %>
|
|
// if in development mode, we assume you are running websocket-gateway
|
|
// on the same host as you hit your server.
|
|
JK.websocket_gateway_uri = "ws://" + location.hostname + ":6767/websocket";
|
|
<% else %>
|
|
// but in any other mode, just trust the config coming through gon
|
|
JK.websocket_gateway_uri = gon.websocket_gateway_uri
|
|
<% end %>
|
|
if (console) { console.log("websocket_gateway_uri:" + JK.websocket_gateway_uri); }
|
|
|
|
|
|
// If no trackVolumeObject (when not running in native client)
|
|
// create a fake one.
|
|
if (!(window.trackVolumeObject)) {
|
|
window.trackVolumeObject = {
|
|
bIsMediaFile: false,
|
|
broadcast: false,
|
|
clientID: "",
|
|
instrumentID: "",
|
|
master: false,
|
|
monitor: false,
|
|
mute: false,
|
|
name: "",
|
|
objectName: "",
|
|
record: false,
|
|
volL: 0,
|
|
volR: 0,
|
|
wigetID: ""
|
|
};
|
|
}
|
|
|
|
|
|
// Some things can't be initialized until we're connected. Put them here.
|
|
function _initAfterConnect(connected) {
|
|
if (this.didInitAfterConnect) return;
|
|
this.didInitAfterConnect = true
|
|
|
|
if(!connected) {
|
|
jamServer.initiateReconnect(null, true);
|
|
}
|
|
}
|
|
|
|
JK.app = JK.JamKazam();
|
|
var jamServer = new JK.JamServer(JK.app);
|
|
jamServer.initialize();
|
|
|
|
// If no jamClient (when not running in native client)
|
|
// create a fake one.
|
|
if (!(window.jamClient)) {
|
|
var p2pMessageFactory = new JK.FakeJamClientMessages();
|
|
window.jamClient = new JK.FakeJamClient(JK.app, p2pMessageFactory);
|
|
window.jamClient.SetFakeRecordingImpl(new JK.FakeJamClientRecordings(JK.app, jamClient, p2pMessageFactory));
|
|
}
|
|
else if(false) { // set to true to time long running bridge calls
|
|
var originalJamClient = window.jamClient;
|
|
var interceptedJamClient = {};
|
|
$.each(Object.keys(originalJamClient), function(i, key) {
|
|
if(key.indexOf('(') > -1) {
|
|
// this is a method. time it
|
|
var jsKey = key.substring(0, key.indexOf('('))
|
|
console.log("replacing " + jsKey)
|
|
interceptedJamClient[jsKey] = function() {
|
|
var original = originalJamClient[key]
|
|
var start = new Date();
|
|
if(key == "FTUEGetDevices()") {
|
|
var returnVal = eval('originalJamClient.FTUEGetDevices(' + arguments[0] + ')');
|
|
}
|
|
else {
|
|
var returnVal = original.apply(originalJamClient, arguments);
|
|
}
|
|
var time = new Date().getTime() - start.getTime();
|
|
if(time >= 0) { // if 0, you'll see ALL bridge calls. If you set it to a higher value, you'll only see calls that are beyond that threshold
|
|
console.error(time + "ms jamClient." + jsKey + ' returns=', returnVal);
|
|
}
|
|
|
|
return returnVal;
|
|
}
|
|
}
|
|
else {
|
|
// we need to intercept properties... but how?
|
|
}
|
|
});
|
|
|
|
|
|
window.jamClient = interceptedJamClient;
|
|
}
|
|
|
|
// Let's get things rolling...
|
|
//if (JK.currentUserId) {
|
|
|
|
// JK.app.initialize();
|
|
|
|
|
|
JK.JamServer.connect() // singleton here defined in JamServer.js
|
|
.done(function() {
|
|
_initAfterConnect(true);
|
|
})
|
|
.fail(function() {
|
|
_initAfterConnect(false);
|
|
});
|
|
}
|
|
}) |