Skip to content
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

feat: support current remote description #257

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export class PeerConnection {
setRemoteDescription(sdp: string, type: DescriptionType): void;
localDescription(): { type: string; sdp: string } | null;
remoteDescription(): { type: string; sdp: string } | null;
currentRemoteDescription(): { type: string; sdp: string } | null;
addRemoteCandidate(candidate: string, mid: string): void;
createDataChannel(label: string, config?: DataChannelInitConfig): DataChannel;
addTrack(media: Video | Audio): Track;
Expand Down
2 changes: 1 addition & 1 deletion polyfill/RTCPeerConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class _RTCPeerConnection extends EventTarget {
}

get currentRemoteDescription() {
return new RTCSessionDescription(this.#peerConnection.remoteDescription());
return new RTCSessionDescription(this.#peerConnection.currentRemoteDescription());
}

get localDescription() {
Expand Down
19 changes: 19 additions & 0 deletions src/peer-connection-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Napi::Object PeerConnectionWrapper::Init(Napi::Env env, Napi::Object exports)
InstanceMethod("setRemoteDescription", &PeerConnectionWrapper::setRemoteDescription),
InstanceMethod("localDescription", &PeerConnectionWrapper::localDescription),
InstanceMethod("remoteDescription", &PeerConnectionWrapper::remoteDescription),
InstanceMethod("currentRemoteDescription", &PeerConnectionWrapper::currentRemoteDescription),
InstanceMethod("addRemoteCandidate", &PeerConnectionWrapper::addRemoteCandidate),
InstanceMethod("createDataChannel", &PeerConnectionWrapper::createDataChannel),
InstanceMethod("addTrack", &PeerConnectionWrapper::addTrack),
Expand Down Expand Up @@ -412,6 +413,24 @@ Napi::Value PeerConnectionWrapper::remoteDescription(const Napi::CallbackInfo &i
return obj;
}

Napi::Value PeerConnectionWrapper::currentRemoteDescription(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();

std::optional<rtc::Description> desc = mRtcPeerConnPtr ? mRtcPeerConnPtr->currentRemoteDescription() : std::nullopt;

// Return JS null if no description
if (!desc.has_value())
{
return env.Null();
}

Napi::Object obj = Napi::Object::New(env);
obj.Set("type", desc->typeString());
obj.Set("sdp", desc.value());
return obj;
}

void PeerConnectionWrapper::addRemoteCandidate(const Napi::CallbackInfo &info)
{
PLOG_DEBUG << "addRemoteCandidate() called";
Expand Down
1 change: 1 addition & 0 deletions src/peer-connection-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PeerConnectionWrapper : public Napi::ObjectWrap<PeerConnectionWrapper>
void setRemoteDescription(const Napi::CallbackInfo &info);
Napi::Value localDescription(const Napi::CallbackInfo &info);
Napi::Value remoteDescription(const Napi::CallbackInfo &info);
Napi::Value currentRemoteDescription(const Napi::CallbackInfo &info);
void addRemoteCandidate(const Napi::CallbackInfo &info);
Napi::Value createDataChannel(const Napi::CallbackInfo &info);
Napi::Value addTrack(const Napi::CallbackInfo &info);
Expand Down
Loading