Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@liveblocks/client

Package Overview
Dependencies
Maintainers
2
Versions
405
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liveblocks/client - npm Package Compare versions

Comparing version 0.9.0 to 0.10.0

4

lib/cjs/authentication.js

@@ -46,3 +46,5 @@ "use strict";

if (typeof endpoint === "function") {
return endpoint(room);
const { token } = yield endpoint(room);
// TODO: Validation
return token;
}

@@ -49,0 +51,0 @@ throw new Error("Authentication error. Liveblocks could not parse the response of your authentication endpoint");

@@ -9,5 +9,22 @@ import { ClientOptions, Client } from "./types";

* authEndpoint: "/api/auth"
* })
* });
*
* // It's also possible to use a function to call your authentication endpoint.
* // Useful to add additional headers or use an API wrapper (like Firebase functions)
* const client = createClient({
* authEndpoint: async (room) => {
* const response = await fetch("/api/auth", {
* method: "POST",
* headers: {
* Authentication: "token",
* "Content-Type": "application/json"
* },
* body: JSON.stringify({ room })
* });
*
* return await response.json();
* }
* });
* ```
*/
export declare function createClient(options: ClientOptions): Client;

@@ -12,3 +12,20 @@ "use strict";

* authEndpoint: "/api/auth"
* })
* });
*
* // It's also possible to use a function to call your authentication endpoint.
* // Useful to add additional headers or use an API wrapper (like Firebase functions)
* const client = createClient({
* authEndpoint: async (room) => {
* const response = await fetch("/api/auth", {
* method: "POST",
* headers: {
* Authentication: "token",
* "Content-Type": "application/json"
* },
* body: JSON.stringify({ room })
* });
*
* return await response.json();
* }
* });
* ```

@@ -15,0 +32,0 @@ */

@@ -27,3 +27,4 @@ import { RecordData, Record, List } from "./doc";

/**
* Get a room. Returns null if you never entered the room
* Gets a room. Returns null if {@link Client.enter} has not been called previously.
*
* @param roomId - The id of the room

@@ -33,3 +34,3 @@ */

/**
* Enter a room.
* Enters a room and returns it.
* @param roomId - The id of the room

@@ -40,3 +41,3 @@ * @param defaultPresence - Optional. Should be serializable to JSON. If omitted, an empty object will be used.

/**
* Leave a room.
* Leaves a room.
* @param roomId - The id of the room

@@ -95,3 +96,5 @@ */

};
declare type AuthEndpointCallback = (room: string) => Promise<string>;
declare type AuthEndpointCallback = (room: string) => Promise<{
token: string;
}>;
export declare type AuthEndpoint = string | AuthEndpointCallback;

