@pipecat-ai/websocket-transport 0.4.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +15 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -25
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +40 -26
- package/dist/index.module.js.map +1 -1
- package/package.json +3 -3
package/dist/index.module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import $kR6tG$dailycodailyjs from "@daily-co/daily-js";
|
|
2
|
-
import {logger as $kR6tG$logger, TransportStartError as $kR6tG$TransportStartError, RTVIMessage as $kR6tG$RTVIMessage, Transport as $kR6tG$Transport} from "@pipecat-ai/client-js";
|
|
2
|
+
import {RTVIError as $kR6tG$RTVIError, logger as $kR6tG$logger, TransportStartError as $kR6tG$TransportStartError, RTVIMessage as $kR6tG$RTVIMessage, UnsupportedFeatureError as $kR6tG$UnsupportedFeatureError, Transport as $kR6tG$Transport} from "@pipecat-ai/client-js";
|
|
3
3
|
import {EventEmitter as $kR6tG$EventEmitter} from "events";
|
|
4
4
|
import {reflectionMergePartial as $kR6tG$reflectionMergePartial, UnknownFieldHandler as $kR6tG$UnknownFieldHandler, WireType as $kR6tG$WireType, MessageType as $kR6tG$MessageType} from "@protobuf-ts/runtime";
|
|
5
5
|
import {mulaw as $kR6tG$mulaw} from "x-law";
|
|
@@ -1564,7 +1564,7 @@ var $fc49a56cd8739127$export$4a0c46dbbe2ddb67 = /** @class */ function() {
|
|
|
1564
1564
|
MediaManager.prototype.setUserAudioCallback = function(userAudioCallback) {
|
|
1565
1565
|
this._userAudioCallback = userAudioCallback;
|
|
1566
1566
|
};
|
|
1567
|
-
MediaManager.prototype.
|
|
1567
|
+
MediaManager.prototype.setClientOptions = function(options, override) {
|
|
1568
1568
|
var _a, _b, _c;
|
|
1569
1569
|
if (override === void 0) override = false;
|
|
1570
1570
|
if (this._options && !override) return;
|
|
@@ -3861,23 +3861,22 @@ class $a6c080dc51c9687f$export$4b2026f8e11b148a {
|
|
|
3861
3861
|
|
|
3862
3862
|
|
|
3863
3863
|
class $7f42eda74f1b1632$export$de21836fc42c6f9c extends (0, $kR6tG$Transport) {
|
|
3864
|
-
constructor(
|
|
3865
|
-
serializer: new (0, $a6c080dc51c9687f$export$4b2026f8e11b148a)(),
|
|
3866
|
-
recorderSampleRate: $7f42eda74f1b1632$export$de21836fc42c6f9c.RECORDER_SAMPLE_RATE,
|
|
3867
|
-
playerSampleRate: $7f42eda74f1b1632$export$de21836fc42c6f9c.PLAYER_SAMPLE_RATE
|
|
3868
|
-
}){
|
|
3864
|
+
constructor(opts = {}){
|
|
3869
3865
|
super();
|
|
3866
|
+
this._wsUrl = null;
|
|
3870
3867
|
this.audioQueue = [];
|
|
3871
|
-
this.
|
|
3868
|
+
this._wsUrl = opts.ws_url || null;
|
|
3869
|
+
this._recorderSampleRate = opts.recorderSampleRate || $7f42eda74f1b1632$export$de21836fc42c6f9c.RECORDER_SAMPLE_RATE;
|
|
3870
|
+
this._mediaManager = new (0, $22ece045290c996a$export$c95c65abc5f47125)(true, true, undefined, undefined, 512, this._recorderSampleRate, opts.playerSampleRate || $7f42eda74f1b1632$export$de21836fc42c6f9c.PLAYER_SAMPLE_RATE);
|
|
3872
3871
|
this._mediaManager.setUserAudioCallback(this.handleUserAudioStream.bind(this));
|
|
3873
3872
|
this._ws = null;
|
|
3874
|
-
this._serializer = serializer;
|
|
3873
|
+
this._serializer = opts.serializer || new (0, $a6c080dc51c9687f$export$4b2026f8e11b148a)();
|
|
3875
3874
|
}
|
|
3876
3875
|
initialize(options, messageHandler) {
|
|
3877
3876
|
this._options = options;
|
|
3878
3877
|
this._callbacks = options.callbacks ?? {};
|
|
3879
3878
|
this._onMessage = messageHandler;
|
|
3880
|
-
this._mediaManager.
|
|
3879
|
+
this._mediaManager.setClientOptions(options);
|
|
3881
3880
|
this.state = "disconnected";
|
|
3882
3881
|
}
|
|
3883
3882
|
async initDevices() {
|
|
@@ -3885,12 +3884,33 @@ class $7f42eda74f1b1632$export$de21836fc42c6f9c extends (0, $kR6tG$Transport) {
|
|
|
3885
3884
|
await this._mediaManager.initialize();
|
|
3886
3885
|
this.state = "initialized";
|
|
3887
3886
|
}
|
|
3888
|
-
|
|
3887
|
+
_validateConnectionParams(connectParams) {
|
|
3888
|
+
if (connectParams === undefined || connectParams === null) return undefined;
|
|
3889
|
+
if (typeof connectParams !== "object") throw new (0, $kR6tG$RTVIError)("Invalid connection parameters");
|
|
3890
|
+
const fixedParams = {};
|
|
3891
|
+
for (const [key, val] of Object.entries(connectParams)){
|
|
3892
|
+
// acept ws_url for backwards compatibility
|
|
3893
|
+
if (key === "ws_url" || key === "connectionUrl") {
|
|
3894
|
+
if (typeof val !== "string") throw new (0, $kR6tG$RTVIError)(`Invalid type for connectionUrl: expected string, got ${typeof val}`);
|
|
3895
|
+
fixedParams.ws_url = val;
|
|
3896
|
+
} else throw new (0, $kR6tG$RTVIError)(`Unrecognized connection parameter: ${key}. Only 'connectionUrl' is allowed.`);
|
|
3897
|
+
}
|
|
3898
|
+
return fixedParams;
|
|
3899
|
+
}
|
|
3900
|
+
async _connect(connectParams) {
|
|
3901
|
+
if (this._abortController?.signal.aborted) return;
|
|
3889
3902
|
this.state = "connecting";
|
|
3903
|
+
this._wsUrl = connectParams?.ws_url || this._wsUrl;
|
|
3904
|
+
if (!this._wsUrl) {
|
|
3905
|
+
(0, $kR6tG$logger).error("No url provided for connection");
|
|
3906
|
+
this.state = "error";
|
|
3907
|
+
throw new (0, $kR6tG$TransportStartError)();
|
|
3908
|
+
}
|
|
3890
3909
|
try {
|
|
3891
|
-
this._ws = this.initializeWebsocket(
|
|
3910
|
+
this._ws = this.initializeWebsocket();
|
|
3892
3911
|
await this._ws.connect();
|
|
3893
3912
|
await this._mediaManager.connect();
|
|
3913
|
+
if (this._abortController?.signal.aborted) return;
|
|
3894
3914
|
this.state = "connected";
|
|
3895
3915
|
this._callbacks.onConnected?.();
|
|
3896
3916
|
} catch (error) {
|
|
@@ -3900,7 +3920,7 @@ class $7f42eda74f1b1632$export$de21836fc42c6f9c extends (0, $kR6tG$Transport) {
|
|
|
3900
3920
|
throw new (0, $kR6tG$TransportStartError)(msg);
|
|
3901
3921
|
}
|
|
3902
3922
|
}
|
|
3903
|
-
async
|
|
3923
|
+
async _disconnect() {
|
|
3904
3924
|
this.state = "disconnecting";
|
|
3905
3925
|
await this._mediaManager.disconnect();
|
|
3906
3926
|
await this._ws?.close();
|
|
@@ -3945,15 +3965,11 @@ class $7f42eda74f1b1632$export$de21836fc42c6f9c extends (0, $kR6tG$Transport) {
|
|
|
3945
3965
|
this._state = state;
|
|
3946
3966
|
this._callbacks.onTransportStateChanged?.(state);
|
|
3947
3967
|
}
|
|
3948
|
-
get expiry() {
|
|
3949
|
-
return this._expiry;
|
|
3950
|
-
}
|
|
3951
3968
|
tracks() {
|
|
3952
3969
|
return this._mediaManager.tracks();
|
|
3953
3970
|
}
|
|
3954
|
-
initializeWebsocket(
|
|
3955
|
-
|
|
3956
|
-
const ws = new (0, $032380dbcf3f4e13$export$4f3d0ffd941ebefb)(`${authBundle.ws_url}`, undefined, {
|
|
3971
|
+
initializeWebsocket() {
|
|
3972
|
+
const ws = new (0, $032380dbcf3f4e13$export$4f3d0ffd941ebefb)(this._wsUrl, undefined, {
|
|
3957
3973
|
parseBlobToJson: false
|
|
3958
3974
|
});
|
|
3959
3975
|
// disabling the keep alive, there is no API for it inside Pipecat
|
|
@@ -4009,18 +4025,16 @@ class $7f42eda74f1b1632$export$de21836fc42c6f9c extends (0, $kR6tG$Transport) {
|
|
|
4009
4025
|
}
|
|
4010
4026
|
}
|
|
4011
4027
|
sendRawMessage(message) {
|
|
4012
|
-
(0, $kR6tG$logger).debug("Received raw message to send to Web Socket", message);
|
|
4013
4028
|
const encoded = this._serializer.serialize(message);
|
|
4014
4029
|
this._sendMsg(encoded);
|
|
4015
4030
|
}
|
|
4016
4031
|
sendMessage(message) {
|
|
4017
|
-
(0, $kR6tG$logger).debug("Received message to send to Web Socket", message);
|
|
4018
4032
|
const encoded = this._serializer.serializeMessage(message);
|
|
4019
4033
|
this._sendMsg(encoded);
|
|
4020
4034
|
}
|
|
4021
4035
|
async _sendAudioInput(data) {
|
|
4022
4036
|
try {
|
|
4023
|
-
const encoded = this._serializer.serializeAudio(data,
|
|
4037
|
+
const encoded = this._serializer.serializeAudio(data, this._recorderSampleRate, 1);
|
|
4024
4038
|
await this._sendMsg(encoded);
|
|
4025
4039
|
} catch (e) {
|
|
4026
4040
|
(0, $kR6tG$logger).error("Error sending audio frame", e);
|
|
@@ -4049,8 +4063,8 @@ class $7f42eda74f1b1632$export$de21836fc42c6f9c extends (0, $kR6tG$Transport) {
|
|
|
4049
4063
|
}
|
|
4050
4064
|
// Not implemented
|
|
4051
4065
|
enableScreenShare(enable) {
|
|
4052
|
-
(0, $kR6tG$logger).error("
|
|
4053
|
-
throw new
|
|
4066
|
+
(0, $kR6tG$logger).error("enableScreenShare not implemented for WebSocketTransport");
|
|
4067
|
+
throw new (0, $kR6tG$UnsupportedFeatureError)("enableScreenShare", "webSocketTransport", "This feature has not been implemented");
|
|
4054
4068
|
}
|
|
4055
4069
|
get isSharingScreen() {
|
|
4056
4070
|
(0, $kR6tG$logger).error("isSharingScreen not implemented for WebSocketTransport");
|
|
@@ -4058,7 +4072,7 @@ class $7f42eda74f1b1632$export$de21836fc42c6f9c extends (0, $kR6tG$Transport) {
|
|
|
4058
4072
|
}
|
|
4059
4073
|
enableCam(enable) {
|
|
4060
4074
|
(0, $kR6tG$logger).error("enableCam not implemented for WebSocketTransport");
|
|
4061
|
-
throw new
|
|
4075
|
+
throw new (0, $kR6tG$UnsupportedFeatureError)("enableCam", "webSocketTransport", "This feature has not been implemented");
|
|
4062
4076
|
}
|
|
4063
4077
|
get isCamEnabled() {
|
|
4064
4078
|
(0, $kR6tG$logger).error("isCamEnabled not implemented for WebSocketTransport");
|
|
@@ -4066,7 +4080,7 @@ class $7f42eda74f1b1632$export$de21836fc42c6f9c extends (0, $kR6tG$Transport) {
|
|
|
4066
4080
|
}
|
|
4067
4081
|
get selectedCam() {
|
|
4068
4082
|
(0, $kR6tG$logger).error("selectedCam not implemented for WebSocketTransport");
|
|
4069
|
-
throw new
|
|
4083
|
+
throw new (0, $kR6tG$UnsupportedFeatureError)("selectedCam", "webSocketTransport", "This feature has not been implemented");
|
|
4070
4084
|
}
|
|
4071
4085
|
}
|
|
4072
4086
|
$7f42eda74f1b1632$export$de21836fc42c6f9c.RECORDER_SAMPLE_RATE = 16000;
|