Skip to content

Commit d3d167a

Browse files
committed
[peer] bump to 0.0.18
1 parent 846de14 commit d3d167a

File tree

6 files changed

+78
-72
lines changed

6 files changed

+78
-72
lines changed

demo-cdn/index.html

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ <h5 id="other-identity"></h5>
3535
</article>
3636

3737
<script type="module">
38-
import { createPeer } from "https://esm.sh/jsr/@pulsebeam/peer@0.0.17";
38+
import {createPeer} from "https://esm.sh/jsr/@pulsebeam/peer@0.0.18";
3939

4040
const params = new URLSearchParams(window.location.search);
4141
const baseUrl = params.get("baseUrl");
@@ -90,84 +90,84 @@ <h5 id="other-identity"></h5>
9090
let currentChannel = null;
9191

9292
function updateUIState() {
93-
const isConnected = !!currentSession;
94-
refAction.textContent = isConnected ? "Disconnect" : "Connect";
95-
refData.disabled = !isConnected;
96-
if (!isConnected) {
97-
refData.value = '';
98-
refOtherIdentity.textContent = '';
99-
}
93+
const isConnected = !!currentSession;
94+
refAction.textContent = isConnected ? "Disconnect" : "Connect";
95+
refData.disabled = !isConnected;
96+
if (!isConnected) {
97+
refData.value = '';
98+
refOtherIdentity.textContent = '';
99+
}
100100
}
101101

