diff --git a/docs/generatedApiDocs/GitHub-API-Index.md b/docs/generatedApiDocs/GitHub-API-Index.md index 15d7a75f95..5a9ce1a346 100644 --- a/docs/generatedApiDocs/GitHub-API-Index.md +++ b/docs/generatedApiDocs/GitHub-API-Index.md @@ -10,7 +10,6 @@ The list of all APIs for phoenix. 1. [utils/ExtensionInterface](ExtensionInterface-API) 1. [utils/FeatureGate](FeatureGate-API) 1. [utils/Metrics](Metrics-API) -1. [utils/PhoenixComm](PhoenixComm-API) 1. [widgets/NotificationUI](NotificationUI-API) 1. [worker/ExtensionsWorker](ExtensionsWorker-API) 1. [worker/IndexingWorker](IndexingWorker-API) diff --git a/docs/generatedApiDocs/utils/PhoenixComm-API.md b/docs/generatedApiDocs/utils/PhoenixComm-API.md deleted file mode 100644 index b244bf8bc9..0000000000 --- a/docs/generatedApiDocs/utils/PhoenixComm-API.md +++ /dev/null @@ -1,70 +0,0 @@ - - -## utils/PhoenixComm - -PhoenixComm APIs can be used to communicate between Phoenix browser tabs/iframe instances across the browser. - -### Import - -```js -// usage within core: -const PhoenixComm = require("utils/PhoenixComm"); - -// usage within default extensions: -const PhoenixComm = brackets.getModule("utils/PhoenixComm"); -``` - -## API - -This section outlines the properties and methods available in this module - -## PHOENIX_INSTANCE_ID - -A unique ID for each phoenix window instance. Test windows also have an id. - -Type: [String][1] - -## broadcast - -Broadcast a message to other Phoenix instances. To listen to the broadcast message on another phoenix instance, -use PhoenixComm.on methord - -Type: [function][2] - -### Parameters - -* `eventType` **[string][1]** The kind of Event Type that needs to be sent to other phoenix instances -* `data` **[Object][3]** The Data object to broadcast - -### Examples - -To broadcast/receive a hello message to everyone - -```javascript -PhoenixComm.broadcast("MSG_TYPE", "hello world", "ms", 200); -// now to receive the message of the type, use the on method -PhoenixComm.on("MSG_TYPE", (evt, data) =>{ - console.log(data); // hello world -}) -``` - -## getAllInstanceDetails - -Returns a map of all instances of Phoenix. Mapped from instanceID to detail {instanceID, isTestWindow}. -Will not contain self instance details. - -Returns **[Object][3]** that maps instance IDs that are currently online to the instance details. - -## EVENTS - -This section outlines the standard events generated by PhoenixComm. use -`PhoenixComm.on(PhoenixComm.EVENT_PHOENIX_CLOSING,fn)` to listen to these events. - -* `EVENT_PHOENIX_CLOSING` - Event raised when another phoenix window is closing. Raises `instanceID` -* `EVENT_PHOENIX_OPENED` - Raises `{instanceID, isTestWindow}` when another phoenix window is opened. - -[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String - -[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function - -[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object diff --git a/src/brackets.js b/src/brackets.js index 379051d3c1..4e85b096e8 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -62,7 +62,6 @@ define(function (require, exports, module) { require("thirdparty/CodeMirror/keymap/sublime"); require("worker/WorkerComm"); - require("utils/PhoenixComm"); require("utils/ZipUtils"); // Load dependent modules @@ -274,7 +273,6 @@ define(function (require, exports, module) { MultiRangeInlineEditor: require("editor/MultiRangeInlineEditor").MultiRangeInlineEditor, NativeApp: require("utils/NativeApp"), PerfUtils: require("utils/PerfUtils"), - PhoenixComm: require("utils/PhoenixComm"), PreferencesManager: require("preferences/PreferencesManager"), ProjectManager: require("project/ProjectManager"), QuickViewManager: require("features/QuickViewManager"), diff --git a/src/utils/PhoenixComm.js b/src/utils/PhoenixComm.js deleted file mode 100644 index 8f5bdcea36..0000000000 --- a/src/utils/PhoenixComm.js +++ /dev/null @@ -1,147 +0,0 @@ -/* - * GNU AGPL-3.0 License - * - * Copyright (c) 2021 - present core.ai . All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see https://opensource.org/licenses/AGPL-3.0. - * - */ - -/*global Phoenix*/ - -// @INCLUDE_IN_API_DOCS -/** - * PhoenixComm APIs can be used to communicate between Phoenix browser tabs/iframe instances across the browser. - * - * ### Import - * ```js - * // usage within core: - * const PhoenixComm = require("utils/PhoenixComm"); - * - * // usage within default extensions: - * const PhoenixComm = brackets.getModule("utils/PhoenixComm"); - * ``` - * - * @module utils/PhoenixComm - */ -define(function (require, exports, module) { - const EventDispatcher = require("utils/EventDispatcher"); - const _phoenixBroadcastChannel = new BroadcastChannel("PhoenixComm"); - /** - * This section outlines the properties and methods available in this module - * @name API - */ - - /** - * A unique ID for each phoenix window instance. Test windows also have an id. - * @typedef PHOENIX_INSTANCE_ID - * @type {String} - */ - const PHOENIX_INSTANCE_ID = "PH-" + Math.round( Math.random()*1000000000000); - Phoenix.PHOENIX_INSTANCE_ID = PHOENIX_INSTANCE_ID; - const EVENT_PHOENIX_CLOSING = "phoenixClosing", - EVENT_PHOENIX_OPENED = "phoenixOpened", - _EVENT_PHOENIX_INSTANCE_DETAILS = "phoenixInstanceDetails"; - - const _phoenixInstanceDetails = {}; - Phoenix.PHOENIX_INSTANCE_DETAILS = _phoenixInstanceDetails; - - /** - * Broadcast a message to other Phoenix instances. To listen to the broadcast message on another phoenix instance, - * use PhoenixComm.on methord - * @example To broadcast/receive a hello message to everyone - * PhoenixComm.broadcast("MSG_TYPE", "hello world", "ms", 200); - * // now to receive the message of the type, use the on method - * PhoenixComm.on("MSG_TYPE", (evt, data) =>{ - * console.log(data); // hello world - * }) - * - * @param {string} eventType The kind of Event Type that needs to be sent to other phoenix instances - * @param {Object} data The Data object to broadcast - * @type {function} - */ - function broadcast(eventType, data) { - _phoenixBroadcastChannel.postMessage({ - eventType, - data - }); - } - - /** - * Returns a map of all instances of Phoenix. Mapped from instanceID to detail {instanceID, isTestWindow}. - * Will not contain self instance details. - * @return {Object} that maps instance IDs that are currently online to the instance details. - */ - function getAllInstanceDetails() { - return _phoenixInstanceDetails; - } - - function _processBroadcastMessage(event) { - if(event.data && event.data.eventType){ - exports.trigger(event.data.eventType, event.data.data); - return; - } - console.error("Unknown event type for _phoenixBroadcastChannel message: ", event); - } - - _phoenixBroadcastChannel.onmessage = _processBroadcastMessage; - - EventDispatcher.makeEventDispatcher(exports); - - function _getInstanceDetails() { - return { - instanceID: PHOENIX_INSTANCE_ID, - isTestWindow: Phoenix.isTestWindow - }; - } - - broadcast(EVENT_PHOENIX_OPENED, _getInstanceDetails()); - addEventListener( 'beforeunload', function() { - broadcast(EVENT_PHOENIX_CLOSING, PHOENIX_INSTANCE_ID); - }); - - exports.on(EVENT_PHOENIX_CLOSING, (_event, instanceID)=>{ - delete _phoenixInstanceDetails[instanceID]; - }); - - exports.on(EVENT_PHOENIX_OPENED, (_event, instanceDetails)=>{ - _phoenixInstanceDetails[instanceDetails.instanceID] = instanceDetails; - // a new window came up, so we broadcast our instance detail so that everyone(esp. the new window) is updated - // of our instance detail. - broadcast(_EVENT_PHOENIX_INSTANCE_DETAILS, _getInstanceDetails()); - }); - - exports.on(_EVENT_PHOENIX_INSTANCE_DETAILS, (_event, instanceDetails)=>{ - _phoenixInstanceDetails[instanceDetails.instanceID] = instanceDetails; - }); - - // public events - /** - * This section outlines the standard events generated by PhoenixComm. use - * `PhoenixComm.on(PhoenixComm.EVENT_PHOENIX_CLOSING,fn)` to listen to these events. - * - * * `EVENT_PHOENIX_CLOSING` - Event raised when another phoenix window is closing. Raises `instanceID` - * * `EVENT_PHOENIX_OPENED` - Raises `{instanceID, isTestWindow}` when another phoenix window is opened. - * @name EVENTS - */ - - exports.EVENT_PHOENIX_CLOSING = EVENT_PHOENIX_CLOSING; - exports.EVENT_PHOENIX_OPENED = EVENT_PHOENIX_OPENED; - - // Define public API - // exports.on is injected by eventDispatcher - exports.broadcast = broadcast; - exports.getAllInstanceDetails = getAllInstanceDetails; - exports.PHOENIX_INSTANCE_ID = PHOENIX_INSTANCE_ID; -}); diff --git a/test/SpecRunner.js b/test/SpecRunner.js index 8da8b5894a..b188e27c1e 100644 --- a/test/SpecRunner.js +++ b/test/SpecRunner.js @@ -173,7 +173,6 @@ define(function (require, exports, module) { require("language/CodeInspection"); require("thirdparty/lodash"); require("thirdparty/jszip"); - require("utils/PhoenixComm"); require("editor/CodeHintManager"); require("utils/Global"); require("command/Menus"); diff --git a/test/UnitTestSuite.js b/test/UnitTestSuite.js index 5d83dc70a3..4f926c570d 100644 --- a/test/UnitTestSuite.js +++ b/test/UnitTestSuite.js @@ -102,7 +102,6 @@ define(function (require, exports, module) { require("spec/BeautificationManager-test"); require("spec/Template-for-integ-test"); require("spec/LiveDevelopmentMultiBrowser-test"); - require("spec/PhoenixComm-integ-test"); require("spec/NewFileContentManager-test"); require("spec/InstallExtensionDialog-integ-test"); require("spec/ExtensionInstallation-test"); diff --git a/test/spec/PhoenixComm-integ-test.js b/test/spec/PhoenixComm-integ-test.js deleted file mode 100644 index 465eabefc8..0000000000 --- a/test/spec/PhoenixComm-integ-test.js +++ /dev/null @@ -1,134 +0,0 @@ -/* - * GNU AGPL-3.0 License - * - * Copyright (c) 2021 - present core.ai . All rights reserved. - * Original work Copyright (c) 2012 - 2021 Adobe Systems Incorporated. All rights reserved. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see https://opensource.org/licenses/AGPL-3.0. - * - */ - -/*global describe, it, expect, beforeAll, afterAll, awaits, awaitsForDone */ - -define(function (require, exports, module) { - // Recommended to avoid reloading the integration test window Phoenix instance for each test. - - const SpecRunnerUtils = require("spec/SpecRunnerUtils"), - PhoenixCommSpecRunner = require("utils/PhoenixComm"); - - const testPath = SpecRunnerUtils.getTestPath("/spec/JSUtils-test-files"); - - let FileViewController, // loaded from brackets.test - ProjectManager, // loaded from brackets.test; - MainViewManager, - CommandManager, - Commands, - testWindow, - brackets, - PhoenixComm; - - - describe("LegacyInteg:PhoenixComm", function () { - - async function _initTestWindow() { - testWindow = await SpecRunnerUtils.createTestWindowAndRun({forceReload: true}); - brackets = testWindow.brackets; - FileViewController = brackets.test.FileViewController; - ProjectManager = brackets.test.ProjectManager; - MainViewManager = brackets.test.MainViewManager; - CommandManager = brackets.test.CommandManager; - Commands = brackets.test.Commands; - PhoenixComm = brackets.test.PhoenixComm; - await awaitsForDone( - FileViewController.openAndSelectDocument( - testPath + "/simple.js", - FileViewController.PROJECT_MANAGER - )); - - await SpecRunnerUtils.loadProjectInTestWindow(testPath); - } - - beforeAll(async function () { - await _initTestWindow(); - }, 30000); - - async function _closeTestWindow(force, blankBeforeClose) { - if(testWindow){ - // comment out below line if you want to debug the test window post running tests - await SpecRunnerUtils.closeTestWindow(force, blankBeforeClose); - } - FileViewController = null; - ProjectManager = null; - testWindow = null; - brackets = null; - } - - afterAll(async function () { - await _closeTestWindow(); - }, 30000); - - it("Should Not have self instance details in Phoenix comm", async function () { // #2813 - let instanceDetails = PhoenixCommSpecRunner.getAllInstanceDetails(); - expect(instanceDetails[PhoenixCommSpecRunner.PHOENIX_INSTANCE_ID]).toBeFalsy(); - }); - - it("Should have the test window instance details in both instances", async function () { // #2813 - let instanceDetailsAtSpecRunner = PhoenixCommSpecRunner.getAllInstanceDetails(); - let instanceDetailsAtTestWindow = PhoenixComm.getAllInstanceDetails(); - // check if we have the instance details of the test window - expect(instanceDetailsAtSpecRunner[PhoenixComm.PHOENIX_INSTANCE_ID]).toEqual({ - instanceID: PhoenixComm.PHOENIX_INSTANCE_ID, - isTestWindow: true - }); - // check if test window have the instance details of this spec runner - expect(instanceDetailsAtTestWindow[PhoenixCommSpecRunner.PHOENIX_INSTANCE_ID]).toEqual({ - instanceID: PhoenixCommSpecRunner.PHOENIX_INSTANCE_ID, - isTestWindow: true - }); - }); - - it("Should remove references from self once test window is closed", async function () { // #2813 - let instanceDetailsAtSpecRunner = PhoenixCommSpecRunner.getAllInstanceDetails(); - let testWindowInstanceID = PhoenixComm.PHOENIX_INSTANCE_ID; - await _closeTestWindow(true, true); - // check if we dont the instance details of the test window - instanceDetailsAtSpecRunner = PhoenixCommSpecRunner.getAllInstanceDetails(); - expect(instanceDetailsAtSpecRunner[testWindowInstanceID]).not.toBeDefined(); - }, 30000); - - it("Should update references from self once test window reloaded", async function () { // #2813 - let oldTestWindowInstanceID = PhoenixComm.PHOENIX_INSTANCE_ID; - await _closeTestWindow(true, true); - await _initTestWindow(); - await awaits(500); - - let instanceDetailsAtSpecRunner = PhoenixCommSpecRunner.getAllInstanceDetails(); - let instanceDetailsAtTestWindow = PhoenixComm.getAllInstanceDetails(); - // check if we dont the instance details of the test window - expect(instanceDetailsAtSpecRunner[oldTestWindowInstanceID]).not.toBeDefined(); - expect(instanceDetailsAtTestWindow[oldTestWindowInstanceID]).not.toBeDefined(); - // check if we have the instance details of the test window - expect(instanceDetailsAtSpecRunner[PhoenixComm.PHOENIX_INSTANCE_ID]).toEqual({ - instanceID: PhoenixComm.PHOENIX_INSTANCE_ID, - isTestWindow: true - }); - // check if test window have the instance details of this spec runner - expect(instanceDetailsAtTestWindow[PhoenixCommSpecRunner.PHOENIX_INSTANCE_ID]).toEqual({ - instanceID: PhoenixCommSpecRunner.PHOENIX_INSTANCE_ID, - isTestWindow: true - }); - }, 30000); - - }); -});