From the course: JavaScript: Web Workers

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Send messages to shared workers

Send messages to shared workers - JavaScript Tutorial

From the course: JavaScript: Web Workers

Start my 1-month free trial

Send messages to shared workers

- [Instructor] Now it's time to talk about how to send messages to a shared web worker. In this case, we need to remember that the architecture is different. We have several documents, Windows, IFrames, privacy web apps, that are currently connected through ports to the same shared web worker. In this case, we are going to use the same postMessage API, but instead of being in direct communication, we are doing that through the port. So from the main thread, that share web worker off shape has support, property, and that port property has the postMessage. We are going to send the message, and the message will be received in the shared web worker, not with a global event handler, but with one event handler per port. Each port will have it's own event handler. Remember we have one port per proxy. Using the same port, the shared web worker can also post a message back, that we will receive in the main thread through the message event inside the port of the shared web worker. The shared…

Contents