Installation & Basic Usage
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/core
# or
yarn add @ember-link/core
Running the Ember Link Server
The easiest way to get started is by running the latest Ember Link Docker image locally.
Download the Docker image:
docker pull emberlinkio/ember-link:latest
Run the Docker container: This will run the server on port
9000
and expose it for your application to connect. TheALLOW_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, import and create a client instance with the host and port you are running the server on:
import { createClient } from '@ember-link/core';
const client = createClient({
baseUrl: 'http://localhost:9000'
});
Once you have a client instance you can then connect to a Channel
// Returns the channel and a function that should be called
// once a user leaves the channel
const { channel, leave } = client.joinChannel('test');
Listening to User Presence
Track when users join or leave the collaboration session and update your own presence:
channel.events.others.subscribe('join', (user) => {
console.log('User join: ', user);
});
channel.events.others.subscribe('update', (user) => {
console.log('User update: ', user);
});
channel.events.others.subscribe('leave', (user) => {
console.log('User leave: ', user);
});
// Sent when we disconnect for some reason so that there
// aren't ghost users hanging around
channel.events.others.subscribe('reset', () => {
console.log('Users reset');
});
// Update your own presence
channel.updatePresence({ status: 'online' });
// Listen to events with your own presence
channel.events.subscribe('presence', (presence) => {
console.log('My Presence was updated:', presence);
});
Listening to Websocket status
channel.events.subscribe('status', (status) => {
console.log('Current websocket status: ', status);
});
Next Steps
- Check out the full API documentation
- Check out examples on the github repo
- Join the Ember Link community on Discord for support & updates