MCPcopy
hub / github.com/PyQt5/PyQt / QWebChannel

Function QWebChannel

QWebChannel/Data/qwebchannel.js:56–174  ·  view source on GitHub ↗
(transport, initCallback)

Source from the content-addressed store, hash-verified

54};
55
56var QWebChannel = function(transport, initCallback)
57{
58 if (typeof transport !== "object" || typeof transport.send !== "function") {
59 console.error("The QWebChannel expects a transport object with a send function and onmessage callback property." +
60 " Given is: transport: " + typeof(transport) + ", transport.send: " + typeof(transport.send));
61 return;
62 }
63
64 var channel = this;
65 this.transport = transport;
66
67 this.send = function(data)
68 {
69 if (typeof(data) !== "string") {
70 data = JSON.stringify(data);
71 }
72 channel.transport.send(data);
73 }
74
75 this.transport.onmessage = function(message)
76 {
77 var data = message.data;
78 if (typeof data === "string") {
79 data = JSON.parse(data);
80 }
81 switch (data.type) {
82 case QWebChannelMessageTypes.signal:
83 channel.handleSignal(data);
84 break;
85 case QWebChannelMessageTypes.response:
86 channel.handleResponse(data);
87 break;
88 case QWebChannelMessageTypes.propertyUpdate:
89 channel.handlePropertyUpdate(data);
90 break;
91 default:
92 console.error("invalid message received:", message.data);
93 break;
94 }
95 }
96
97 this.execCallbacks = {};
98 this.execId = 0;
99 this.exec = function(data, callback)
100 {
101 if (!callback) {
102 // if no callback is given, send directly
103 channel.send(data);
104 return;
105 }
106 if (channel.execId === Number.MAX_VALUE) {
107 // wrap
108 channel.execId = Number.MIN_VALUE;
109 }
110 if (data.hasOwnProperty("id")) {
111 console.error("Cannot exec message with property id: " + JSON.stringify(data));
112 return;
113 }

Callers 1

__init__Method · 0.50

Calls 2

errorMethod · 0.80
keysMethod · 0.80

Tested by

no test coverage detected