|
| 1 | +open ChannelMessagingAPI |
| 2 | +open WebWorkersAPI |
| 3 | + |
| 4 | +include EventTarget.Impl({ |
| 5 | + type t = sharedWorker |
| 6 | +}) |
| 7 | + |
| 8 | +/** |
| 9 | +`make(string)` |
| 10 | +
|
| 11 | +The SharedWorker() constructor creates a SharedWorker object that executes the |
| 12 | +script at the specified URL. This script must obey the same-origin policy. |
| 13 | +
|
| 14 | +```res |
| 15 | +let shared: sharedWorker = SharedWorker.make("sharedworker.js") |
| 16 | +``` |
| 17 | +
|
| 18 | +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/) |
| 19 | +*/ |
| 20 | +@new |
| 21 | +external make: string => sharedWorker = "SharedWorker" |
| 22 | + |
| 23 | +/** |
| 24 | +`make_withName(string, string)` |
| 25 | +
|
| 26 | +The SharedWorker() constructor creates a SharedWorker object that executes the |
| 27 | +script at the specified URL. This script must obey the same-origin policy. |
| 28 | +
|
| 29 | +```res |
| 30 | +let shared: sharedWorker = SharedWorker.make("sharedworker.js", "name") |
| 31 | +``` |
| 32 | +
|
| 33 | +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/) |
| 34 | +*/ |
| 35 | +@new |
| 36 | +external make_withName: (string, string) => sharedWorker = "SharedWorker" |
| 37 | + |
| 38 | +/** |
| 39 | +`make_withOptions(string, workerOptions)` |
| 40 | +
|
| 41 | +The SharedWorker() constructor creates a SharedWorker object that executes the |
| 42 | +script at the specified URL. This script must obey the same-origin policy. |
| 43 | +
|
| 44 | +```res |
| 45 | +let shared3: sharedWorker = SharedWorker.make_withOptions("sharedworker.js", { |
| 46 | + name: "workerName", |
| 47 | + type_: Module |
| 48 | +}) |
| 49 | +``` |
| 50 | +
|
| 51 | +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/) |
| 52 | +*/ |
| 53 | +@new |
| 54 | +external make_withOptions: (string, workerOptions) => sharedWorker = "SharedWorker" |
| 55 | + |
| 56 | +/** |
| 57 | +`port(sharedWorker)` |
| 58 | +
|
| 59 | +The port property of the SharedWorker interface returns a MessagePort object |
| 60 | +used to communicate and control the shared worker. |
| 61 | +
|
| 62 | +```res |
| 63 | +let port: WebAPI.ChannelMessagingAPI.messagePort = SharedWorker.port(myWorker) |
| 64 | +``` |
| 65 | +
|
| 66 | +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/port) |
| 67 | +*/ |
| 68 | +@get |
| 69 | +external port: sharedWorker => messagePort = "port" |
0 commit comments