-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using shared web worker to maintain state
- Loading branch information
Showing
7 changed files
with
64 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
/** | ||
* This is a very basic implementation of the server side of the desktop agent. | ||
* You can register message ports with it and plug in extra functionality to handle new message types. | ||
*/ | ||
|
||
class SimpleServer { | ||
|
||
constructor() { | ||
} | ||
|
||
register(client: MessagePort) { | ||
console.log("Added new listener") | ||
client.addEventListener("message", e => { | ||
console.log("Received: "+e.data) | ||
}) | ||
} | ||
} | ||
|
||
const theServer = new SimpleServer(); | ||
|
||
onconnect = function (event) { | ||
const port = event.ports[0] | ||
theServer.register(port) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { FDC3_PORT_TRANSFER_REQUEST_TYPE, FDC3_PORT_TRANSFER_RESPONSE_TYPE, exchange, exchangePostMessage } from "fdc3-common"; | ||
|
||
const appWindow = window.parent; | ||
|
||
window.addEventListener("load", () => { | ||
|
||
const sw = new SharedWorker('http://localhost:8080/src/SimpleServer.ts') | ||
sw.port.start() | ||
|
||
// the other end to the app | ||
appWindow.postMessage({ | ||
type: FDC3_PORT_TRANSFER_RESPONSE_TYPE, | ||
},"*", [sw.port]) | ||
|
||
|
||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters