
Product
A New Overview in our Dashboard
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
@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 patch
npm publish
Or npm version minor
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
The npm package @zencastr/socket-transactions receives a total of 0 weekly downloads. As such, @zencastr/socket-transactions popularity was classified as not popular.
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.
Product
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.