Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions docs/excel/custom-functions-web-reqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,34 @@ Within a custom function, you can use [WebSockets](https://developer.mozilla.org

### WebSockets example

The following code sample establishes a WebSocket connection and then logs each incoming message from the server.
The following code sample establishes a WebSocket connection and then logs each incoming message from the server to excel reference cell

```js
let ws = new WebSocket('wss://bundles.office.com');
// functions.js file

ws.onmessage(message) {
console.log(`Received: ${message}`);
var ws = null;

createSocketObject(invocationData){

if(!!ws){
ws = new WebSocket('wss://bundles.office.com');
}

ws.onmessage(message) {
console.log(`Received: ${message}`);
invocationData.setResult(message); // <--- print data in excel cell reference
}

ws.onerror(error){
console.err(`Failed: ${error}`);
}
}

ws.onerror(error){
console.err(`Failed: ${error}`);
function getLivePrice(quote_symbol, invocation) {
createSocketObject(invocation);
}

CustomFunctions.associate('quote', getLivePrice);
```

## Next steps
Expand Down