diff --git a/web/app/assets/javascripts/JamServer.js b/web/app/assets/javascripts/JamServer.js index f150b12cf..cdf22ddb7 100644 --- a/web/app/assets/javascripts/JamServer.js +++ b/web/app/assets/javascripts/JamServer.js @@ -839,7 +839,6 @@ : null, // latency tester doesn't have the stun class loaded }; var uri = context.gon.websocket_gateway_uri + "?" + $.param(params); // Set in index.html.erb. - logger.debug("connecting websocket: " + uri); server.connecting = true; @@ -1002,6 +1001,7 @@ }; server.onMessage = function (e) { + console.log("__ONMESSAGE__", JSON.parse(e.data)) var message = JSON.parse(e.data), messageType = message.type.toLowerCase(), payload = message[messageType], diff --git a/web/app/assets/javascripts/everywhere/everywhere.js b/web/app/assets/javascripts/everywhere/everywhere.js index 8d7d88e17..1791751ef 100644 --- a/web/app/assets/javascripts/everywhere/everywhere.js +++ b/web/app/assets/javascripts/everywhere/everywhere.js @@ -2,6 +2,7 @@ // !!!! Keep white space after last require !!!! // //= require fakeJamClient +//= require fakeJamClientProxy //= require fakeJamClientMessages //= require fakeJamClientRecordings //= require qwebchannel.js @@ -36,6 +37,7 @@ if(!app) throw "app not found"; // makes window.jamClient / context.jamClient set to something non-null very early on + console.log("____DEBUG everywhere", context.jamClient) context.JK.initJamClient(app); updateScoringIntervals(); diff --git a/web/app/assets/javascripts/fakeJamClient.js b/web/app/assets/javascripts/fakeJamClient.js index fe7589ab4..20ac0d122 100644 --- a/web/app/assets/javascripts/fakeJamClient.js +++ b/web/app/assets/javascripts/fakeJamClient.js @@ -923,6 +923,7 @@ } function SessionSetAlertCallback(callback) { + //console('running.....') alertCallbackName = callback; // simulate a backend alert @@ -1529,6 +1530,12 @@ return {} } + function RegisterSessionJoinLeaveRequestCallBack(){} + + function RegisterGenericCallBack(){} + + function GetDetailedOS(){} + // Javascript Bridge seems to camel-case // Set the instance functions: this.AbortRecording = AbortRecording; @@ -1575,6 +1582,8 @@ this.GetStaticPort = GetStaticPort; this.SetStaticPort = SetStaticPort; this.connected = true; + this.RegisterGenericCallBack = RegisterGenericCallBack; + this.GetDetailedOS = GetDetailedOS; // FTUE (round 3) this.FTUESetInputMusicDevice = FTUESetInputMusicDevice; @@ -1664,6 +1673,7 @@ this.SessionPageEnter = SessionPageEnter; this.SessionPageLeave = SessionPageLeave; this.SetMixerMode = SetMixerMode; + this.RegisterSessionJoinLeaveRequestCallBack = RegisterSessionJoinLeaveRequestCallBack; this.SetVURefreshRate = SetVURefreshRate; this.SessionGetMasterLocalMix = SessionGetMasterLocalMix; @@ -1811,6 +1821,8 @@ this.listTrackAssignments = listTrackAssignments; this.applySubscriptionPolicy = applySubscriptionPolicy; this.clientID = "devtester"; + this.NetworkTestResult = NetworkTestResult; + }; })(window, jQuery); diff --git a/web/app/assets/javascripts/fakeJamClientProxy.js b/web/app/assets/javascripts/fakeJamClientProxy.js new file mode 100644 index 000000000..3b82c028f --- /dev/null +++ b/web/app/assets/javascripts/fakeJamClientProxy.js @@ -0,0 +1,35 @@ +(function(context,$) { + + "use strict"; + + context.JK = context.JK || {}; + context.JK.FakeJamClientProxy = function(app, p2pMessageFactory) { + + const handler = { + get: (target, prop, receiver) => { + return function (...args) { + return new Promise((resolve, reject) => { + try { + //console.log('[fakeJamClient]', prop) + if(target[prop]){ + const result = target[prop].apply(target, args); + resolve(result); + }else{ + console.error('[fakeJamClient] error: No such method in FakeJamClient', prop); + reject(`No such method in FakeJamClient: ${prop}`); + } + + } catch (error) { + console.error('[fakeJamClient] error:', prop, error); + reject(error); + } + }); + } + } + } + + const fakeJamClient = new JK.FakeJamClient(app, p2pMessageFactory); + return new Proxy(fakeJamClient, handler); + } + +})(window, jQuery); \ No newline at end of file diff --git a/web/app/assets/javascripts/jk2021/jk2021.js b/web/app/assets/javascripts/jk2021/jk2021.js index 215372817..d7d9c6239 100644 --- a/web/app/assets/javascripts/jk2021/jk2021.js +++ b/web/app/assets/javascripts/jk2021/jk2021.js @@ -85,6 +85,7 @@ //= require ../web/affiliate_program //= require ../web/affiliate_links //= require fakeJamClient +//= require fakeJamClientProxy //= require fakeJamClientMessages //= require fakeJamClientRecordings //= require JamServer diff --git a/web/app/assets/javascripts/modern/scripts.js b/web/app/assets/javascripts/modern/scripts.js index 392a0d30d..dccf0f4a8 100644 --- a/web/app/assets/javascripts/modern/scripts.js +++ b/web/app/assets/javascripts/modern/scripts.js @@ -18,6 +18,7 @@ //= require modern/JamServer_copy //= require fakeJamClient +//= require fakeJamClientProxy //= require fakeJamClientMessages //= require fakeJamClientRecordings diff --git a/web/app/assets/javascripts/utils.js b/web/app/assets/javascripts/utils.js index eb22a1f28..b6e5c8e65 100644 --- a/web/app/assets/javascripts/utils.js +++ b/web/app/assets/javascripts/utils.js @@ -1124,16 +1124,18 @@ context.JK.initJamClient = async function(app) { // 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(app, p2pMessageFactory); //legacy jamClient calling directly the C++ backend functions - logger.log("Setting up AsyncJamClient..."); - const asyncJamClient = new JK.AsyncJamClient(app); //wraper that asynchronously connects c++ app via websocket - - window.jamClient = asyncJamClient; - - await window.jamClient.SetFakeRecordingImpl(new JK.FakeJamClientRecordings(app, jamClient, p2pMessageFactory)); + client_type = context.JK.clientType(); + if(client_type === 'browser'){ + let p2pMessageFactory = new JK.FakeJamClientMessages(); + logger.log("running in a web browser. bypassing calls to jamClient to FakeJamClient."); + window.jamClient = new JK.FakeJamClientProxy(app, p2pMessageFactory); + window.jamClient.SetFakeRecordingImpl(new JK.FakeJamClientRecordings(app, window.jamClient, p2pMessageFactory)); + }else{ + logger.log("running in client. setting up AsyncJamClient."); + const asyncJamClient = new JK.AsyncJamClient(app); //wraper that asynchronously connects c++ backend + window.jamClient = asyncJamClient; + } } else if(false) { // set to true to time long running bridge calls var originalJamClient = window.jamClient; @@ -1181,12 +1183,13 @@ context.JK.clientType = function () { if (!client_type) { - if (context.jamClient) { - client_type = context.JK.isQWebEngine ? 'client' : 'browser'; - } - else { - client_type = 'browser'; - } + // if (context.jamClient) { + // client_type = context.JK.isQWebEngine ? 'client' : 'browser'; + // } + // else { + // client_type = 'browser'; + // } + client_type = context.JK.isQWebEngine ? 'client' : 'browser'; } return client_type; } diff --git a/web/app/assets/javascripts/web/web.js b/web/app/assets/javascripts/web/web.js index 241f5fd8f..27ab9921d 100644 --- a/web/app/assets/javascripts/web/web.js +++ b/web/app/assets/javascripts/web/web.js @@ -81,6 +81,7 @@ //= require web/affiliate_program //= require web/affiliate_links //= require fakeJamClient +//= require fakeJamClientProxy //= require fakeJamClientMessages //= require fakeJamClientRecordings //= require JamServer