talksphere-sdk 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/MIGRATION_EXAMPLE.md +164 -0
- package/README.md +241 -0
- package/dist/config-fetcher.d.ts +11 -0
- package/dist/config-fetcher.d.ts.map +1 -0
- package/dist/config-fetcher.js +23 -0
- package/dist/config-fetcher.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/room.d.ts +79 -0
- package/dist/room.d.ts.map +1 -0
- package/dist/room.js +227 -0
- package/dist/room.js.map +1 -0
- package/dist/signaling/socket-client.d.ts +88 -0
- package/dist/signaling/socket-client.d.ts.map +1 -0
- package/dist/signaling/socket-client.js +136 -0
- package/dist/signaling/socket-client.js.map +1 -0
- package/dist/types.d.ts +36 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/webrtc/media.d.ts +45 -0
- package/dist/webrtc/media.d.ts.map +1 -0
- package/dist/webrtc/media.js +87 -0
- package/dist/webrtc/media.js.map +1 -0
- package/dist/webrtc/peer.d.ts +65 -0
- package/dist/webrtc/peer.d.ts.map +1 -0
- package/dist/webrtc/peer.js +137 -0
- package/dist/webrtc/peer.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type IceServerConfig = Array<{
|
|
2
|
+
urls: string | string[];
|
|
3
|
+
username?: string;
|
|
4
|
+
credential?: string;
|
|
5
|
+
}>;
|
|
6
|
+
export interface PeerConnectionCallbacks {
|
|
7
|
+
onIceCandidate: (candidate: RTCIceCandidate) => void;
|
|
8
|
+
onTrack: (track: MediaStreamTrack, stream: MediaStream) => void;
|
|
9
|
+
onConnectionStateChange: (state: RTCPeerConnectionState) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Peer Connection Manager
|
|
13
|
+
* Manages RTCPeerConnection lifecycle and WebRTC negotiation
|
|
14
|
+
* PRESERVES exact behavior from useWebRTC.ts
|
|
15
|
+
*/
|
|
16
|
+
export declare class PeerConnectionManager {
|
|
17
|
+
private pc;
|
|
18
|
+
private iceServers;
|
|
19
|
+
private callbacks;
|
|
20
|
+
constructor(iceServers: IceServerConfig, callbacks: PeerConnectionCallbacks);
|
|
21
|
+
/**
|
|
22
|
+
* Create RTCPeerConnection
|
|
23
|
+
* MIGRATED from useWebRTC.ts lines 136-158
|
|
24
|
+
*/
|
|
25
|
+
createPeerConnection(): RTCPeerConnection;
|
|
26
|
+
/**
|
|
27
|
+
* Get current peer connection
|
|
28
|
+
*/
|
|
29
|
+
getPeerConnection(): RTCPeerConnection | null;
|
|
30
|
+
/**
|
|
31
|
+
* Add local tracks to peer connection
|
|
32
|
+
* MIGRATED from useWebRTC.ts line 71, 85
|
|
33
|
+
*/
|
|
34
|
+
addTracks(stream: MediaStream): void;
|
|
35
|
+
/**
|
|
36
|
+
* Create and set local offer
|
|
37
|
+
* MIGRATED from useWebRTC.ts lines 74-75
|
|
38
|
+
*/
|
|
39
|
+
createOffer(): Promise<RTCSessionDescriptionInit>;
|
|
40
|
+
/**
|
|
41
|
+
* Set remote offer and create answer
|
|
42
|
+
* MIGRATED from useWebRTC.ts lines 89-92
|
|
43
|
+
*/
|
|
44
|
+
createAnswer(remoteSdp: string): Promise<RTCSessionDescriptionInit>;
|
|
45
|
+
/**
|
|
46
|
+
* Set remote answer
|
|
47
|
+
* MIGRATED from useWebRTC.ts lines 99-101
|
|
48
|
+
*/
|
|
49
|
+
setRemoteAnswer(remoteSdp: string): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Add ICE candidate
|
|
52
|
+
* MIGRATED from useWebRTC.ts lines 107-109
|
|
53
|
+
*/
|
|
54
|
+
addIceCandidate(candidate: RTCIceCandidateInit): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Close peer connection
|
|
57
|
+
* MIGRATED from useWebRTC.ts line 176
|
|
58
|
+
*/
|
|
59
|
+
close(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Get connection state
|
|
62
|
+
*/
|
|
63
|
+
getConnectionState(): RTCPeerConnectionState | null;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=peer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peer.d.ts","sourceRoot":"","sources":["../../src/webrtc/peer.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC,CAAC;AAEH,MAAM,WAAW,uBAAuB;IACpC,cAAc,EAAE,CAAC,SAAS,EAAE,eAAe,KAAK,IAAI,CAAC;IACrD,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;IAChE,uBAAuB,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,CAAC;CACpE;AAED;;;;GAIG;AACH,qBAAa,qBAAqB;IAC9B,OAAO,CAAC,EAAE,CAAkC;IAC5C,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,SAAS,CAA0B;gBAE/B,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,uBAAuB;IAK3E;;;OAGG;IACH,oBAAoB,IAAI,iBAAiB;IAsCzC;;OAEG;IACH,iBAAiB,IAAI,iBAAiB,GAAG,IAAI;IAI7C;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAUpC;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAUvD;;;OAGG;IACG,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAczE;;;OAGG;IACG,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvD;;;OAGG;IACG,eAAe,CAAC,SAAS,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAapE;;;OAGG;IACH,KAAK,IAAI,IAAI;IAOb;;OAEG;IACH,kBAAkB,IAAI,sBAAsB,GAAG,IAAI;CAGtD"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Peer Connection Manager
|
|
2
|
+
// Wraps RTCPeerConnection and handles WebRTC negotiation
|
|
3
|
+
// MIGRATED from useWebRTC.ts lines 136-158
|
|
4
|
+
/**
|
|
5
|
+
* Peer Connection Manager
|
|
6
|
+
* Manages RTCPeerConnection lifecycle and WebRTC negotiation
|
|
7
|
+
* PRESERVES exact behavior from useWebRTC.ts
|
|
8
|
+
*/
|
|
9
|
+
export class PeerConnectionManager {
|
|
10
|
+
constructor(iceServers, callbacks) {
|
|
11
|
+
this.pc = null;
|
|
12
|
+
this.iceServers = iceServers;
|
|
13
|
+
this.callbacks = callbacks;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create RTCPeerConnection
|
|
17
|
+
* MIGRATED from useWebRTC.ts lines 136-158
|
|
18
|
+
*/
|
|
19
|
+
createPeerConnection() {
|
|
20
|
+
// Close existing connection if any
|
|
21
|
+
if (this.pc) {
|
|
22
|
+
this.pc.close();
|
|
23
|
+
}
|
|
24
|
+
this.pc = new RTCPeerConnection({
|
|
25
|
+
iceServers: this.iceServers,
|
|
26
|
+
});
|
|
27
|
+
// ICE candidate handler
|
|
28
|
+
// MIGRATED from lines 139-143
|
|
29
|
+
this.pc.onicecandidate = (event) => {
|
|
30
|
+
if (event.candidate) {
|
|
31
|
+
this.callbacks.onIceCandidate(event.candidate);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
// Remote track handler
|
|
35
|
+
// MIGRATED from lines 145-151
|
|
36
|
+
this.pc.ontrack = (event) => {
|
|
37
|
+
console.log('Remote track received');
|
|
38
|
+
const track = event.track;
|
|
39
|
+
const stream = event.streams[0];
|
|
40
|
+
this.callbacks.onTrack(track, stream);
|
|
41
|
+
};
|
|
42
|
+
// Connection state change handler
|
|
43
|
+
// MIGRATED from lines 153-155
|
|
44
|
+
this.pc.onconnectionstatechange = () => {
|
|
45
|
+
if (this.pc) {
|
|
46
|
+
this.callbacks.onConnectionStateChange(this.pc.connectionState);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return this.pc;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get current peer connection
|
|
53
|
+
*/
|
|
54
|
+
getPeerConnection() {
|
|
55
|
+
return this.pc;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Add local tracks to peer connection
|
|
59
|
+
* MIGRATED from useWebRTC.ts line 71, 85
|
|
60
|
+
*/
|
|
61
|
+
addTracks(stream) {
|
|
62
|
+
if (!this.pc) {
|
|
63
|
+
throw new Error('Peer connection not created');
|
|
64
|
+
}
|
|
65
|
+
stream.getTracks().forEach(track => {
|
|
66
|
+
this.pc.addTrack(track, stream);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create and set local offer
|
|
71
|
+
* MIGRATED from useWebRTC.ts lines 74-75
|
|
72
|
+
*/
|
|
73
|
+
async createOffer() {
|
|
74
|
+
if (!this.pc) {
|
|
75
|
+
throw new Error('Peer connection not created');
|
|
76
|
+
}
|
|
77
|
+
const offer = await this.pc.createOffer();
|
|
78
|
+
await this.pc.setLocalDescription(offer);
|
|
79
|
+
return offer;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Set remote offer and create answer
|
|
83
|
+
* MIGRATED from useWebRTC.ts lines 89-92
|
|
84
|
+
*/
|
|
85
|
+
async createAnswer(remoteSdp) {
|
|
86
|
+
if (!this.pc) {
|
|
87
|
+
throw new Error('Peer connection not created');
|
|
88
|
+
}
|
|
89
|
+
await this.pc.setRemoteDescription(new RTCSessionDescription({ type: 'offer', sdp: remoteSdp }));
|
|
90
|
+
const answer = await this.pc.createAnswer();
|
|
91
|
+
await this.pc.setLocalDescription(answer);
|
|
92
|
+
return answer;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Set remote answer
|
|
96
|
+
* MIGRATED from useWebRTC.ts lines 99-101
|
|
97
|
+
*/
|
|
98
|
+
async setRemoteAnswer(remoteSdp) {
|
|
99
|
+
if (!this.pc) {
|
|
100
|
+
throw new Error('Peer connection not created');
|
|
101
|
+
}
|
|
102
|
+
await this.pc.setRemoteDescription(new RTCSessionDescription({ type: 'answer', sdp: remoteSdp }));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Add ICE candidate
|
|
106
|
+
* MIGRATED from useWebRTC.ts lines 107-109
|
|
107
|
+
*/
|
|
108
|
+
async addIceCandidate(candidate) {
|
|
109
|
+
if (!this.pc) {
|
|
110
|
+
console.warn('Cannot add ICE candidate: peer connection not created');
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
await this.pc.addIceCandidate(new RTCIceCandidate(candidate));
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error('Error adding ICE candidate:', error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Close peer connection
|
|
122
|
+
* MIGRATED from useWebRTC.ts line 176
|
|
123
|
+
*/
|
|
124
|
+
close() {
|
|
125
|
+
if (this.pc) {
|
|
126
|
+
this.pc.close();
|
|
127
|
+
this.pc = null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get connection state
|
|
132
|
+
*/
|
|
133
|
+
getConnectionState() {
|
|
134
|
+
return this.pc?.connectionState ?? null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=peer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peer.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|
+
"name": "talksphere-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/",
|
|
15
|
+
"README.md",
|
|
16
|
+
"MIGRATION_EXAMPLE.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"dev": "tsc --watch"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"socket.io-client": "^4.8.3",
|
|
24
|
+
"@talksphere/shared": "*"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^5"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"react": {
|
|
34
|
+
"optional": true
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|