Getting Started

Ember Link makes adding real-time collaboration to your app effortless. This guide will help you set up Ember Link and start using its core features.

Installation

You can install Ember Link via npm or yarn or any other package manager you use:

npm install @ember-link/react
# or
yarn add @ember-link/react

Running the Ember Link Server

The easiest way to get started is by running the latest Ember Link Docker image locally.

  1. Download the Docker image:

    docker pull emberlinkio/ember-link:latest
  2. Run the Docker container: This will run the server on port 9000 and expose it for your application to connect. The ALLOW_UNAUTHORIZED flag is enabled for easier testing.

    docker run -d -p 9000:9000 --env PORT=9000 --env HOST=0.0.0.0 --env ALLOW_UNAUTHORIZED=true emberlinkio/ember-link:latest

Server Configuration

View all server configuration environment variables here

Connecting to Ember Link

After installing, wrap your root component with an EmberLinkProvider

import { ChannelProvider, EmberLinkProvider } from '@ember-link/react';

function App() {
	return <EmberLinkProvider baseUrl="http://localhost:9000">{children}</EmberLinkProvider>;
}

Then where you plan on using Ember Link you can wrap that component with a ChannelProvider to connect to a Channel

function Channel() {
	return (
		<ChannelProvider channelName="test" options={{}}>
			<Page />
		</ChannelProvider>
	);
}

Listening to User Presence

Track when users join or leave the collaboration session and update your own presence:

import { useMyPresence, useOthers } from '@ember-link/react';
import { useEffect } from 'react';

export const Page = () => {
	const others = useOthers();
	const [myPresence, setMyPresence] = useMyPresence();

	useEffect(() => {
		setMyPresence({ status: 'online' });
	}, [setMyPresence]);

	return (
		<div>
			{myPresence}
			{others.map((other) => {
				return <div>{other.clientId}</div>;
			})}
		</div>
	);
};

Listening to Websocket status

import { useChannel } from '@ember-link/react';
import { useEffect } from 'react';

export const Page = () => {
	const channel = useChannel();

	useEffect(() => {
		const unsub = channel.events.subscribe('status', (status) => {
			console.log('Current websocket status: ', status);
		});

		return () => {
			unsub();
		};
	}, [channel]);

	return (
		/*
			Display the status as a badge
		*/
	);
};

Next Steps