MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / connect

Method connect

packages/yalt/src/index.ts:127–171  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

125 }
126
127 async connect() {
128 this.log("Connecting to tunnel", {
129 url: this.url,
130 address: this.address,
131 socketOptions: this.socketOptions,
132 });
133
134 this.socket = new WebSocket(`wss://${this.url}/connect`, [], this.socketOptions);
135
136 this.socket.addEventListener("open", (args) => {
137 this.log("Connected to tunnel");
138 });
139
140 this.socket.addEventListener("close", (event) => {
141 this.log("Disconnected from tunnel", { event: event.code, reason: event.reason });
142 });
143
144 this.socket.addEventListener("message", async (event) => {
145 const data = JSON.parse(
146 typeof event.data === "string" ? event.data : new TextDecoder("utf-8").decode(event.data)
147 );
148
149 const message = ServerMessages.safeParse(data);
150
151 if (!message.success) {
152 this.log("Received invalid message", { data });
153 return;
154 }
155
156 switch (message.data.type) {
157 case "request": {
158 await this.handleRequest(message.data);
159
160 break;
161 }
162 default: {
163 console.error(`Unknown message type: ${message.data.type}`);
164 }
165 }
166 });
167
168 this.socket.addEventListener("error", (event) => {
169 this.log("Socket error", { error: event.message });
170 });
171 }
172
173 private async handleRequest(request: RequestMessage) {
174 if (!this.socket) {

Callers

nothing calls this directly

Calls 4

logMethod · 0.95
handleRequestMethod · 0.95
parseMethod · 0.80
errorMethod · 0.65

Tested by

no test coverage detected