Skip to content

Commit

Permalink
Merge pull request #7 from thomasjammet/dev
Browse files Browse the repository at this point in the history
feat(adapter): get rid of webrtc-adapter
  • Loading branch information
jobl committed Mar 4, 2024
2 parents 2f23a1e + d88befb commit 57cb7a4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import * as WebRTC from '@ceeblue/webrtc-client';
> }
> }
> ```
> - To avoid potential issues with backward compatibility or problems on iOS when using `navigator.mediaDevices.getUserMedia`, we recommend including the [WebRTC adapter](https://github.com/webrtcHacks/adapter) in the final project. This often mitigates common compatibility issues on certain older devices.
### Publish a stream
Expand Down
2 changes: 1 addition & 1 deletion examples/player-with-timed-metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>WebRTC Client Timed Metadata Player Example</h2>
<textarea id="metadata" rows="10" readonly></textarea>

<script type="module">
import { Player, Util, NetAddress } from "/dist/webrtc-client.js";
import { Player, Util, NetAddress } from "../dist/webrtc-client.js";

const logs = document.getElementById("metadata");
const videoElement = document.getElementById('video');
Expand Down
2 changes: 0 additions & 2 deletions examples/player.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ <h3 class="text-center">WebRTC Client Player Example</h3>
</div>
</div>

<!-- Avoid naming issues with Apple devices : -->
<script src="https://cdn.jsdelivr.net/npm/webrtc-adapter/out/adapter.js"></script>
<script type="module">
import { Player, HTTPConnector, WSController, Util, NetAddress } from "../dist/webrtc-client.js";
// development version, includes helpful console warnings
Expand Down
1 change: 0 additions & 1 deletion examples/streamer.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ <h4 class="text-center font-weight-bold">On Air</h4>
<!--<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>-->
<!-- production version, optimized for size and speed -->
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<script src="https://cdn.jsdelivr.net/npm/webrtc-adapter/out/adapter.js"></script>
<script type="module">
import { Streamer, HTTPConnector, WSController, Util, NetAddress } from "../dist/webrtc-client.js";
console.log('webrtc-client version:', Util.VERSION);
Expand Down
20 changes: 19 additions & 1 deletion src/connectors/SIPConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { SDP } from '../utils/SDP';
import { Util } from '../utils/Util';
import { ConnectionInfos, IConnector } from './IConnector';

const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);

/**
* SIPConnector is a common abstract class for negotiating a new RTCPeerConnection connection
* with the server.
Expand Down Expand Up @@ -221,7 +223,7 @@ export abstract class SIPConnector extends EventEmitter implements IConnector {
}
// Start the RTCPeerConnection and create an offer
try {
this._peerConnection = new RTCPeerConnection(iceServer ? { iceServers: [iceServer] } : undefined);
this._peerConnection = new RTCPeerConnection({ iceServers: [iceServer] });
} catch (e) {
this.close('RTCPeerConnection failed, ' + Util.stringify(e));
return;
Expand All @@ -239,6 +241,22 @@ export abstract class SIPConnector extends EventEmitter implements IConnector {
};
}

// Add transceivers for Safari
// This is necessary for Safari to handle the audio and video tracks correctly
if (isSafari) {
if (!this._stream) {
this._peerConnection.addTransceiver('audio', { direction: 'recvonly' });
this._peerConnection.addTransceiver('video', { direction: 'recvonly' });
} else {
const transceivers = this._peerConnection.getTransceivers();
for (const transceiver of transceivers) {
if (transceiver.receiver.track.kind === 'audio' || transceiver.receiver.track.kind === 'video') {
transceiver.direction = 'sendonly';
}
}
}
}

let sdp: string;
this._peerConnection
.createOffer({ offerToReceiveAudio: !this._stream, offerToReceiveVideo: !this._stream })
Expand Down

0 comments on commit 57cb7a4

Please sign in to comment.