@@ -147,2 +150,11 @@ export declare type ClientOptions = {

* Subscribe to the current user presence updates.
*
* @param listener - the callback that is called everytime the current user presence is updated with {@link Room.updatePresence}.
*
* ### Example
* ``` typescript
* room.subscribe("my-presence", (presence) => {
* // Do something
* });
* ```
*/

@@ -152,7 +164,24 @@ <T extends Presence>(type: "my-presence", listener: MyPresenceCallback<T>): void;

* Subscribe to the other users updates.
* The listener will be called when a user enters or leaves the room or when a user update its presence.
*
* @param listener - the callback that is called when a user enters or leaves the room or when a user update its presence.
*
* ### Example
* ``` typescript
* room.subscribe("others", (others) => {
* // Do something
* });
* ```
*/
<T extends Presence>(type: "others", listener: OthersEventCallback<T>): void;
/**
* Subscribe to events broadcasted by room.broadcastEvent
* Subscribe to events broadcasted by {@link Room.broadcastEvent}
*
* @param listener - the callback that is called when a user calls {@link Room.broadcastEvent}
*
* ### Example
* ``` typescript
* room.subscribe("event", ({ event, connectionId }) => {
* // Do something
* });
* ```
*/

@@ -173,2 +202,11 @@ (type: "event", listener: EventCallback): void;

* Unsubscribe to the current user presence updates.
*
* @param listener - the callback that has been used with {@link Room.subscribe}("my-presence").
*
* ### Example
* ``` typescript
* const onPresenceChange = (presence) => { };
* room.subscribe("my-presence", onPresenceChange);
* room.unsubscribe("my-presence", onPresenceChange);
* ```
*/

@@ -178,6 +216,24 @@ <T extends Presence>(type: "my-presence", listener: MyPresenceCallback<T>): void;

* Unsubscribe to the other users updates.
*
* @param listener - the callback that has been used with {@link Room.subscribe}("others").
*
* ### Example
* ``` typescript
* const onOthersChange = (presence) => { };
* room.subscribe("others", onOthersChange);
* room.unsubscribe("others", onOthersChange);
* ```
*/
<T extends Presence>(type: "others", listener: OthersEventCallback<T>): void;
/**
* Unsubscribe to events broadcasted by room.broadcastEvent
* Unsubscribe to events broadcasted by {@link Room.broadcastEvent}
*
* @param listener - the callback that has been used with {@link Room.unsubscribe}("event").
*
* ### Example
* ``` typescript
* const onEvent = ({ event, connectionId }) => { };
* room.subscribe("event", onEvent);
* room.unsubscribe("event", onEvent);
* ```
*/

@@ -196,3 +252,3 @@ (type: "event", listener: EventCallback): void;

/**
* Get the current user.
* Gets the current user.
*

@@ -206,3 +262,3 @@ * ### Example

/**
* Get the presence of the current user.
* Gets the presence of the current user.
*

@@ -216,3 +272,3 @@ * ### Example

/**
* Get all the other users in the room.
* Gets all the other users in the room.
*

@@ -226,4 +282,4 @@ * ### Example

/**
* Update the presence of the current user. Only pass the properties you want to update. No need to send the full presence.
* @param {Partial<T>} overrides - A partial object that contains the properties you want to update.
* Updates the presence of the current user. Only pass the properties you want to update. No need to send the full presence.
* @param {Partial<T>} overrides A partial object that contains the properties you want to update.
*

@@ -241,4 +297,4 @@ * ### Example

/**
* Broadcast an event to other users in the room.
* @param {any} event - the event to broadcast. Should be serializable to JSON
* Broadcast an event to other users in the room. Event broadcasted to the room can be listened with {@link Room.subscribe}("event").
* @param {any} event the event to broadcast. Should be serializable to JSON
*

@@ -249,7 +305,9 @@ * ### Example

* // On client A
* room.broadcastEvent({ type: "EMOJI", emoji: 🔥 });
* room.broadcastEvent({ type: "EMOJI", emoji: "🔥" });
*
* // On client B
* room.subscribe("event", ({ event }) => {
*
* if(event.type === "EMOJI") {
* // Do something
* }
* });

@@ -256,0 +314,0 @@ * ```

@@ -43,3 +43,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

if (typeof endpoint === "function") {
return endpoint(room);
const { token } = yield endpoint(room);
// TODO: Validation
return token;
}

@@ -46,0 +48,0 @@ throw new Error("Authentication error. Liveblocks could not parse the response of your authentication endpoint");

@@ -9,5 +9,22 @@ import { ClientOptions, Client } from "./types";

* authEndpoint: "/api/auth"
* })
* });
*
* // It's also possible to use a function to call your authentication endpoint.
* // Useful to add additional headers or use an API wrapper (like Firebase functions)
* const client = createClient({
* authEndpoint: async (room) => {
* const response = await fetch("/api/auth", {
* method: "POST",
* headers: {
* Authentication: "token",
* "Content-Type": "application/json"
* },
* body: JSON.stringify({ room })
* });
*
* return await response.json();
* }
* });
* ```
*/
export declare function createClient(options: ClientOptions): Client;

@@ -9,3 +9,20 @@ import { createRoom } from "./room";

* authEndpoint: "/api/auth"
* })
* });
*
* // It's also possible to use a function to call your authentication endpoint.
* // Useful to add additional headers or use an API wrapper (like Firebase functions)
* const client = createClient({
* authEndpoint: async (room) => {
* const response = await fetch("/api/auth", {
* method: "POST",
* headers: {
* Authentication: "token",
* "Content-Type": "application/json"
* },
* body: JSON.stringify({ room })
* });
*
* return await response.json();
* }
* });
* ```

@@ -12,0 +29,0 @@ */

@@ -27,3 +27,4 @@ import { RecordData, Record, List } from "./doc";

/**
* Get a room. Returns null if you never entered the room
* Gets a room. Returns null if {@link Client.enter} has not been called previously.
*
* @param roomId - The id of the room

@@ -33,3 +34,3 @@ */

/**
* Enter a room.
* Enters a room and returns it.
* @param roomId - The id of the room

@@ -40,3 +41,3 @@ * @param defaultPresence - Optional. Should be serializable to JSON. If omitted, an empty object will be used.

/**
* Leave a room.
* Leaves a room.
* @param roomId - The id of the room

@@ -95,3 +96,5 @@ */

};
declare type AuthEndpointCallback = (room: string) => Promise<string>;
declare type AuthEndpointCallback = (room: string) => Promise<{
token: string;
}>;
export declare type AuthEndpoint = string | AuthEndpointCallback;

@@ -147,2 +150,11 @@ export declare type ClientOptions = {

* Subscribe to the current user presence updates.
*
* @param listener - the callback that is called everytime the current user presence is updated with {@link Room.updatePresence}.
*
* ### Example
* ``` typescript
* room.subscribe("my-presence", (presence) => {
* // Do something
* });
* ```
*/

@@ -152,7 +164,24 @@ <T extends Presence>(type: "my-presence", listener: MyPresenceCallback<T>): void;

* Subscribe to the other users updates.
* The listener will be called when a user enters or leaves the room or when a user update its presence.
*
* @param listener - the callback that is called when a user enters or leaves the room or when a user update its presence.
*
* ### Example
* ``` typescript
* room.subscribe("others", (others) => {
* // Do something
* });
* ```
*/
<T extends Presence>(type: "others", listener: OthersEventCallback<T>): void;
/**
* Subscribe to events broadcasted by room.broadcastEvent
* Subscribe to events broadcasted by {@link Room.broadcastEvent}
*
* @param listener - the callback that is called when a user calls {@link Room.broadcastEvent}
*
* ### Example
* ``` typescript
* room.subscribe("event", ({ event, connectionId }) => {
* // Do something
* });
* ```
*/

@@ -173,2 +202,11 @@ (type: "event", listener: EventCallback): void;

* Unsubscribe to the current user presence updates.
*
* @param listener - the callback that has been used with {@link Room.subscribe}("my-presence").
*
* ### Example
* ``` typescript
* const onPresenceChange = (presence) => { };
* room.subscribe("my-presence", onPresenceChange);
* room.unsubscribe("my-presence", onPresenceChange);
* ```
*/

@@ -178,6 +216,24 @@ <T extends Presence>(type: "my-presence", listener: MyPresenceCallback<T>): void;

* Unsubscribe to the other users updates.
*
* @param listener - the callback that has been used with {@link Room.subscribe}("others").
*
* ### Example
* ``` typescript
* const onOthersChange = (presence) => { };
* room.subscribe("others", onOthersChange);
* room.unsubscribe("others", onOthersChange);
* ```
*/
<T extends Presence>(type: "others", listener: OthersEventCallback<T>): void;
/**
* Unsubscribe to events broadcasted by room.broadcastEvent
* Unsubscribe to events broadcasted by {@link Room.broadcastEvent}
*
* @param listener - the callback that has been used with {@link Room.unsubscribe}("event").
*
* ### Example
* ``` typescript
* const onEvent = ({ event, connectionId }) => { };
* room.subscribe("event", onEvent);
* room.unsubscribe("event", onEvent);
* ```
*/

@@ -196,3 +252,3 @@ (type: "event", listener: EventCallback): void;

/**
* Get the current user.
* Gets the current user.
*

@@ -206,3 +262,3 @@ * ### Example

/**
* Get the presence of the current user.
* Gets the presence of the current user.
*

@@ -216,3 +272,3 @@ * ### Example

/**
* Get all the other users in the room.
* Gets all the other users in the room.
*

@@ -226,4 +282,4 @@ * ### Example

/**
* Update the presence of the current user. Only pass the properties you want to update. No need to send the full presence.
* @param {Partial<T>} overrides - A partial object that contains the properties you want to update.
* Updates the presence of the current user. Only pass the properties you want to update. No need to send the full presence.
* @param {Partial<T>} overrides A partial object that contains the properties you want to update.
*

@@ -241,4 +297,4 @@ * ### Example

/**
* Broadcast an event to other users in the room.
* @param {any} event - the event to broadcast. Should be serializable to JSON
* Broadcast an event to other users in the room. Event broadcasted to the room can be listened with {@link Room.subscribe}("event").
* @param {any} event the event to broadcast. Should be serializable to JSON
*

@@ -249,7 +305,9 @@ * ### Example

* // On client A
* room.broadcastEvent({ type: "EMOJI", emoji: 🔥 });
* room.broadcastEvent({ type: "EMOJI", emoji: "🔥" });
*
* // On client B
* room.subscribe("event", ({ event }) => {
*
* if(event.type === "EMOJI") {
* // Do something
* }
* });

@@ -256,0 +314,0 @@ * ```

{
"name": "@liveblocks/client",
"version": "0.9.0",
"version": "0.10.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "./lib/cjs/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc