Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix socketio sample #9525

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
35 changes: 24 additions & 11 deletions api-reference/v1.0/api/subscriptions-socketio.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,30 @@ The `notificationUrl` returned is a socket.io endpoint URL.

The following example shows how to use the `notificationUrl` with socket.io in JavaScript.

```javascript
// this is the notificationUrl returned from this API
var notificationUrl = "https://f3hb0mpua.svc.ms/zbaehwg/callback?snthgk=1ff3-2345672zz831837523";

// 'io' comes from the socket.io client library
var socket = io(notificationUrl);

// these examples log to the console.
// your app would provide its own callbacks
socket.on("connect", ()=>console.log("Connected!"));
socket.on("notification", (data)=>console.log("Notification!", data));
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.8.1/socket.io.js"></script>
<script>
// This is the notificationUrl returned from this API
var notificationUrl = "https://f3hb0mpua.svc.ms/zbaehwg/callback?snthgk=1ff3-2345672zz831837523";

// 'io' comes from the socket.io client library
var socket = io(notificationUrl, {
transports: ['websocket'] // Make sure to use "websocket" as the default is set to "polling" which is not supported
});

socket.on("connect", () => {
console.log(`connect`, socket.id);
});

socket.on("disconnect", () => {
// Returns "undefined" on disconnect
console.log(`disconnect`, socket.id);
});

socket.on("notification", (data) => {
console.log(`Notification received:`, data);
});
</script>
```

<!-- uuid: 8fcb5dbc-d5aa-4681-8e31-b001d5168d79
Expand Down