Don shigarwa da daidaitawa Mediasoup-client a cikin aikin, bi waɗannan matakan:
Shigar Node.js
Da farko, kuna buƙatar shigar da Node.js akan kwamfutarka. Node.js yanayi ne na lokaci mai aiki na JavaScript. Ziyarci gidan yanar gizon Node.js na hukuma( https://nodejs.org ) kuma zazzage sigar da ta dace don tsarin aikin ku. Da zarar an gama shigarwa, zaku iya bincika sigar Node.js da aka shigar ta buɗe tasha da gudanar da umarni mai zuwa:
node -v
Fara aikin kuma shigar Mediasoup-client
Ƙirƙiri sabon kundin adireshi don aikin ku kuma buɗe tasha a cikin wannan jagorar. Gudun umarni mai zuwa don fara sabon aikin Node.js kuma ƙirƙirar fayil ɗin package.json:
npm init -y
Na gaba, shigar Mediasoup-client a cikin aikin ta hanyar gudanar da umarni mai zuwa:
npm install mediasoup-client
Shigo da daidaitawa Mediasoup-client
A cikin fayil ɗin lambar tushen aikin ku, ƙara layi mai zuwa don shigo da shi Mediasoup-client
const mediasoupClient = require('mediasoup-client');
Don saita Mediasoup-client, kuna buƙatar ƙirƙirar Device
abu. Wannan abu yana wakiltar na'urar abokin ciniki kuma za'a yi amfani dashi don ƙirƙira da sarrafa hanyoyin sadarwa tare da uwar garken Mediasoup. Kuna iya ƙirƙirar wani Device
abu ta amfani da mahallin mahallin:
const device = new mediasoupClient.Device();
Bayan haka, kuna buƙatar ɗaukar bayanan "RTP Capabilities na Router" daga uwar garken Mediasoup. Ƙarfin RTP na na'ura mai ba da hanya tsakanin hanyoyin sadarwa yana ƙunshe da sigogi na fasaha kamar codecs masu goyan baya, tallafin uwar garke, da sigogin sarrafa kafofin watsa labarai masu alaƙa. Kuna iya dawo da wannan bayanin ta hanyar HTTP API ko ta hanyar sadarwa kai tsaye tare da uwar garken Mediasoup.
Bayan samun damar RTP na Router, yi amfani da device.load()
hanyar don loda wannan bayanin a cikin Device
abun.
Misali:
const routerRtpCapabilities = await fetchRouterRtpCapabilities(); // Function to fetch Router RTP Capabilities from the Mediasoup server
await device.load({ routerRtpCapabilities });
Ƙirƙiri da amfani da Sufuri
Don aikawa da karɓar rafukan mai jarida, kuna buƙatar ƙirƙira da amfani da Transport
abu. Kowane Transport
abu yana wakiltar hanyar sadarwa ta musamman tare da uwar garken Mediasoup. Kuna iya ƙirƙirar Transport
abu ta amfani da hanyoyin device.createSendTransport()
ko device.createRecvTransport()
hanyoyin.
Misali:
const transport = await device.createSendTransport({
// Transport configuration
});
Lokacin ƙirƙirar sufuri, zaku iya samar da sigogin daidaitawa kamar URL uwar garken da tashar haɗi. Bugu da ƙari, kuna iya sauraron abubuwan da suka faru kamar 'haɗa' ko 'samar da' akan Transport
abin don gudanar da hulɗar kafofin watsa labarai masu alaƙa.
Ƙirƙiri da amfani da Furodusa da Mabukaci
Don aikawa da karɓar rafukan mai jarida, kuna buƙatar ƙirƙira da amfani Producer
da Consumer
abubuwa. A Producer
yana wakiltar tushen kafofin watsa labarai da aka aika daga abokin ciniki zuwa uwar garken, yayin da yake Consumer
wakiltar tushen kafofin watsa labarai da aka karɓa daga uwar garken zuwa abokin ciniki. Kuna iya ƙirƙirar ta Producer
amfani da transport.produce()
hanyar, kuma ƙirƙirar ta Consumer
amfani da transport.consume()
hanyar.
Misali:
// Create Producer
const producer = await transport.produce({
kind: 'video',
// Producer configuration
});
// Create Consumer
const consumer = await transport.consume({
// Consumer configuration
});
// Use Producer and Consumer to send and receive media streams
// ...
Kuna iya amfani da samammun hanyoyin da abubuwan da suka faru akan abubuwan Producer
da Consumer
abubuwa don sarrafa watsawar watsa labarai, kamar aika bayanai, kunnawa/kashe rafukan watsa labarai, ko sarrafa abubuwan da suka shafi kafofin watsa labarai.
Saki albarkatun
Lokacin da kuka gama amfani da shi Mediasoup-client, tabbatar da fitar da albarkatu don guje wa ɓarnawar ƙwaƙwalwar ajiya da al'amuran albarkatun tsarin. Rufe sufuri da sauke na'urar ta amfani da hanyoyi transport.close()
da device.unload()
hanyoyin.
transport.close();
device.unload();
Waɗannan su ne ainihin matakan shigarwa, daidaitawa, da amfani da su Mediasoup-client a cikin aikin ku. Koma zuwa Mediasoup-client takaddun da ƙarin cikakkun misalai don ƙarin koyo game da fasalulluka masu ƙarfi da iyawarsa.