102102
peer.onsession = (sess) => {
103-
// For you app consider your UI/UX in what you want to support
104-
// In this app, we only support one session at a time.
105-
// Closes any incoming sessions (connections) in favor of maintaining current session
106-
if (currentSession) {
107-
sess.close();
108-
// currentSession.close() //TODO: Seems like a bug when in this state
109-
}
110-
111-
currentSession = sess;
112-
otherPeerId = sess.other.peerId;
113-
114-
updateUIState()
115-
const chOut = sess.createDataChannel("chat");
116-
currentChannel = chOut;
117-
118-
chOut.onopen = () => {
119-
refOtherIdentity.textContent = `connected to ${otherPeerId}`;
120-
const inputHandler = (e) => chOut.send(e.target.value);
121-
refData.addEventListener("input", inputHandler);
122-
chOut._inputHandler = inputHandler;
123-
updateUIState();
124-
};
103+
// For you app consider your UI/UX in what you want to support
104+
// In this app, we only support one session at a time.
105+
// Closes any incoming sessions (connections) in favor of maintaining current session
106+
if (currentSession) {
107+
sess.close();
108+
// currentSession.close() //TODO: Seems like a bug when in this state
109+
}
110+
111+
currentSession = sess;
112+
otherPeerId = sess.other.peerId;
125113

126-
chOut.onclose = cleanup;
127-
sess.onclose = cleanup;
128-
sess.ondatachannel = (e) => {
129-
const chIn = e.channel;
130-
chIn.onmessage = ({data}) => {
131-
refData.value = data;
132-
};
133-
chIn.onclose = cleanup;
114+
updateUIState()
115+
const chOut = sess.createDataChannel("chat");
116+
currentChannel = chOut;
117+
118+
chOut.onopen = () => {
119+
refOtherIdentity.textContent = `connected to ${otherPeerId}`;
120+
const inputHandler = (e) => chOut.send(e.target.value);
121+
refData.addEventListener("input", inputHandler);
122+
chOut._inputHandler = inputHandler;
123+
updateUIState();
124+
};
125+
126+
chOut.onclose = cleanup;
127+
sess.onclose = cleanup;
128+
sess.ondatachannel = (e) => {
129+
const chIn = e.channel;
130+
chIn.onmessage = ({data}) => {
131+
refData.value = data;
134132
};
133+
chIn.onclose = cleanup;
134+
};
135135
};
136136

137137
function cleanup() {
138-
if (currentChannel) {
139-
if (currentChannel._inputHandler) {
140-
refData.removeEventListener("input", currentChannel._inputHandler);
141-
}
142-
currentChannel.close();
143-
currentChannel = null;
138+
if (currentChannel) {
139+
if (currentChannel._inputHandler) {
140+
refData.removeEventListener("input", currentChannel._inputHandler);
144141
}
145-
if (currentSession) {
146-
currentSession.close();
147-
currentSession = null;
148-
}
149-
updateUIState();
142+
currentChannel.close();
143+
currentChannel = null;
144+
}
145+
if (currentSession) {
146+
currentSession.close();
147+
currentSession = null;
148+
}
149+
updateUIState();
150150
}
151151

152152
let ac = new AbortController();
153153
action.addEventListener("click", async () => {
154-
if (currentSession || refAction.textContent === "Connecting...") {
155-
cleanup();
156-
ac.abort();
157-
ac = new AbortController();
158-
return;
159-
}
154+
if (currentSession || refAction.textContent === "Connecting...") {
155+
cleanup();
156+
ac.abort();
157+
ac = new AbortController();
158+
return;
159+
}
160160

161-
// Only initiate connection if not already connected
162-
try {
163-
refAction.textContent = "Connecting...";
164-
otherPeerId = refInput.value;
165-
console.log(`connecting to ${otherGroupId}:${otherPeerId}`);
166-
await peer.connect(otherGroupId, otherPeerId, ac.signal);
167-
} catch (e) {
168-
console.error(`Error in connecting to other peer: ${e}`)
169-
cleanup();
170-
}
161+
// Only initiate connection if not already connected
162+
try {
163+
refAction.textContent = "Connecting...";
164+
otherPeerId = refInput.value;
165+
console.log(`connecting to ${otherGroupId}:${otherPeerId}`);
166+
await peer.connect(otherGroupId, otherPeerId, ac.signal);
167+
} catch (e) {
168+
console.error(`Error in connecting to other peer: ${e}`)
169+
cleanup();
170+
}
171171
});
172172

173173
peer.start();

demo-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"dependencies": {
2020
"@pulsebeam/demo-server": "^1.0.0",
21-
"@pulsebeam/peer": "^0.0.17",
21+
"@pulsebeam/peer": "^0.0.18",
2222
"@pulsebeam/server": "^0.0.29",
2323
"@theopenweb/get-user-media-mock": "^1.0.0",
2424
"immer": "^10.1.1",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

peer/jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulsebeam/peer",
3-
"version": "0.0.17",
3+
"version": "0.0.18",
44
"exports": "./index.ts",
55
"license": "Apache-2.0",
66
"author": "Lukas Herman support@pulsebeam.dev",

peer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulsebeam/peer",
3-
"version": "0.0.17",
3+
"version": "0.0.18",
44
"type": "module",
55
"main": "./dist/index.cjs",
66
"module": "dist/index.mjs",

peer/transport.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import { afterEach, describe, expect, it } from "vitest";
2+
import { asleep } from "./util.ts";
3+
4+
describe("util", () => {
5+
it("should pass", async () => {
6+
});
7+
});
8+
19
/**
210
* skip these tests in favor of embedding foss server
3-
import { afterEach, describe, expect, it } from "vitest";
411
import { GrpcWebFetchTransport } from "@protobuf-ts/grpcweb-transport";
512
import {
613
ReservedConnId,
@@ -20,7 +27,6 @@ import { type ISignalingClient, SignalingClient } from "./signaling.client.ts";
2027
import type { ServerStreamingCall, UnaryCall } from "@protobuf-ts/runtime-rpc";
2128
import type { RpcOptions } from "@protobuf-ts/runtime-rpc";
2229
import { Logger, PRETTY_LOG_SINK } from "./logger.ts";
23-
import { asleep } from "./util.ts";
2430
2531
async function waitFor(
2632
conditionFn: () => boolean | Promise<boolean>,

0 commit comments

Comments
 (0)