object instead of string

This commit is contained in:
mbattista 2021-04-04 20:08:28 +00:00
parent 29b4881c08
commit c7a178e5a4
5 changed files with 10 additions and 15 deletions

View File

@ -183,7 +183,7 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
this._ws!.send(JSON.stringify({ event, ...payload })) this._ws!.send(JSON.stringify({ event, ...payload }))
} }
public createPeer(sdp: string, lite: boolean, servers: string) { public createPeer(sdp: string, lite: boolean, servers: RTCIceServer[]) {
this.emit('debug', `creating peer`) this.emit('debug', `creating peer`)
if (!this.socketOpen) { if (!this.socketOpen) {
this.emit( this.emit(
@ -202,7 +202,7 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
this._peer = new RTCPeerConnection() this._peer = new RTCPeerConnection()
if (lite !== true) { if (lite !== true) {
this._peer = new RTCPeerConnection({ this._peer = new RTCPeerConnection({
iceServers: JSON.parse(servers), iceServers: servers,
}) })
} }

View File

@ -67,7 +67,7 @@ export interface SignalProvideMessage extends WebSocketMessage, SignalProvidePay
export interface SignalProvidePayload { export interface SignalProvidePayload {
id: string id: string
lite: boolean lite: boolean
ice: string ice: RTCIceServer[]
sdp: string sdp: string
} }

View File

@ -54,9 +54,9 @@ func (s *WebRTC) Set() {
s.ICELite = viper.GetBool("icelite") s.ICELite = viper.GetBool("icelite")
s.ICEServers = []webrtc.ICEServer{{URLs: viper.GetStringSlice("iceserver")}} s.ICEServers = []webrtc.ICEServer{{URLs: viper.GetStringSlice("iceserver")}}
if (viper.GetString("iceservers") != "") { if (viper.GetString("iceservers") != "") {
errj := json.Unmarshal([]byte(viper.GetString("iceservers")), &s.ICEServers) err := json.Unmarshal([]byte(viper.GetString("iceservers")), &s.ICEServers)
if (errj != nil) { if (err != nil) {
panic(errj) panic(err)
} }
} }
s.NAT1To1IPs = viper.GetStringSlice("nat1to1") s.NAT1To1IPs = viper.GetStringSlice("nat1to1")

View File

@ -2,6 +2,8 @@ package message
import ( import (
"n.eko.moe/neko/internal/types" "n.eko.moe/neko/internal/types"
"github.com/pion/webrtc/v3"
) )
type Message struct { type Message struct {
@ -18,7 +20,7 @@ type SignalProvide struct {
ID string `json:"id"` ID string `json:"id"`
SDP string `json:"sdp"` SDP string `json:"sdp"`
Lite bool `json:"lite"` Lite bool `json:"lite"`
ICE string `json:"ice"` ICE []webrtc.ICEServer `json:"ice"`
} }
type SignalAnswer struct { type SignalAnswer struct {

View File

@ -1,8 +1,6 @@
package websocket package websocket
import ( import (
"encoding/json"
"n.eko.moe/neko/internal/types" "n.eko.moe/neko/internal/types"
"n.eko.moe/neko/internal/types/event" "n.eko.moe/neko/internal/types/event"
"n.eko.moe/neko/internal/types/message" "n.eko.moe/neko/internal/types/message"
@ -14,17 +12,12 @@ func (h *MessageHandler) signalProvide(id string, session types.Session) error {
return err return err
} }
tmp, err := json.Marshal(ice)
if (err != nil) {
panic(err)
}
if err := session.Send(message.SignalProvide{ if err := session.Send(message.SignalProvide{
Event: event.SIGNAL_PROVIDE, Event: event.SIGNAL_PROVIDE,
ID: id, ID: id,
SDP: sdp, SDP: sdp,
Lite: lite, Lite: lite,
ICE: string(tmp), ICE: ice,
}); err != nil { }); err != nil {
return err return err
} }