-
Notifications
You must be signed in to change notification settings - Fork 22
Set maxMessageSize on transports and... #84
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| import cloneDeep from "lodash/cloneDeep"; | ||
| import { | ||
| APIRequest, | ||
| isAPIRequest, | ||
| logger, | ||
| makeRequest, | ||
| messageSizeWithinLimit, | ||
| MessageTooLargeError, | ||
| RTVIError, | ||
| RTVIMessage, | ||
| PipecatClientOptions, | ||
|
|
@@ -10,8 +14,6 @@ import { | |
| TransportStartError, | ||
| TransportState, | ||
| UnsupportedFeatureError, | ||
| APIRequest, | ||
| isAPIRequest, | ||
| } from "@pipecat-ai/client-js"; | ||
| import { MediaManager } from "../../../lib/media-mgmt/mediaManager"; | ||
| import { DailyMediaManager } from "../../../lib/media-mgmt/dailyMediaManager"; | ||
|
|
@@ -428,6 +430,13 @@ export class SmallWebRTCTransport extends Transport { | |
| logger.warn(`Datachannel is not ready. Message not sent: ${message}`); | ||
| return; | ||
| } | ||
|
|
||
| // Note: This shouldn't happen since client-js should have already checked this | ||
| if (!messageSizeWithinLimit(message, this._maxMessageSize)) { | ||
| throw new MessageTooLargeError( | ||
| "Message data too large. Max size is " + this._maxMessageSize, | ||
| ); | ||
| } | ||
| this.dc?.send(JSON.stringify(message)); | ||
| } | ||
|
|
||
|
|
@@ -903,6 +912,7 @@ export class SmallWebRTCTransport extends Transport { | |
|
|
||
| dc.addEventListener("open", () => { | ||
| logger.debug("datachannel opened"); | ||
| this._maxMessageSize = this.pc?.sctp?.maxMessageSize ?? 64 * 1024; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was inspecting this and noticed that Chrome requested (offer SDP) a max message size of: However, the answer (SDP) from aiortc was: So the default value we’re using is correct. However, if we want to be 100% accurate, we could retrieve this exact value from the SDP answer, in case
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. per our discussion, this is happening with the above
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I have missed this one. 🙂 |
||
| if (this._connectResolved) { | ||
| this.syncTrackStatus(); | ||
| this._connectResolved(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ export class WebSocketTransport extends Transport { | |
| ); | ||
| this._ws = null; | ||
| this._serializer = opts.serializer || new ProtobufFrameSerializer(); | ||
| this._maxMessageSize = 1024 * 1024; // python websockets default to 1MB | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to allow users to change this default value when creating the transport ? I’m not sure whether they can change it on the server side if they have a custom WebSocket implementation.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. per our discussion, we think this is fine for now. |
||
| } | ||
|
|
||
| initialize( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I haven’t tested this yet. Is this what happens if we try to send a message that’s too large, the data channel never recover ?
I would expect to just receive an error and for it to keep working afterward. 🤕