OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2022-01-13 4545664bbece1b1b185945376b344b1660669a53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
importScripts ("/stomp.js");
 
// *WebWorker* onmessage implementation
onmessage = function (event) {
  var url = event.data.url;
  var login = event.data.login;
  var passcode = event.data.passcode;
  var destination = event.data.destination;
  var text = event.data.text;
 
  // create the Stomp client
  var client = Stomp.client(url);
  
  // connect to the server
  client.connect(login, passcode, function(frame) {
    // upon connection, subscribe to the destination
    var sub = client.subscribe(destination, function(message) {
      // when a message is received, post it to the current WebWorker
      postMessage("WebWorker: " + message.body);
      //... unsubscribe from the destination
      sub.unsubscribe();
      //... and disconnect from the server
      client.disconnect();
    });
    // send the text to the destination
    client.send(destination, {}, text);
  });
};