Skip to main content

Meeting observer

The meeting observer is a one-way websocket connection that is based on the rails actioncable protocol. "AnyCable" is the successor of it.

You can connect to a specific room at any time. The room must have been started from the related API key.

Setup

The URL is the API origin "https://api.eyeson.team" followed by "/rt" (for "realtime") and then add "room_id" as query parameter.

https://api.eyeson.team/rt?room_id=651b0c4c3ae7400ea35db31fs
note

You might need to use the more common wss:// protocol instead of https://, depending on your implementation.

Channel subscription

You must subscribe to the channel named RoomChannel to receive all events.

note

As soon as the meeting shuts down, the connection is closed automatically.

Authorization

You need an API key to connect. Here's how to get your API key, if you don't have it already.

There are 3 ways to include the API key.

  1. "Authorization" header
  2. API key as WebSocket protocol
  3. Query parameter "api_key=<YOUR_API_KEY>"

It depends on the implementation and environment which way you need to use. For example in the browser you can't set the header, so you can use the WebSocket protocol, but if the library doesn't support altering the protocol, you can at least use the query parameter.

caution

Make sure to handle your secret API key with care! Especially logging can be a pitfall.

Examples

The observer is already integrated in the eyeson-node library.
But you can find a more detailed version down below.

import Eyeson from 'eyeson-node';

const eyeson = new Eyeson({ apiKey: '< api-key >' }); // configure to use your api key

const meeting = await eyeson.join(username);

const connection = eyeson.observer.connect(meeting.roomId);
connection.on('disconnected', reason => {
console.log('Channel closed', reason);
});
connection.on('event', event => {
if (event.type === 'room_update') {
console.log(event.content);
}
else if (event.type === 'chat') {
console.log(event.content);
}
else if (event.type === 'participant_update') {
console.log(event.participant);
}
// and many more
});

Simplified example of usage with eyeson-node

Here's an example of how to implement the observer in Nodejs.

import WebSocket from 'ws';
import { createCable } from '@anycable/core';

let cable = null;

const connect = (room_id) => {
const url = `https://api.eyeson.team/rt?room_id=${room_id}`;
cable = createCable(url, {
websocketImplementation: WebSocket,
websocketOptions: {
headers: {
'Authorization': process.env.API_KEY,
},
},
});
const channel = cable.subscribeTo('RoomChannel');
channel.on('message', onMessage);
channel.on('connect', onConnected);
channel.on('disconnect', onDisconnected);
};

const disconnect = () => {
if (cable) {
cable.disconnect();
cable = null;
}
};

const onMessage = message => {
if (message.type === 'room_update') {
if (message.content.ready === true) {
console.log('Meeting ready');
}
if (message.content.shutdown === true) {
console.log('Meeting shutdown - disconnect');
disconnect();
}
}
};

const onConnected = () => {
console.log('Connected');
};

const onDisconnected = ({ name, message, reason }) => {
console.log('Disconnected', name, message, reason);
if (reason === 'unauthorized') {
disconnect();
}
};