Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPII-4218: Send UIO+ settings to Morphic #52

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ https://github.com/fluid-project/uio-plus#ui-options-plus-uio) allows you to cus
personal needs and preferences.

_**Note**: The ability to apply an adaptation will vary from page to page_
_**Note**: UIO+ for Morphic is not compatible with Morphic Classic v1.3.5 or earlier_

UI Options Plus for Morphic is the result of a joint effort of the Inclusive Design Research Centre at OCAD University
and the Trace R&D Center at University of Maryland under funding for the FLOE Project from the William and Flora Hewlett
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"infusion": "3.0.0-dev.20200525T161532Z.fc4d4b3.FLUID-6145",
"ws": "7.3.0",
"uio-plus": "0.1.0-dev.20200603T175039Z.86d4551"
"uio-plus": "0.1.0-dev.20200610T141822Z.83bce7f"
},
"devDependencies": {
"deepmerge": "4.2.2",
Expand Down
20 changes: 19 additions & 1 deletion src/js/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@

fluid.defaults("gpii.chrome.morphic", {
gradeNames: "uioPlus.chrome.settings",
invokers: {
updateSettings: {
funcName: "gpii.chrome.morphic.updateSettings",
args: ["{that}", "{arguments}.0", "updateSettings"]
}
},
modelListeners: {
"settings": {
func: "{wsConnector}.sendMessage",
args: ["changeSettings", {settings: "{change}.value"}],
excludeSource: ["init", "updateSettings"],
namespace: "sendToMorphic"
}
},
components: {
wsConnector: {
type: "gpii.wsConnector",
Expand All @@ -25,11 +39,15 @@ fluid.defaults("gpii.chrome.morphic", {
flowManager: "ws://localhost:8081/browserChannel",
retryTime: 10,
listeners: {
"{that}.events.onSettingsChange": "{uioPlus.chrome.settings}.updateSettings"
"{that}.events.onSettingsChange": "{gpii.chrome.morphic}.updateSettings"
}
}
}
}
});

gpii.chrome.morphic.updateSettings = function (that, settings, source) {
that.applier.change("settings", settings || that.options.defaultSettings, "ADD", source);
};

gpii.chrome.morphic();
33 changes: 24 additions & 9 deletions src/js/background/wsConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ fluid.defaults("gpii.wsConnector", {
messageHandler: {
funcName: "gpii.wsConnector.messageHandler",
args: ["{that}", "{arguments}.0"]
},
sendMessage: {
funcName: "gpii.wsConnector.sendMessage",
args: ["{that}", "{arguments}.0", "{arguments}.1"]
}
},
events: {
onConnect: null,
onConnectionSucceeded: null,
onError: null,
onSettingsChange: null
onSettingsChange: null,
onSettingsReceived: null
},
listeners: {
"onCreate.connect": "{wsConnector}.connect",
Expand Down Expand Up @@ -76,8 +81,11 @@ gpii.wsConnector.messageHandler = function (that, ev) {
}
} else if (msg.type === "onSettingsChanged") {
that.events.onSettingsChange.fire(msg.payload ? msg.payload : undefined);
} else if (msg.type === "changeSettingsReceived") {
// confirms that settings sent back across the socket have been received by the server
that.events.onSettingsReceived.fire(msg.payload);
} else {
fluid.log("Unrecognized event/message");
fluid.log("Unrecognized event/message", msg);
}
};

Expand All @@ -100,12 +108,19 @@ gpii.wsConnector.error = function (that, err) {
};

gpii.wsConnector.setup = function (that) {
var authPayload = {
type: "connect",
payload: {
solutionId: that.options.solutionId
}
};
that.socket.send(JSON.stringify(authPayload));
that.sendMessage("connect", {solutionId: that.options.solutionId});
that.socket.onmessage = that.messageHandler;
};

gpii.wsConnector.sendMessage = function (that, type, payload) {
var message = {
type: type,
payload: payload
};

if (that.socket) {
that.socket.send(JSON.stringify(message));
} else {
fluid.log("Unable to send message: " + message + ". No socket connection available.");
}
};
2 changes: 2 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "UI Options Plus (UIO+) for Morphic",
"short_name": "UIO+ for Morphic",
"version": "0.2.0",
"version_name": "0.2.0",
"browser_action": {
"default_title": "UIO+ for Morphic"
},
Expand Down
23 changes: 19 additions & 4 deletions tests/node/wsConnectorTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ fluid.defaults("gpii.chrome.tests.wsConnector.server", {
allowClient: {
funcName: "gpii.chrome.tests.wsConnector.server.allowClient",
args: ["{that}", "{arguments}.0"]
},
broadcastMessage: {
funcName: "gpii.chrome.tests.wsConnector.server.broadcastMessage",
args: ["{that}", "{arguments}.0", "{arguments}.1"]
}
},
listeners: {
Expand All @@ -81,8 +85,8 @@ fluid.defaults("gpii.chrome.tests.wsConnector.server", {
},
modelListeners: {
"settings": {
funcName: "gpii.chrome.tests.wsConnector.server.broadcastSettings",
args: ["{that}", "{change}.value"],
func: "{that}.broadcastMessage",
args: ["onSettingsChanged", "{change}.value"],
namespace: "broadcastSettings",
excludeSource: ["init"]
}
Expand Down Expand Up @@ -136,9 +140,9 @@ gpii.chrome.tests.wsConnector.server.setupClient = function (that, client) {
client.on("message", that.events.onMessage.fire);
};

gpii.chrome.tests.wsConnector.server.broadcastSettings = function (that, settings) {
gpii.chrome.tests.wsConnector.server.broadcastMessage = function (that, type, settings) {
var msg = {
type: "onSettingsChanged",
type: type,
payload: settings
};
if (that.model.clientSocket) {
Expand Down Expand Up @@ -287,6 +291,17 @@ fluid.defaults("gpii.chrome.tests.wsConnector.tester", {
listener: "gpii.chrome.tests.wsConnector.checkSettings",
args: ["{arguments}.0"]
}]
}, {
name: "Server sends changeSettingsReceived message",
expect: 1,
sequence: [{
func: "{server}.broadcastMessage",
args: ["changeSettingsReceived", "{that}.options.payloads.test1.settings"]
}, {
event: "{clientOne}.events.onSettingsReceived",
listener: "gpii.chrome.tests.wsConnector.checkSettings",
args: ["{arguments}.0", "{that}.options.payloads.test1.settings"]
}]
}, {
name: "Server disconnects client, client reconnects",
expect: 2,
Expand Down