
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@zencastr/socket-transactions
Advanced tools
Recording tailored transactions over socket.io
Package that enables running transactions over socket.io.
The API is tailored to our use case, namely it expects the action names to be start
, stop
, pause
, resume
and recording-check
(even though you an use whatever you want), and also that the recordingId
is sent as a parameter in the transaction (this just flows from initiator to members in the transaction, the idea was to check if everyone is in the same recording).
Build: npm run build
Publish new version:
npm run build
npm version path
npm publsh
Or npm version path
or npm version major
Run tests:
npm run test
Run tests in watch mode:
npm run test:watch
Install @zencastr/socket-transactions
npm install @zencastr/socket-transactions -S
Call init
with the socket.io
's server instance (usually called io
):
import { recordingTransactionsCoordinator, connectedSocketsTracker } from '@zencastr/socket-transactions';
//...
recordingTransactionsCoordinator.init(io, /optional server timeout for transactions, default is 1000ms/ )
When a socket joins a recording:
connectedSocketsTracker.add(roomId, socket.user.username, socket);
//roomId is the projectId
When a socket disconnects:
connectedSocketsTracker.removeBySocketId(socket.id);
Install @zencastr/socket-transactions
npm install @zencastr/socket-transactions -S
Call init
on the connected socket
import { recordingTransactionsClient } from '@zencastr/socket-transactions';
//...
recordingTransactionsClient.init(socket, /optional client side timeout for transactions, default is 1000ms/);
try {
await recordingTransactionsClient.startTransaction({
actionType: 'start',
members: ['participantUsername1', 'participantUsername2'],
roomId: 'projectId',
recordingId: 'recordingId'
});
//transaction completed successfully (everyone in the member list was able to start recording)
} catch(error) { recordingTransactionsClient.unRegisterActionHandler('start');
recordingTransactionsClient.unRegisterAbortHandler('start');
//error is of type FailureReason
/*
interface FailureReason {
failedMemberId?: string;
/** Timeout occurred at the coordinator level waiting for members to reply */
isTimeout?: boolean;
/** Timeout happened at the initiator of the transaction waiting for the coordinator(server) to complete or abort the transaction */
isInitiatorTimeout?: boolean;
description: string}
*/
}
The client needs to provide a transaction handler. The registration of this handler is done per action type, for example for start
:
recordingTransactionsClient.registerActionHandler('start', async recordingId => {
//check if we are in the right recording
//start recording
//throwing an error will make the transaction fail and abort to be sent to all members of the transaction
});
Optionally the client can supply an abort action handler, for example for start
:
recordingTransactionsClient.registerAbortHandler('start', async recordingId => {
//if recording, stop
//throwing an error here won't affect the transaction (it's already aborted at this point). It will just log the error to the console
});
There can only be on handler for each action type. It is possible to "unregister" handlers, e.g.:
recordingTransactionsClient.unRegisterActionHandler('start');
recordingTransactionsClient.unRegisterAbortHandler('start');
Transaction is started for participant1
and participant2
. Both reply positively, transaction completes. participant3
also replies positively. An abort of the transaction type is sent to the room (e.g. if the transaction was to start recording then the room will get an abort recording) but there's no TransactionAborted
sent to the initiator (host).
TransactionAborted
) and this event only happens once per transaction.FAQs
Recording tailored transactions over socket.io
We found that @zencastr/socket-transactions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 11 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.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
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.