fix Server Disconnect

add FakeJamClientProxy to wrap FakeJamClient. It accepts API calls and
sends back javascript promises.
This commit is contained in:
Nuwan 2023-07-06 09:00:49 +05:30
parent dd4f62cb07
commit 69addda196
8 changed files with 71 additions and 16 deletions

View File

@ -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],

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -85,6 +85,7 @@
//= require ../web/affiliate_program
//= require ../web/affiliate_links
//= require fakeJamClient
//= require fakeJamClientProxy
//= require fakeJamClientMessages
//= require fakeJamClientRecordings
//= require JamServer

View File

@ -18,6 +18,7 @@
//= require modern/JamServer_copy
//= require fakeJamClient
//= require fakeJamClientProxy
//= require fakeJamClientMessages
//= require fakeJamClientRecordings

View File

@ -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
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;
await window.jamClient.SetFakeRecordingImpl(new JK.FakeJamClientRecordings(app, jamClient, p2pMessageFactory));
}
}
else if(false) { // set to true to time long running bridge calls
var originalJamClient = window.jamClient;
@ -1181,13 +1183,14 @@
context.JK.clientType = function () {
if (!client_type) {
if (context.jamClient) {
// if (context.jamClient) {
// client_type = context.JK.isQWebEngine ? 'client' : 'browser';
// }
// else {
// client_type = 'browser';
// }
client_type = context.JK.isQWebEngine ? 'client' : 'browser';
}
else {
client_type = 'browser';
}
}
return client_type;
}
/**

View File

@ -81,6 +81,7 @@
//= require web/affiliate_program
//= require web/affiliate_links
//= require fakeJamClient
//= require fakeJamClientProxy
//= require fakeJamClientMessages
//= require fakeJamClientRecordings
//= require JamServer