Docs

Subscriptions

Get live updates, such as now playing, over WebSocket.

Subscriptions use the graphql-ws protocol at wss://api.staging.swztech.net/graphql/ws.

import { createClient } from 'graphql-ws';

const client = createClient({ url: 'wss://api.staging.swztech.net/graphql/ws' });

client.subscribe(
  {
    query: `subscription ($networkId: ID!) {
      nowPlayingChanged(networkId: $networkId) { __typename }
    }`,
    variables: { networkId: 'your-network-id' },
  },
  {
    next: (event) => console.log(event),
    error: (error) => console.error(error),
    complete: () => console.log('done'),
  },
);

See nowPlayingChanged in the reference for its arguments and the fields each event carries. Events include the new feed item, so you can update your view without refetching.