New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@yomo/presencejs

Package Overview
Dependencies
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yomo/presencejs - npm Package Compare versions

Comparing version 1.0.0-alpha.2 to 1.0.0-alpha.3

6

dist/helper.d.ts

@@ -1,2 +0,2 @@

import { IPresenceOption } from './type';
import { PresenceOption } from './type';
/**

@@ -38,6 +38,6 @@ * Load wasm

* @param host Service url
* @param {IPresenceOption} option
* @param {PresenceOption} option
*
* @returns Promise containing AuthorizedURL
*/
export declare function getAuthorizedURL(host: string, option: IPresenceOption): Promise<string>;
export declare function getAuthorizedURL(host: string, option: PresenceOption): Promise<string>;
import { Observable, Subject } from 'rxjs';
import { EventMessage, IPresenceOption } from './type';
import { EventMessage, PresenceOption } from './type';
export default class Presence extends Subject<EventMessage> {

@@ -16,3 +16,3 @@ host: string;

private _wtSubscription;
constructor(host: string, option: IPresenceOption);
constructor(host: string, option: PresenceOption);
/**

@@ -19,0 +19,0 @@ * Function to handle response for given event from server

@@ -1413,3 +1413,3 @@ 'use strict';

* @param host Service url
* @param {IPresenceOption} option
* @param {PresenceOption} option
*

@@ -1416,0 +1416,0 @@ * @returns Promise containing AuthorizedURL

@@ -1409,3 +1409,3 @@ import { interval, Subject } from 'rxjs';

* @param host Service url
* @param {IPresenceOption} option
* @param {PresenceOption} option
*

@@ -1412,0 +1412,0 @@ * @returns Promise containing AuthorizedURL

@@ -1,2 +0,1 @@

import { Observable } from 'rxjs';
export declare type EventMessage = {

@@ -6,12 +5,3 @@ event: string;

};
export interface IPresence {
host: string;
on: <T>(event: string, cb: (data: T) => void) => void;
on$: <T>(event: string) => Observable<T>;
send: <T>(event: string, data: T) => void;
toRoom: (roomName: string) => IPresence;
ofRoom: (roomName: string, event: string) => void;
close: () => void;
}
export interface IPresenceOption {
export interface PresenceOption {
auth?: {

@@ -18,0 +8,0 @@ type: 'publickey' | 'token';

{
"version": "1.0.0-alpha.2",
"version": "1.0.0-alpha.3",
"description": "@yomo/presencejs ⚡️ made realtime web applications edge-aware by YoMo",

@@ -8,3 +8,4 @@ "keywords": [

"presencejs",
"metaverse"
"metaverse",
"webtransport"
],

@@ -11,0 +12,0 @@ "license": "MIT",

@@ -18,3 +18,3 @@ <p align="center">

- **Secure**, **low-latency** and **high-performance**
- Support **unreliable** and **reliable** data ransmitting
- Support **unreliable** and **reliable** data transmitting
- **Real-time** experience

@@ -31,10 +31,12 @@ - Auto Reconnection

- React Cursor Chat Component:
- React Cursor Chat Component:
- Preview: https://cursor-chat-example.vercel.app
- Source code: https://github.com/yomorun/react-cursor-chat
- Next.js Commerce with realtime collaboration:
- Preview: https://commerce-ochre-sigma-86.vercel.app/
- Next.js Commerce with realtime collaboration:
- Preview: https://commerce-cursor-chat.vercel.app
- Source code: https://github.com/osdodo/commerce
- Solid.js Cursor Chat Component:
- Preview: https://solid-cursor-chat-example.netlify.app
- Source code: https://github.com/osdodo/solid-cursor-chat
## 🥷🏼 Quick Start

@@ -72,7 +74,7 @@

The client need to authenticate with YoMo to establish a realtime connection. The following code sample uses a demo YoMo's server(`https://prsc.yomo.dev`) and public Key to authenticate and print the message `Connected to YoMo!` when you’ve successfully connected.
The client need to authenticate with YoMo to establish a realtime connection. The following code sample uses a demo YoMo's server(`https://prsc.yomo.dev`) and `token` to authenticate and print the message `Connected to YoMo!` when you’ve successfully connected.
#### How do I get a token?
If you build your application using next.js, then you can use [API Routes](https://nextjs.org/docs/api-routes/introduction) to get the access token.
If you build your application using Next.js, then you can use [API Routes](https://nextjs.org/docs/api-routes/introduction) to get the access token.
For example, the following API route `pages/api/presence-auth.js` returns a json response with a status code of 200:

@@ -123,3 +125,3 @@

#### Create a `Presence` instance.
#### Create a `Presence` instance

@@ -134,3 +136,3 @@ ```js

type: 'token',
// api for getting access token
// Api for getting access token
endpoint: '/api/presence-auth',

@@ -137,0 +139,0 @@ },

import Go from './wasm-exec';
import { IPresenceOption } from './type';
import { PresenceOption } from './type';

@@ -93,7 +93,7 @@ const y3WasmPath = 'https://d1lxb757x1h2rw.cloudfront.net/y3.wasm';

* @param host Service url
* @param {IPresenceOption} option
* @param {PresenceOption} option
*
* @returns Promise containing AuthorizedURL
*/
export async function getAuthorizedURL(host: string, option: IPresenceOption) {
export async function getAuthorizedURL(host: string, option: PresenceOption) {
// `publickey` is the way to test

@@ -100,0 +100,0 @@ // if (option?.auth?.type === 'publickey' && option.auth.publicKey) {

import { interval, Observable, Subject, Subscription } from 'rxjs';
import { distinctUntilChanged, filter, map, takeWhile } from 'rxjs/operators';
import { WebSocketSubject } from 'rxjs/webSocket';
import { decoder, encoder, getAuthorizedURL, getProtocol, loadWasm } from './helper';
import { EventMessage, IPresenceOption } from './type';
import {
decoder,
encoder,
getAuthorizedURL,
getProtocol,
loadWasm,
} from './helper';
import { EventMessage, PresenceOption } from './type';

@@ -33,3 +39,3 @@ export default class Presence extends Subject<EventMessage> {

constructor(host: string, option: IPresenceOption) {
constructor(host: string, option: PresenceOption) {
super();

@@ -61,3 +67,3 @@ this.host = host;

this._connectionStatus$.subscribe({
next: (isConnected) => {
next: isConnected => {
if (

@@ -75,3 +81,3 @@ !this._reconnectionObservable &&

loadWasm().then(() => {
getAuthorizedURL(this.host, option).then((url) => {
getAuthorizedURL(this.host, option).then(url => {
this.host = url;

@@ -84,3 +90,3 @@ if (this.type === 'WebSocket') {

});
})
});
}

@@ -101,3 +107,3 @@

distinctUntilChanged(),
filter((isConnected) => {
filter(isConnected => {
return (

@@ -139,3 +145,3 @@ (isConnected && event === 'connected') ||

}),
map((_) => _.data)
map(_ => _.data)
);

@@ -226,3 +232,3 @@ }

this._socketSubscription = this._socket$.subscribe({
next: (msg) => {
next: msg => {
this.next(msg);

@@ -299,3 +305,3 @@ },

private _ping(): Subscription {
return interval(5000).subscribe((_) => {
return interval(5000).subscribe(_ => {
this.send('ping', { timestamp: Date.now() });

@@ -313,3 +319,3 @@ });

private _pong(): Subscription {
return this.on$<any>('pong').subscribe((data) => {
return this.on$<any>('pong').subscribe(data => {
const { timestamp, meshId } = data;

@@ -338,4 +344,3 @@ if (timestamp) {

try {
this._transportDatagramWriter =
this._transport.datagrams.writable.getWriter();
this._transportDatagramWriter = this._transport.datagrams.writable.getWriter();
await this._transport.ready;

@@ -348,3 +353,3 @@ this._connectionStatus$.next(true);

this._connectionStatus$.subscribe({
next: (isConnected) => {
next: isConnected => {
if (

@@ -351,0 +356,0 @@ !this._reconnectionObservable &&

@@ -1,3 +0,1 @@

import { Observable } from 'rxjs';
export type EventMessage = {

@@ -8,20 +6,3 @@ event: string;

export interface IPresence {
// Service url
host: string;
// Function to handle response for given event from server
on: <T>(event: string, cb: (data: T) => void) => void;
// Same as the `on` method, returns an observable response
on$: <T>(event: string) => Observable<T>;
// Function for sending data to the server
send: <T>(event: string, data: T) => void;
// Enter a room
toRoom: (roomName: string) => IPresence;
// Function for sending data streams to the server
ofRoom: (roomName: string, event: string) => void;
// Close subscriptions, clean up
close: () => void;
}
export interface IPresenceOption {
export interface PresenceOption {
// Authentication

@@ -28,0 +9,0 @@ auth?: {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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