MCPcopy Create free account
hub / github.com/GoogleChrome/samples / addConnection

Function addConnection

presentation-api/receiver/receiver.js:4–22  ·  view source on GitHub ↗
(connection)

Source from the content-addressed store, hash-verified

2let messageIdx = 0;
3
4function addConnection(connection) {
5 connection.connectionId = ++connectionIdx;
6 addMessage('New connection #' + connectionIdx);
7
8 connection.addEventListener('message', function(event) {
9 messageIdx++;
10 const data = JSON.parse(event.data);
11 const logString = 'Message ' + messageIdx + ' from connection #' +
12 connection.connectionId + ': ' + data.message;
13 addMessage(logString, data.lang);
14 maybeSetFruit(data.message);
15 connection.send('Received message ' + messageIdx);
16 });
17
18 connection.addEventListener('close', function(event) {
19 addMessage('Connection #' + connection.connectionId + ' closed, reason = ' +
20 event.reason + ', message = ' + event.message);
21 });
22};
23
24/* Utils */
25

Callers 1

receiver.jsFile · 0.85

Calls 4

addMessageFunction · 0.85
maybeSetFruitFunction · 0.85
parseMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected