
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
@yomo/presencejs
Advanced tools
Presencejs
is a JavaScript library that allows you to build real-time web applications quickly, the server is built atop of YoMo, which provide secure, low-latency, and high-performance geo-distributed services.
...and a lot more.
With presencejs
, components will get data flow in real time. Thus, the UI will be always fast and reactive.
presencejs
to your web appUsing npm
$ npm i --save @yomo/presencejs
Using yarn
$ yarn add @yomo/presencejs
Using pnpm
$ pmpm i @yomo/presencejs
For CDN, you can use skypack: https://cdn.skypack.dev/@yomo/presencejs
<script type="module">
import { Presence } from 'https://cdn.skypack.dev/@yomo/presencejs';
</script>
The client need to authenticate with YoMo to establish a realtime connection. The following code sample uses a demo YoMo's server(wss://presence.yomo.dev
) and public Key to authenticate and print the message Connected to YoMo!
when you’ve successfully connected.
If you build your application using next.js, then you can use API Routes to get the access token.
For example, the following API route pages/api/auth.js
returns a json response with a status code of 200:
export default async function handler(req, res) {
if (req.method === 'GET') {
const response = await fetch('https://presence.yomo.dev/api/v1/auth', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
app_id: process.env.PRESENCE_APP_ID,
app_secret: process.env.PRESENCE_APP_SECRET,
}),
});
const data = await response.json();
res.status(200).json(data.data);
} else {
// Handle any other HTTP method
}
}
Response data:
{
"token": "eyJhbGciOiJIUzI1..."
}
Presence
instance.import { Presence } from '@yomo/presencejs';
// new Presence(host: string, option?: {
// // Authentication
// auth?: {
// // Certification Type
// type: 'publickey' | 'token',
// // The public key in your Allegro Mesh project.
// publicKey?: string,
// // api for getting access token
// endpoint?: string,
// };
// // The reconnection interval value.
// reconnectInterval?: number;
// // The reconnection attempts value.
// reconnectAttempts?: number;
// }): Presence
// create an instance.
const yomo = new Presence('wss://presence.yomo.dev', {
auth: {
// Certification Type
type: 'token',
// api for getting access token
endpoint: '/api/auth',
},
});
yomo.on('connected', () => {
console.log('Connected to server: ', yomo.host);
});
Call the toRoom('001')
function to enter room 001
, without it, you are in the default room.The client receives a message with the name online
through the on
callback function, and can also subscribe to a message with the name mousemove
by returning an observable object through on$
.
yomo.on('connected', () => {
// Enter a room
yomo.toRoom('001');
// Function to handle response for given event from server
yomo.on('online', data => {
console.log('online:', data);
});
// Same as the `on` method, returns an observable response
yomo.on$('mousemove').subscribe(data => {
console.log('mousemove:', data);
});
// If you want to display the latency, you can get the value of the latency like this
yomo.on('latency', data => {
const { id, latency, meshId } = data;
console.log('latency:', latency);
});
});
The following example code send a message to the quickstart room with the name online
and the contents pixel position.
You can use rxjs to get an observable sequence of browser event transitions,then send the data to the signal channel with the name mousemove
in room 001
via ofRoom('001', 'mousemove')
.
import { fromEvent } from 'rxjs';
import { map } from 'rxjs/operators';
const ID = '34a1dbb5-c031-4680-926c-84a789d251e0';
yomo.on('connected', () => {
// Function for sending data to the server
yomo.send('online', {
id: ID,
x: 10,
y: 10,
});
// Converting browser events into observable sequences.
const mousemove$ = fromEvent(document, 'mousemove').pipe(
map(event => {
return {
id: ID,
x: event.clientX,
y: event.clientY,
};
})
);
// Sending data streams to the server
mousemove$.subscribe(yomo.ofRoom('001', 'mousemove'));
});
A connection to YoMo can be closed once it is no longer needed.
yomo.close();
yomo.on('closed', () => {
console.log('Closed the connection');
});
Methods of instance | Description | Type |
---|---|---|
on | Function to handle response for given event from server | on<T>(event: string, cb: (data: T) => void): void |
on$ | Same as the on method, returns an observable response | on$<T>(event: string): Observable<T> |
send | Function for sending data to the server | send<T>(event: string, data: T) |
toRoom | Enter a room | toRoom(roomName: string): Presence |
ofRoom | Function for sending data streams to the server | ofRoom(roomName: string, event: string) |
close | A connection to YoMo can be closed once it is no longer needed. | close(): void |
The MIT License.
FAQs
@yomo/presencejs ⚡️ made realtime web applications edge-aware by YoMo
The npm package @yomo/presencejs receives a total of 5 weekly downloads. As such, @yomo/presencejs popularity was classified as not popular.
We found that @yomo/presencejs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.