-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix RealtimeAPI
getRoomSessions
(#750)
* add wrtc to e2e-test rt-api * add videoUtils * add TODO lines * improve rt-api e2e tests for video * run only video tests * add videoUtils to spin off roomSessions in realtime-api e2e tests * improve e2e tests for realtime-api * disable cache for some video events * revert unit test - we have no cache obj now * changeset * revert dev change
- Loading branch information
Edoardo Gallo
authored
Feb 28, 2023
1 parent
908e158
commit fe3b0e2
Showing
8 changed files
with
685 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@signalwire/realtime-api': patch | ||
--- | ||
|
||
Fix bug between getRoomSessions and nested objects in the Video client. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { mediaDevices, RTCPeerConnection, MediaStream } from 'wrtc' | ||
import { CloseEvent } from '@signalwire/core' | ||
import { Video } from '@signalwire/js' | ||
import { WebSocket } from 'ws' | ||
import { request } from 'node:https' | ||
import { getAuthorization } from './utils' | ||
|
||
// @ts-expect-error | ||
mediaDevices.enumerateDevices = () => { | ||
return Promise.resolve([]) | ||
} | ||
|
||
const PERMISSIONS = [ | ||
'room.self.audio_mute', | ||
'room.self.audio_unmute', | ||
'room.self.video_mute', | ||
'room.self.video_unmute', | ||
'room.self.deaf', | ||
'room.self.undeaf', | ||
'room.self.set_input_volume', | ||
'room.self.set_output_volume', | ||
'room.self.set_input_sensitivity', | ||
'room.list_available_layouts', | ||
'room.set_layout', | ||
'room.member.video_mute', | ||
'room.member.audio_mute', | ||
'room.member.remove', | ||
'room.recording', | ||
'room.playback', | ||
'room.playback_seek', | ||
] | ||
type CreateVRTParams = { | ||
roomName: string | ||
userName: string | ||
} | ||
const createVRT = (params: CreateVRTParams): Promise<{ token: string }> => { | ||
return new Promise((resolve, reject) => { | ||
const data = JSON.stringify({ | ||
room_name: params.roomName, | ||
user_name: params.userName, | ||
auto_create_room: true, | ||
permissions: PERMISSIONS, | ||
}) | ||
const options = { | ||
host: process.env.API_HOST, | ||
port: 443, | ||
method: 'POST', | ||
path: '/api/video/room_tokens', | ||
headers: { | ||
Authorization: getAuthorization(), | ||
'Content-Type': 'application/json', | ||
'Content-Length': data.length, | ||
}, | ||
} | ||
// console.log('CRT options', options) | ||
const req = request(options, (response) => { | ||
let body = '' | ||
response.on('data', (chunk) => { | ||
body += chunk | ||
}) | ||
|
||
response.on('end', () => { | ||
resolve(JSON.parse(body)) | ||
}) | ||
}) | ||
|
||
req.on('error', reject) | ||
|
||
req.write(data) | ||
req.end() | ||
}) | ||
} | ||
|
||
type CreateRoomSessionParams = CreateVRTParams & {} | ||
export const createRoomSession = ( | ||
params: CreateRoomSessionParams | ||
): Promise<Video.RoomSession> => { | ||
return new Promise(async (resolve, reject) => { | ||
try { | ||
const { token } = await createVRT(params) | ||
|
||
global.MediaStream = MediaStream | ||
// @ts-expect-error | ||
global.Audio = function () { | ||
console.log('using audio') | ||
} | ||
global.CloseEvent = CloseEvent | ||
global.WebSocket = WebSocket | ||
// @ts-expect-error | ||
global.navigator = { | ||
mediaDevices, | ||
} | ||
// @ts-expect-error | ||
global.window = { | ||
RTCPeerConnection, | ||
} | ||
|
||
const roomSession = new Video.RoomSession({ | ||
host: process.env.RELAY_HOST || 'relay.signalwire.com', | ||
token: token, | ||
audio: true, | ||
video: true, | ||
// logLevel: 'error', | ||
// debug: { | ||
// logWsTraffic: true, | ||
// }, | ||
}) | ||
|
||
// @ts-expect-error | ||
roomSession._mungeSDP = (sdp: string) => { | ||
console.log('SDP', sdp) | ||
const newLine = '\r\n' | ||
return ( | ||
sdp | ||
.split(newLine) | ||
.filter((line) => { | ||
if (line.startsWith('a=candidate')) { | ||
return !line.includes('127.0.0.1') | ||
} | ||
return true | ||
}) | ||
.join(newLine) + newLine | ||
) | ||
} | ||
|
||
roomSession.join().then((roomSession) => { | ||
// console.log('CreateRoomSession OK', roomSession) | ||
resolve(roomSession) | ||
}) | ||
} catch (error) { | ||
console.error('CreateRoomSession Error', error) | ||
reject(error) | ||
} | ||
}) | ||
} |
Oops, something went wrong.