Skip to content

Commit

Permalink
Separate Object Stream Forwarder function (#140)
Browse files Browse the repository at this point in the history
* refactor: separate lib.rs

* refactor: session_handler as class

* separate fn in uni stream receiver

* refactor: uni stream forwarder

* fix: not to close session with normal case

* added tracing

* Dagagram send/recv for client (#141)

* impl: datagram send/recv

* Datagram forward for server (#142)

* impl: datagram relay

* marked datagram

* fix: struct & variable name
  • Loading branch information
tetter27 authored Dec 20, 2024
1 parent 6e21eab commit 63df7f4
Show file tree
Hide file tree
Showing 18 changed files with 1,537 additions and 329 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Supported version: draft-ietf-moq-transport-06
- [ ] TRACK_STATUS
- [x] SUBSCRIBE_NAMESPACE_OK
- [x] SUBSCRIBE_NAMESPACE_ERROR
- [ ] Data Streams
- [ ] Object Datagram Message
- [x] Data Streams
- [x] Object Datagram Message
- [x] Track Stream
- [x] Subgroup Stream
- [ ] Features
Expand Down
28 changes: 19 additions & 9 deletions js/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ <h2>Connection</h2>
</div>
<br />
<div>
<h2>Forwarding Preference</h2>
<label><input type="radio" name="forwarding-preference" id="selectDatagram" value="datagram" />Datagram </label>
<label><input type="radio" name="forwarding-preference" id="selectTrack" value="track" checked/>Track </label>
<label><input type="radio" name="forwarding-preference" id="selectSubgroup" value="subgroup" />Subgroup </label>
<br />
*You must select at first
<h2>Message</h2>
<label>AuthInfo: <input type="text" name="auth-info" id="" value="secret" /> </label>
<br />
Expand Down Expand Up @@ -73,10 +79,9 @@ <h3>SUBSCRIBE</h3>
<button type="button" id="sendSubscribeBtn">Send</button>

<h3>OBJECT</h3>
<label><input type="radio" name="data-stream-type" id="selectTrack" value="track" checked/>Track Stream </label>
<label><input type="radio" name="data-stream-type" id="selectSubgroup" value="subgroup" />Track Subgroup </label>
<br />
<h4>Header</h4>
<div id="headerField" style="display: blocked;">
<h4>Header</h4>
</div>
<label>Subscribe ID: <input type="text" name="object-subscribe-id" id="" value="0" /> </label>
<br />
<label>Track Alias: <input type="text" name="object-track-alias" id="" value="0" /> </label>
Expand All @@ -89,12 +94,14 @@ <h4>Header</h4>
</div>
<label>Publisher Priority: <input type="text" name="publisher-priority" id="" value="0" /> </label>
<br />
<h4>Object</h4>
<div id="trackObjectContents" style="display: blocked;">
Group ID: <p id="trackGroupId">0</p>
<div id="objectField" style="display: blocked;">
<h4>Object</h4>
</div>
<div id="notSubgroupObjectContents" style="display: blocked;">
Group ID: <p id="mutableGroupId">0</p>
<br />
<button type="button" id="descendTrackGroupIdBtn">&lt;</button>
<button type="button" id="ascendTrackGroupIdBtn">&gt;</button>
<button type="button" id="descendMutableGroupIdBtn">&lt;</button>
<button type="button" id="ascendMutableGroupIdBtn">&gt;</button>
<br />
<br />
</div>
Expand All @@ -104,6 +111,9 @@ <h4>Object</h4>
<label>Payload:
<br /><textarea name="payload" id="object-payload" rows="5" cols="33">test</textarea> </label>
<br />
<div id="sendDatagramObject" style="display: none;">
<button type="button" id="sendDatagramObjectBtn">Send</button>
</div>
<div id="sendTrackObject" style="display: blocked;">
<button type="button" id="sendTrackObjectBtn">Send</button>
</div>
Expand Down
87 changes: 66 additions & 21 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ init().then(async () => {

let headerSend = false
let objectId = 0n
let trackGroupId = 0n
let mutableGroupId = 0n

const connectBtn = document.getElementById('connectBtn')
connectBtn.addEventListener('click', async () => {
Expand Down Expand Up @@ -57,7 +57,8 @@ init().then(async () => {

if (isSuccess) {
let expire = 0n
await client.sendSubscribeOkMessage(receivedSubscribeId, expire, authInfo)
const forwardingPreference = Array.from(form['forwarding-preference']).filter((elem) => elem.checked)[0].value
await client.sendSubscribeOkMessage(receivedSubscribeId, expire, authInfo, forwardingPreference)
} else {
// TODO: set accurate reasonPhrase
let reasonPhrase = 'subscribe error'
Expand All @@ -73,6 +74,11 @@ init().then(async () => {
console.log({ subscribeNamespaceResponse })
})

client.onObjectDatagram(async (objectDatagram) => {
console.log({ objectDatagram })
describeReceivedObject(objectDatagram.object_payload)
})

client.onStreamHeaderTrack(async (streamHeaderTrack) => {
console.log({ streamHeaderTrack })
})
Expand All @@ -92,7 +98,7 @@ init().then(async () => {
})

const objectIdElement = document.getElementById('objectId')
const trackGroupIdElement = document.getElementById('trackGroupId')
const mutableGroupIdElement = document.getElementById('mutableGroupId')

const sendSetupBtn = document.getElementById('sendSetupBtn')
sendSetupBtn.addEventListener('click', async () => {
Expand Down Expand Up @@ -155,6 +161,28 @@ init().then(async () => {
)
})

const sendDatagramObjectBtn = document.getElementById('sendDatagramObjectBtn')
sendDatagramObjectBtn.addEventListener('click', async () => {
console.log('send datagram object btn clicked')
const subscribeId = form['object-subscribe-id'].value
const trackAlias = form['object-track-alias'].value
const publisherPriority = form['publisher-priority'].value
const objectPayloadString = form['object-payload'].value

// encode the text to the object array
const objectPayloadArray = new TextEncoder().encode(objectPayloadString)

await client.sendObjectDatagram(
BigInt(subscribeId),
BigInt(trackAlias),
mutableGroupId,
objectId++,
publisherPriority,
objectPayloadArray
)
objectIdElement.textContent = objectId
})

const sendTrackObjectBtn = document.getElementById('sendTrackObjectBtn')
sendTrackObjectBtn.addEventListener('click', async () => {
console.log('send track stream object btn clicked')
Expand All @@ -172,7 +200,7 @@ init().then(async () => {
headerSend = true
}

await client.sendObjectStreamTrack(BigInt(subscribeId), trackGroupId, objectId++, objectPayloadArray)
await client.sendObjectStreamTrack(BigInt(subscribeId), mutableGroupId, objectId++, objectPayloadArray)
objectIdElement.textContent = objectId
})

Expand Down Expand Up @@ -205,50 +233,67 @@ init().then(async () => {
objectIdElement.textContent = objectId
})

const ascendTrackGroupBtn = document.getElementById('ascendTrackGroupIdBtn')
ascendTrackGroupBtn.addEventListener('click', async () => {
trackGroupId++
const ascendMutableGroupId = document.getElementById('ascendMutableGroupIdBtn')
ascendMutableGroupId.addEventListener('click', async () => {
mutableGroupId++
objectId = 0n
console.log('ascend trackGroupId', trackGroupId)
console.log('ascend mutableGroupId', mutableGroupId)

trackGroupIdElement.textContent = trackGroupId
mutableGroupIdElement.textContent = mutableGroupId
objectIdElement.textContent = objectId
})

const descendTrackGroupBtn = document.getElementById('descendTrackGroupIdBtn')
descendTrackGroupBtn.addEventListener('click', async () => {
if (trackGroupId === 0n) {
const descendMutableGroupId = document.getElementById('descendMutableGroupIdBtn')
descendMutableGroupId.addEventListener('click', async () => {
if (mutableGroupId === 0n) {
return
}
trackGroupId--
mutableGroupId--
objectId = 0n
console.log('descend trackGroupId', trackGroupId)
trackGroupIdElement.textContent = trackGroupId
console.log('descend mutableGroupId', mutableGroupId)
mutableGroupIdElement.textContent = mutableGroupId
objectIdElement.textContent = objectId
})

await client.start()
})

const dataStreamType = document.querySelectorAll('input[name="data-stream-type"]')
const forwardingPreference = document.querySelectorAll('input[name="forwarding-preference"]')
const subgroupHeaderContents = document.getElementById('subgroupHeaderContents')
const trackObjectContents = document.getElementById('trackObjectContents')
const notSubgroupObjectContents = document.getElementById('notSubgroupObjectContents')
const sendDatagramObject = document.getElementById('sendDatagramObject')
const sendTrackObject = document.getElementById('sendTrackObject')
const sendSubgroupObject = document.getElementById('sendSubgroupObject')
const headerField = document.getElementById('headerField')
const objectField = document.getElementById('objectField')

// change ui within track/subgroup
dataStreamType.forEach((elem) => {
forwardingPreference.forEach((elem) => {
elem.addEventListener('change', async () => {
if (elem.value === 'track') {
trackObjectContents.style.display = 'block'
if (elem.value === 'datagram') {
notSubgroupObjectContents.style.display = 'block'
subgroupHeaderContents.style.display = 'none'
sendDatagramObject.style.display = 'block'
sendTrackObject.style.display = 'none'
sendSubgroupObject.style.display = 'none'
headerField.style.display = 'none'
objectField.style.display = 'none'
} else if (elem.value === 'track') {
notSubgroupObjectContents.style.display = 'block'
subgroupHeaderContents.style.display = 'none'
sendDatagramObject.style.display = 'none'
sendTrackObject.style.display = 'block'
sendSubgroupObject.style.display = 'none'
headerField.style.display = 'block'
objectField.style.display = 'block'
} else if (elem.value === 'subgroup') {
trackObjectContents.style.display = 'none'
notSubgroupObjectContents.style.display = 'none'
subgroupHeaderContents.style.display = 'block'
sendDatagramObject.style.display = 'none'
sendTrackObject.style.display = 'none'
sendSubgroupObject.style.display = 'block'
headerField.style.display = 'block'
objectField.style.display = 'block'
}
})
})
Expand Down
1 change: 1 addition & 0 deletions moqt-client-sample/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ anyhow = "1.0.75"
version = "0.3.64"
features = [
'WebTransport',
"WebTransportDatagramDuplexStream",
'WebTransportBidirectionalStream',
'WebTransportSendStream',
'WebTransportReceiveStream',
Expand Down
Loading

0 comments on commit 63df7f4

Please sign in to comment.