CASTO SDK
The javascript implementation of the CASTO platform.
Install
npm install --save @casto/sdk
Tutorial and Examples
Basic
for sender
const Casto = require('@casto/sdk')
streamer = new Casto({type: "sender"})
for viewer
const Casto = require('@casto/sdk')
viewer = new Casto({type: "viewer"})
viewer.onSendChannelsList = ({channels}) => {
for (const channel in channels) {
/* Do some stuff for channel list */
button.addEventListener('click', ()=> {
/* media should be a mediaElement for streaming */
media.srcObject = await casto.getChannel(channel.peerId})
})
}
}
For other web frameworks (TBD)
- react tutorial
- vue tutorial
- vanilla javascript tutorial
Modules
{type: "sender"}
)
sender ( module that send stream to specific serviceId
{type: "viewer"}
)
viewer ( module that receive channel list of serviceId
and choose stream from the list to view.
relay
service that relays copies of the sender's stream to viewers.
- https://prisms.casto.tv/serviceId=<SERVICE_ID>
- default: https://prisms.casto.tv/serviceId=TESTO
API
Methods
Create a Casto - new Casto(options)
create an instance of the Casto Require keys in the
options
object:
-
type
: type of casto instance. If you want to do a broadcast, setsender
or setviewer
if you want to watch a broadcast. -
serviceId
: default isTESTO
-
streamerPeerId
:
casto.start(): MediaStream
start a broadcast by the Casto. Should return a
MediaStream
, which is an object for transfer to the remote.
casto.getChannel(peerId): MediaStream
Should return a
MediaStream
, which is an object that received broadcasting frompeerId
Events
Sender
casto.onNodeInitiated:
Casto is initiated. Ready to connect to relay nodes.
casto.onReadyToCast:
Successfully connected to a relay node and is ready to start broadcasting.
casto.onCompleted:
webRTC peerConnection is 'completed'. currently sending stream to a relay.
casto.onClosed:
webRTC peerConnection is 'closed'.
Viewer
casto.onNodeInitiated:
Casto is initiated. Ready to connect to relay nodes.
casto.onReadyToCast:
Successfully connected to a relay node and is ready to view streams.
casto.onClosed:
webRTC peerConnection is 'closed'.
casto.onSendChannelsList:
Retrieved available lists of channels from relay nodes.
casto.onSendChannelRemoved:
Channel is removed.
casto.onSendChannelAdded:
Channel is added.
casto.onWavesUpdated:
Received the updated channel information.
License
MIT © Casto Network