Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added payload-protocol-identifier code. #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/association.js
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ class Association extends EventEmitter {
},
stream_id: streamId,
ssn: this.ssn[streamId],
ppid: options.streamId,
ppid: options.ppid,
user_data: buffer.slice(offset, offset + mtu)
}
offset += mtu
Expand All @@ -1797,7 +1797,7 @@ class Association extends EventEmitter {
},
stream_id: streamId,
ssn: this.ssn[streamId],
ppid: options.streamId,
ppid: options.ppid,
user_data: buffer
}
this._sendChunk('data', chunk, null, callback)
Expand Down
30 changes: 27 additions & 3 deletions lib/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const EventEmitter = require('events').EventEmitter
const debug = require('debug')
const ip = require('ip')
const Endpoint = require('./endpoint')
const defs = require('./defs')

class SCTPStreamReadable extends Readable {
// Constructor is useless
Expand Down Expand Up @@ -41,9 +42,32 @@ class SCTPStreamWritable extends Writable {
if (!this.socket.association) {
return callback(new Error('no association established'))
}
const options = {}
options.stream_id = this.stream_id
this.bytesWritten += chunk.length
// Set ppid (payload-protocol-identifier)
// more info:
// https://webrtcforthecurious.com/docs/07-data-communication/#payload-protocol-identifier
let ppid

// Data is binary?
if (chunk.length == 0) {
// if No data, lenght == 0, then
// chunk = add ceros 'like firefox'
// and set ppid to empty code with flavor Binary or String.
chunk = Buffer.from('00000000', 'hex')
ppid = encoding === 'buffer'
? defs.PPID.WEBRTC_BINARY_EMPTY
: defs.PPID.WEBRTC_STRING_EMPTY
} else {
// set ppid to data code with flavor Binary or String.
ppid = encoding === 'buffer'
? defs.PPID.WEBRTC_BINARY
: defs.PPID.WEBRTC_STRING
}

const options = {
stream_id: this.stream_id,
unordered: this.socket.unordered,
ppid,
}
this.socket.bytesWritten += chunk.length
return this.socket.association.SEND(chunk, options, callback)
}
Expand Down
Loading