Skip to content

Commit

Permalink
improve example
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyoshiaki committed Aug 8, 2024
1 parent e35d4b4 commit d1d626b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 195 deletions.
46 changes: 0 additions & 46 deletions examples/send/fixture.ts

This file was deleted.

78 changes: 0 additions & 78 deletions examples/send/main.ts

This file was deleted.

19 changes: 0 additions & 19 deletions examples/send/package.json

This file was deleted.

49 changes: 22 additions & 27 deletions examples/sendrecv/audio.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import {
Event,
LocalAudioStream,
MediaStreamTrack,
MediaStreamTrackFactory,
RemoteVideoStream,
RtpPacket,
SkyWayContext,
SkyWayRoom,
randomPort,
SkyWayStreamFactory,
} from '../../packages/room/src';
import { testTokenString } from './fixture';
import { createSocket } from 'dgram';
import Gst from '@girs/node-gst-1.0';
import {
deserializeAudioLevelIndication,
Expand All @@ -23,34 +20,32 @@ gst.init([]);
const context = await SkyWayContext.Create(testTokenString, {
codecCapabilities: [{ mimeType: 'audio/opus' }],
});
const [track, port] = await MediaStreamTrackFactory.rtpSource({
kind: 'audio',
cb: (buf) => {
const rtp = RtpPacket.deSerialize(buf);
rtp.header.extension = true;
rtp.header.extensions.push({
id: 3,
payload: serializeAudioLevelIndication(25),
});
return rtp.serialize();
},
});
Gst.parseLaunch(
`audiotestsrc wave=ticks ! audioconvert ! audioresample ! queue ! opusenc ! rtpopuspay ! udpsink host=127.0.0.1 port=${port}`
).setState(Gst.State.PLAYING);
SkyWayStreamFactory.registerMediaDevices({ audio: track });

const room = await SkyWayRoom.Create(context, {
type: 'sfu',
});
console.log('roomId', room.id);
const sender = await room.join();

const audio = await randomPort();
const onAudio = new Event<Buffer>();
createSocket('udp4')
.on('message', (buf) => {
onAudio.emit(buf);
})
.bind(audio);
Gst.parseLaunch(
`audiotestsrc wave=ticks ! audioconvert ! audioresample ! queue ! opusenc ! rtpopuspay ! udpsink host=127.0.0.1 port=${audio}`
).setState(Gst.State.PLAYING);
const audioTrack = new MediaStreamTrack({ kind: 'audio' });
onAudio.add((buf) => {
const rtp = RtpPacket.deSerialize(buf);
rtp.header.extension = true;
rtp.header.extensions.push({
id: 3,
payload: serializeAudioLevelIndication(25),
});
audioTrack.writeRtp(rtp);
});

const publication = await sender.publish(new LocalAudioStream(audioTrack));
const publication = await sender.publish(
await SkyWayStreamFactory.createMicrophoneAudioStream()
);

const receiver = await (await SkyWayRoom.Find(context, room, 'sfu')).join();
const { stream: remoteStream } = await receiver.subscribe<RemoteVideoStream>(
Expand Down
37 changes: 13 additions & 24 deletions examples/sendrecv/video.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import {
LocalVideoStream,
MediaStreamTrack,
RemoteVideoStream,
SkyWayContext,
SkyWayRoom,
dePacketizeRtpPackets,
randomPort,
Event,
MediaStreamTrackFactory,
SkyWayStreamFactory,
} from '../../packages/room/src';
import { testTokenString } from './fixture';
import { createSocket } from 'dgram';
import Gst from '@girs/node-gst-1.0';

const gst = require('node-gtk').require('Gst', '1.0') as typeof Gst;
Expand All @@ -27,32 +24,24 @@ gst.init([]);
},
},
],
rtcConfig: { turnPolicy: 'disable' },
});
const room = await SkyWayRoom.Create(context, {
type: 'sfu',
const [track, port] = await MediaStreamTrackFactory.rtpSource({
kind: 'video',
});
console.log('roomId', room.id);
const sender = await room.join();

const video = await randomPort();
const onVideo = new Event<Buffer>();
createSocket('udp4')
.on('message', (buf) => {
onVideo.emit(buf);
})
.bind(video);

Gst.parseLaunch(
`videotestsrc ! video/x-raw,width=640,height=480,format=I420 ! x264enc key-int-max=60 ! rtph264pay ! udpsink host=127.0.0.1 port=${video}`
`videotestsrc ! video/x-raw,width=640,height=480,format=I420 ! x264enc key-int-max=60 ! rtph264pay ! udpsink host=127.0.0.1 port=${port}`
).setState(Gst.State.PLAYING);
SkyWayStreamFactory.registerMediaDevices({ video: track });

const track = new MediaStreamTrack({ kind: 'video' });
onVideo.add((data) => {
track.writeRtp(data);
const room = await SkyWayRoom.Create(context, {
type: 'sfu',
});
console.log('roomId', room.id);
const sender = await room.join();

const publication = await sender.publish(new LocalVideoStream(track));
const publication = await sender.publish(
await SkyWayStreamFactory.createCameraVideoStream()
);

const receiver = await (await SkyWayRoom.Find(context, room, 'sfu')).join();
const { stream: remoteStream } = await receiver.subscribe<RemoteVideoStream>(
Expand Down
2 changes: 1 addition & 1 deletion submodules/mediasoup
Submodule mediasoup updated 1 files
+1 −1 submodules/werift

0 comments on commit d1d626b

Please sign in to comment.